From 8b07fb77d099e4154060965e7f3205193977eb2e Mon Sep 17 00:00:00 2001 From: Viv Date: Fri, 2 Jun 2023 16:33:44 -0400 Subject: [PATCH] `parsetja.py`: Add `applyFumenStructureToParsedTJA` function This function basically just takes the output of the `getCourse` function, and restructures it so that it more closely matches the structure of the fumen `song` format. --- tja2fumen/parsetja.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tja2fumen/parsetja.py b/tja2fumen/parsetja.py index 92bff30..d8df826 100644 --- a/tja2fumen/parsetja.py +++ b/tja2fumen/parsetja.py @@ -218,7 +218,30 @@ def parseTJA(tja): courses[currentCourse].append(parsed) # Convert parsed course lines into actual note data + songs = {} for courseName, courseLines in courses.items(): - courses[courseName] = getCourse(headers, courseLines) + courseHeader, courseMeasures = getCourse(headers, courseLines) + songs[courseName] = applyFumenStructureToParsedTJA(headers, courseHeader, courseMeasures) - return headers, courses + return songs + + +def applyFumenStructureToParsedTJA(globalHeader, courseHeader, measures): + song = { 'measures': [], 'metadata': {} } + + for k, v in globalHeader.items(): + song['metadata'][k] = v + + for k, v in courseHeader.items(): + if k in ['scoreInit', 'scoreDiff']: + song[k] = v + else: + song['metadata'][k] = v + + for i, measure in enumerate(measures): + song['measures'].append(measure) + for event in measure['events']: + if event['name'].upper() in BRANCH_COMMANDS: + song['branches'] = True + + return song