1
0
mirror of synced 2025-01-24 23:13:40 +01:00

Simplify #SECTION/#BRANCHSTART logic

Previous code was unnecessarily convoluted.
This commit is contained in:
Viv 2023-07-25 19:08:59 -04:00
parent f088e95e02
commit ec72398abe
2 changed files with 11 additions and 17 deletions

View File

@ -196,16 +196,8 @@ def convert_tja_to_fumen(tja):
if barline_off or is_submeasure: if barline_off or is_submeasure:
measure_fumen.barline = False measure_fumen.barline = False
# If a #SECTION command occurs in isolation, and it has a valid
# condition, then treat it like a branch_start
if (measure_tja.section is not None
and measure_tja.section != 'not_available'
and not measure_tja.branch_start):
branch_condition = measure_tja.section
else:
branch_condition = measure_tja.branch_start
# Check to see if the measure contains a branching condition # Check to see if the measure contains a branching condition
branch_condition = measure_tja.branch_start
if branch_condition: if branch_condition:
# Update the branch_info values for the measure # Update the branch_info values for the measure
measure_fumen.set_branch_info( measure_fumen.set_branch_info(

View File

@ -185,16 +185,18 @@ def parse_tja_course_data(course):
elif line.name == 'MEASURE': elif line.name == 'MEASURE':
current_event = TJAData('measure', line.value, pos) current_event = TJAData('measure', line.value, pos)
elif line.name == 'SECTION': elif line.name == 'SECTION':
if branch_condition is None: # If #SECTION occurs before a #BRANCHSTART, then ensure that
current_event = TJAData('section', 'not_available', pos) # it's present on every branch. Otherwise, #SECTION will only
else: # be present on the current branch, and so the `branch_info`
current_event = TJAData('section', branch_condition, pos) # values won't be correctly set for the other two branches.
# If the command immediately after #SECTION is #BRANCHSTART,
# then we need to make sure that #SECTION is put on every
# branch. (We can't do this unconditionally because #SECTION
# commands can also exist in isolation.)
if course.data[idx_l+1].name == 'BRANCHSTART': if course.data[idx_l+1].name == 'BRANCHSTART':
current_event = TJAData('section', None, pos)
current_branch = 'all' current_branch = 'all'
# Otherwise, #SECTION exists in isolation. In this case, to
# reset the accuracy, we just repeat the previous #BRANCHSTART.
else:
current_event = TJAData('branch_start', branch_condition,
pos)
elif line.name == 'BRANCHSTART': elif line.name == 'BRANCHSTART':
if flag_levelhold: if flag_levelhold:
continue continue