From b380ad77860911d18c83fb58ad06295c4f830878 Mon Sep 17 00:00:00 2001 From: Viv Date: Sun, 30 Jul 2023 20:09:04 -0400 Subject: [PATCH] Fix additional type issues caught by `mypyc` --- src/tja2fumen/converters.py | 11 ++++++----- src/tja2fumen/parsers.py | 5 +++-- src/tja2fumen/types.py | 7 ++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tja2fumen/converters.py b/src/tja2fumen/converters.py index 7efc440..198ffe2 100644 --- a/src/tja2fumen/converters.py +++ b/src/tja2fumen/converters.py @@ -89,6 +89,7 @@ def process_tja_commands(tja: TJACourse) \ # measure in those cases.) elif data.name in ['bpm', 'scroll', 'gogo']: # Parse the values + new_val: bool | float if data.name == 'bpm': new_val = current_bpm = float(data.value) elif data.name == 'scroll': @@ -193,7 +194,7 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: continue branch_points_total = 0 branch_points_measure = 0 - current_drumroll = None + current_drumroll = FumenNote() current_levelhold = False branch_types: list[str] = [] branch_conditions: list[tuple[float, float]] = [] @@ -281,7 +282,7 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: # Handle '8' notes (end of a drumroll/balloon) if data.value == "EndDRB": - if not isinstance(current_drumroll, FumenNote): + if not current_drumroll.note_type: raise ValueError( "'8' note encountered without matching " "drumroll/balloon/kusudama note." @@ -299,13 +300,13 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: current_drumroll.duration = float(int( current_drumroll.duration )) - current_drumroll = None + current_drumroll = FumenNote() continue # The TJA spec technically allows you to place # double-Kusudama notes. But this is unsupported in # fumens, so just skip the second Kusudama note. - if data.value == "Kusudama" and current_drumroll: + if data.value == "Kusudama" and current_drumroll.note_type: continue # Handle note metadata @@ -349,7 +350,7 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: measure_fumen.branches[current_branch].length += 1 # If drumroll hasn't ended by this measure, increase duration - if current_drumroll: + if current_drumroll.note_type: # If drumroll spans multiple measures, add full duration if current_drumroll.multimeasure: current_drumroll.duration += measure_fumen.duration diff --git a/src/tja2fumen/parsers.py b/src/tja2fumen/parsers.py index 3a2afc0..0540292 100644 --- a/src/tja2fumen/parsers.py +++ b/src/tja2fumen/parsers.py @@ -198,8 +198,9 @@ def parse_tja_course_data(course: TJACourse) -> None: command, name, value, note_data = '', '', '', '' match_command = re.match(r"^#([A-Z]+)(?:\s+(.+))?", line) if match_command: - command, value = match_command.groups() - value = '' if value is None else value + command = match_command.group(1) + if match_command.group(2): + value = match_command.group(2) else: note_data = line # If not a command, then line must be note data diff --git a/src/tja2fumen/types.py b/src/tja2fumen/types.py index 8f14f40..72e7b11 100644 --- a/src/tja2fumen/types.py +++ b/src/tja2fumen/types.py @@ -87,7 +87,7 @@ class FumenNote: pos: float = 0.0 score_init: int = 0 score_diff: int = 0 - padding: int = 0 + padding: float = 0.0 item: int = 0 duration: float = 0.0 multimeasure: bool = False @@ -225,8 +225,9 @@ class FumenMeasure: class FumenHeader: """Contains all the byte values for a Fumen chart file's header.""" order: str = "<" - b000_b431_timing_windows: list[float] = field(default_factory=lambda: - [25.025, 75.075, 108.422]*36) + b000_b431_timing_windows: tuple[float, ...] = field( + default_factory=lambda: tuple([25.025, 75.075, 108.422]*36) + ) b432_b435_has_branches: int = 0 b436_b439_hp_max: int = 10000 b440_b443_hp_clear: int = 8000