1
0
mirror of synced 2025-02-09 23:48:31 +01:00

converters.py: Minor refactoring tweaks (e.g. comments)

This commit is contained in:
Viv 2023-07-31 09:18:15 -04:00
parent 78379d5143
commit 73ad83d621

View File

@ -190,8 +190,11 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
# Iterate through the different branches in the TJA # Iterate through the different branches in the TJA
total_notes = {'normal': 0, 'professional': 0, 'master': 0} total_notes = {'normal': 0, 'professional': 0, 'master': 0}
for current_branch, branch_tja in tja_branches_processed.items(): for current_branch, branch_tja in tja_branches_processed.items():
# Skip empty branches (e.g. 'professional', 'master')
if not branch_tja: if not branch_tja:
continue continue
# Track properties that will change over the course of the song
branch_points_total = 0 branch_points_total = 0
branch_points_measure = 0 branch_points_measure = 0
current_drumroll = FumenNote() current_drumroll = FumenNote()
@ -200,10 +203,9 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
branch_conditions: list[tuple[float, float]] = [] branch_conditions: list[tuple[float, float]] = []
course_balloons = tja.balloon.copy() course_balloons = tja.balloon.copy()
# Iterate through the measures within the branch # Iterate over pairs of TJA and Fumen measures
for idx_m, measure_tja in enumerate(branch_tja): for idx_m, (measure_tja, measure_fumen) in \
# Fetch the corresponding fumen measure enumerate(zip(branch_tja, fumen.measures)):
measure_fumen = fumen.measures[idx_m]
# Copy over basic measure properties from the TJA # Copy over basic measure properties from the TJA
measure_fumen.branches[current_branch].speed = measure_tja.scroll measure_fumen.branches[current_branch].speed = measure_tja.scroll
@ -309,23 +311,24 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
if data.value == "Kusudama" and current_drumroll.note_type: if data.value == "Kusudama" and current_drumroll.note_type:
continue continue
# Handle note metadata # Now that the edge cases have been taken care of ('continue'),
# we can initialize a note and handle general note metadata.
note = FumenNote() note = FumenNote()
note.pos = note_pos note.pos = note_pos
note.note_type = data.value note.note_type = data.value
note.score_init = tja.score_init note.score_init = tja.score_init
note.score_diff = tja.score_diff note.score_diff = tja.score_diff
# Handle drumroll notes # Handle drumroll-specific note metadata
if note.note_type in ["Balloon", "Kusudama"]: if note.note_type in ["Drumroll", "DRUMROLL"]:
current_drumroll = note
elif note.note_type in ["Balloon", "Kusudama"]:
try: try:
note.hits = course_balloons.pop(0) note.hits = course_balloons.pop(0)
except IndexError as exc: except IndexError as exc:
raise ValueError(f"Not enough values for 'BALLOON: " raise ValueError(f"Not enough values for 'BALLOON: "
f"{course_balloons}'") from exc f"{course_balloons}'") from exc
current_drumroll = note current_drumroll = note
elif note.note_type in ["Drumroll", "DRUMROLL"]:
current_drumroll = note
# Track Don/Ka notes (to later compute header values) # Track Don/Ka notes (to later compute header values)
elif (note.note_type.lower().startswith('don') elif (note.note_type.lower().startswith('don')