From 8e8332cd2bf360139a1ce969c2cdc577b1536aca Mon Sep 17 00:00:00 2001 From: Viv Date: Thu, 24 Oct 2024 22:57:21 -0400 Subject: [PATCH] Use `itertools.cycle` to repeat over balloons If branches have the same balloons, then `cycle` will cause the list to be repeated once per branch. However, if branches have different balloons, then assuming that all the balloon values for all branches are listed, the list will be iterated over normally. This --- src/tja2fumen/converters.py | 3 +-- src/tja2fumen/parsers.py | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tja2fumen/converters.py b/src/tja2fumen/converters.py index 247c02f..152f5a5 100644 --- a/src/tja2fumen/converters.py +++ b/src/tja2fumen/converters.py @@ -209,7 +209,6 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: current_levelhold = False branch_types: List[str] = [] branch_conditions: List[Tuple[float, float]] = [] - course_balloons = tja.balloon.copy() # Iterate over pairs of TJA and Fumen measures for idx_m, (measure_tja, measure_fumen) in \ @@ -334,7 +333,7 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse: current_drumroll = note elif note.note_type in ["Balloon", "Kusudama"]: try: - note.hits = course_balloons.pop(0) + note.hits = next(tja.balloon) except IndexError: warnings.warn(f"Not enough values for 'BALLOON:' " f"({tja.balloon}). Using value=1 to " diff --git a/src/tja2fumen/parsers.py b/src/tja2fumen/parsers.py index e04ff1e..a648e34 100644 --- a/src/tja2fumen/parsers.py +++ b/src/tja2fumen/parsers.py @@ -8,6 +8,7 @@ import struct import warnings from copy import deepcopy from typing import BinaryIO, Any, List, Dict, Tuple +from itertools import cycle from tja2fumen.classes import (TJASong, TJACourse, TJAMeasure, TJAData, FumenCourse, FumenMeasure, FumenBranch, @@ -121,7 +122,7 @@ def split_tja_lines_into_courses(lines: List[str]) -> TJASong: elif name_upper == 'BALLOON': if value: balloons = [int(v) for v in value.split(",") if v] - parsed_tja.courses[current_course].balloon = balloons + parsed_tja.courses[current_course].balloon = cycle(balloons) elif name_upper == 'STYLE': # Reset the course name to remove "P1/P2" that may have been # added by a previous STYLE:DOUBLE chart