Skip to content

Commit 6359286

Browse files
committed
shift ticks over 6000
1 parent 3b0849e commit 6359286

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

gm4_timelines/plugins/generate.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def beet_default(ctx: Context) -> None:
7272

7373
data = remove_null_entries(data)
7474

75+
data = shift_ticks(data, 6000)
76+
7577
ctx.data["minecraft:day"] = Timeline(data.model_dump())
7678

7779

@@ -99,28 +101,28 @@ def remove_null_entries(data: TimelineData) -> TimelineData:
99101

100102

101103

102-
def factor_ticks(data: TimelineData) -> TimelineData:
104+
def shift_ticks(data: TimelineData, shift: int) -> TimelineData:
103105
"""
104-
Each keyframe tick is shifted by a fixed offset, wrapped to the original
105-
period, and then multiplied by the tick factor. The timeline period
106-
itself is also scaled accordingly.
106+
Each keyframe tick is shifted by a fixed offset, the timeline period
107+
itself is also increased accordingly. This is to make sure day definitions
108+
start at noon (aka daytime = 6000)
107109
108110
Args:
109111
data: Timeline data whose ticks will be modified.
112+
shift: ticks to shift ticks and period by
110113
111114
Returns:
112-
TimelineData instance with modified tick values.
115+
TimelineData instance with shifted tick values.
113116
"""
114117
factored_data = copy.deepcopy(data)
115118

116-
# offset and scale the ticks
119+
# shift the ticks
117120
for track in factored_data.tracks.values():
118121
for kf in track.keyframes:
119-
kf.ticks = ((kf.ticks + TICK_OFFSET) % DAY_DURATION_TICKS) * TICK_FACTOR
120-
track.keyframes.sort(key=lambda k: k.ticks)
122+
kf.ticks += shift
121123

122-
# scale the period
123-
factored_data.period_ticks = DAY_DURATION_TICKS * TICK_FACTOR
124+
# shift the period
125+
factored_data.period_ticks += shift
124126

125127
return factored_data
126128

@@ -167,7 +169,7 @@ def process_day_files(
167169
Returns:
168170
TimelineData instance representing the concatenated day timeline.
169171
"""
170-
function_data: List[Dict[str, Any]] = []
172+
function_data: dict[str, Any] = {}
171173
full_timeline = TimelineData(period_ticks=0, tracks={})
172174

173175
# loop over day definitions
@@ -179,14 +181,16 @@ def process_day_files(
179181
# loop over supported moon phases
180182
moon_phases = day_data.settings.get("moon_phase", [])
181183
for moon_phase in moon_phases:
184+
182185
day_build, functions = register_day(default_data, day_data, moon_phase)
186+
183187
full_timeline = append_to_timeline(full_timeline, day_build)
184188

185-
function_data.append({
186-
"moon_phase": moon_phase,
187-
"in_type": day_data.settings['in_type'],
188-
"out_type": day_data.settings['out_type'],
189-
"weight": day_data.settings['weight'],
189+
function_moon_phase = function_data.setdefault(moon_phase, {})
190+
function_entries = function_moon_phase.setdefault(day_data.settings["in_type"], [])
191+
function_entries.append({
192+
"out_type": day_data.settings["out_type"],
193+
"weight": day_data.settings["weight"],
190194
"start_time": full_timeline.period_ticks,
191195
"functions": functions,
192196
"dev": is_dev
@@ -315,3 +319,30 @@ def append_to_timeline(full_timeline: TimelineData, new_data: TimelineData) -> T
315319
)
316320

317321
return full_timeline
322+
323+
324+
## This isn't used rn, but just kept in case
325+
# def factor_ticks(data: TimelineData) -> TimelineData:
326+
# """
327+
# Each keyframe tick is shifted by a fixed offset, wrapped to the original
328+
# period, and then multiplied by the tick factor. The timeline period
329+
# itself is also scaled accordingly.
330+
331+
# Args:
332+
# data: Timeline data whose ticks will be modified.
333+
334+
# Returns:
335+
# TimelineData instance with modified tick values.
336+
# """
337+
# factored_data = copy.deepcopy(data)
338+
339+
# # offset and scale the ticks
340+
# for track in factored_data.tracks.values():
341+
# for kf in track.keyframes:
342+
# kf.ticks = ((kf.ticks + TICK_OFFSET) % DAY_DURATION_TICKS) * TICK_FACTOR
343+
# track.keyframes.sort(key=lambda k: k.ticks)
344+
345+
# # scale the period
346+
# factored_data.period_ticks = DAY_DURATION_TICKS * TICK_FACTOR
347+
348+
# return factored_data

0 commit comments

Comments
 (0)