From 7aead6f8ef7e17dc206b22d97662137fe291f221 Mon Sep 17 00:00:00 2001 From: Viv Date: Tue, 25 Jul 2023 23:29:07 -0400 Subject: [PATCH] `parsers.py`: Simplify convoluted P1 copying logic --- src/tja2fumen/constants.py | 15 +++++++++------ src/tja2fumen/parsers.py | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/tja2fumen/constants.py b/src/tja2fumen/constants.py index 3f6d98a..b35f8c1 100644 --- a/src/tja2fumen/constants.py +++ b/src/tja2fumen/constants.py @@ -58,12 +58,6 @@ FUMEN_NOTE_TYPES = { # Invert the dict to go from note type to fumen byte values FUMEN_TYPE_NOTES = {v: k for k, v in FUMEN_NOTE_TYPES.items()} -# All combinations of difficulty and single/multiplayer type -TJA_COURSE_NAMES = [] -for difficulty in ['Ura', 'Oni', 'Hard', 'Normal', 'Easy']: - for player in ['', 'P1', 'P2']: - TJA_COURSE_NAMES.append(difficulty+player) - # Normalize the various fumen course names into 1 name per difficulty NORMALIZE_COURSE = { '0': 'Easy', @@ -79,6 +73,15 @@ NORMALIZE_COURSE = { 'Edit': 'Ura' } +# Fetch the 5 valid course names from NORMALIZE_COURSE's values +COURSE_NAMES = list(set(NORMALIZE_COURSE.values())) + +# All combinations of difficulty and single/multiplayer type +TJA_COURSE_NAMES = [] +for difficulty in COURSE_NAMES: + for player in ['', 'P1', 'P2']: + TJA_COURSE_NAMES.append(difficulty+player) + # Map course difficulty to filename IDs (e.g. Oni -> `song_m.bin`) COURSE_IDS = { 'Easy': 'e', diff --git a/src/tja2fumen/parsers.py b/src/tja2fumen/parsers.py index 7cc8ac4..87b4ab2 100644 --- a/src/tja2fumen/parsers.py +++ b/src/tja2fumen/parsers.py @@ -5,8 +5,8 @@ from copy import deepcopy from tja2fumen.types import (TJASong, TJAMeasure, TJAData, FumenCourse, FumenMeasure, FumenBranch, FumenNote, FumenHeader) -from tja2fumen.constants import (NORMALIZE_COURSE, TJA_NOTE_TYPES, - BRANCH_NAMES, FUMEN_NOTE_TYPES) +from tja2fumen.constants import (NORMALIZE_COURSE, COURSE_NAMES, BRANCH_NAMES, + TJA_NOTE_TYPES, FUMEN_NOTE_TYPES) ############################################################################### # TJA-parsing functions # @@ -128,14 +128,14 @@ def split_tja_lines_into_courses(lines): else: parsed_tja.courses[current_course].data.append(line) - # If a course has no song data, then this is likely because the course has - # "STYLE: Double" but no "STYLE: Single". To fix this, we copy over the P1 - # chart from "STYLE: Double" to fill the "STYLE: Single" role. - for course_name, course in parsed_tja.courses.items(): - if not course.data: - if course_name+"P1" in parsed_tja.courses.keys(): - parsed_tja.courses[course_name] = \ - deepcopy(parsed_tja.courses[course_name+"P1"]) + # If a .tja has "STYLE: Double" but no "STYLE: Single", then it will be + # missing data for the "single player" chart. To fix this, we copy over + # the P1 chart from "STYLE: Double" to fill the "STYLE: Single" role. + for course_name in COURSE_NAMES: + course_single_player = parsed_tja.courses[course_name] + course_player_one = parsed_tja.courses[course_name+"P1"] + if course_player_one.data and not course_single_player.data: + parsed_tja.courses[course_name] = deepcopy(course_player_one) # Remove any charts (e.g. P1/P2) not present in the TJA file (empty data) for course_name in [k for k, v in parsed_tja.courses.items()