Skip to content

Commit

Permalink
Fix PyCharm code inspection warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vivaria committed Jul 30, 2023
1 parent 300a58e commit ade127b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
29 changes: 20 additions & 9 deletions src/tja2fumen/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def process_tja_commands(tja: TJACourse) \
branch_cond = (float(val1), float(val2))
elif branch_type == 'p': # p = Percentage
branch_cond = (float(val1)/100, float(val2)/100)
else:
raise ValueError(f"Invalid #BRANCHSTART type: "
f"'{branch_type}'.")
measure_tja_processed.branch_type = branch_type
measure_tja_processed.branch_cond = branch_cond
elif data.name == 'section':
Expand Down Expand Up @@ -96,7 +99,8 @@ def process_tja_commands(tja: TJACourse) \
# - Case 1: Command happens at the start of a measure;
# just change the value directly
if data.pos == 0:
setattr(measure_tja_processed, data.name, new_val)
setattr(measure_tja_processed, data.name,
new_val) # noqa: new_val will always be set
# - Case 2: Command happens in the middle of a measure;
# start a new sub-measure
else:
Expand Down Expand Up @@ -361,11 +365,15 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
# If song has only drumroll branching conditions (also allowing percentage
# conditions that force a level up/level down), then set the header bytes
# so that only drumrolls contribute to branching.
drumroll_only = branch_types and branch_conditions and all(
(branch_type == 'r') or
(branch_type == 'p' and cond[0] == 0.0 and cond[1] == 0.0) or
(branch_type == 'p' and cond[0] > 1.00 and cond[1] > 1.00)
for branch_type, cond in zip(branch_types, branch_conditions)
drumroll_only = (
branch_types # noqa: branch_types will always be set
and branch_conditions # noqa: branch_conditions will always be set
and all(
(branch_type == 'r') or
(branch_type == 'p' and cond[0] == 0.0 and cond[1] == 0.0) or
(branch_type == 'p' and cond[0] > 1.00 and cond[1] > 1.00)
for branch_type, cond in zip(branch_types, branch_conditions)
)
)
if drumroll_only:
fumen.header.b468_b471_branch_pts_good = 0
Expand All @@ -377,9 +385,12 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:

# Alternatively, if the song has only percentage-based conditions, then set
# the header bytes so that only notes and balloons contribute to branching.
percentage_only = branch_types and all(
(branch_type != 'r')
for branch_type in branch_types
percentage_only = (
branch_types # noqa: branch_types will always be set
and all(
(branch_type != 'r')
for branch_type in branch_types
)
)
if percentage_only:
fumen.header.b480_b483_branch_pts_drumroll = 0
Expand Down
1 change: 1 addition & 0 deletions src/tja2fumen/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def parse_tja_course_data(course: TJACourse) -> None:
'DELAY', 'SCROLL', 'BPMCHANGE', 'MEASURE',
'LEVELHOLD', 'SECTION', 'BRANCHSTART']:
# Get position of the event
pos = 0
for branch_name in (course.branches.keys()
if current_branch == 'all'
else [current_branch]):
Expand Down
3 changes: 2 additions & 1 deletion src/tja2fumen/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def write_fumen(path_out: str, song: FumenCourse) -> None:
extra_vals = [note.hits, note.hits_padding]
else:
extra_vals = [note.score_init, note.score_diff * 4]
note_struct.extend(extra_vals + [note.duration])
note_struct.extend(extra_vals)
note_struct.append(note.duration)
write_struct(file, song.header.order,
format_string="ififHHf",
value_list=note_struct)
Expand Down

0 comments on commit ade127b

Please sign in to comment.