Ensure that header branch bytes are correctly set for all branching cases (#50)
Some backstory: - In [#45](https://github.com/vivaria/tja2fumen/pull/45), I reworked the header parsing code to make sure every header value was correctly identified. - In [#46](https://github.com/vivaria/tja2fumen/pull/46), I changed how the "branch point" header bytes were set by checking if a song contained only drumroll branching conditions. This fixed drumroll-only songs like BATTLE NO. 1, Shoutoku Taiko, etc. However, I missed a corner case in #46 -- songs with `#BRANCHSTART p,0,0` should still be considered "drumroll only". As well, I neglected to consider the "percentage only" songs. So, I fixed the header bytes there, too. Then, to confirm that my changes do in fact produce correct headers, I enabled the check for `branch_points` for (most) of the songs in the test suite. The tests pass. :)
This commit is contained in:
parent
5ce313ca83
commit
000125eb10
@ -248,9 +248,8 @@ def convert_tja_to_fumen(tja):
|
|||||||
|
|
||||||
# Reset the note counter corresponding to this branch (i.e. reset the accuracy)
|
# Reset the note counter corresponding to this branch (i.e. reset the accuracy)
|
||||||
total_notes_branch = 0
|
total_notes_branch = 0
|
||||||
# Cache branch conditions, but skip conditions where the only purpose is to level down to 'normal'
|
# Keep track of branch conditions (to later determine how to set the header bytes for branches)
|
||||||
if measure_fumen.branch_info != [999, 999, 999, 999, 999, 999]:
|
branch_conditions.append(branch_condition)
|
||||||
branch_conditions.append(branch_condition)
|
|
||||||
|
|
||||||
# NB: We update the branch condition note counter *after* we check the current measure's branch condition.
|
# NB: We update the branch condition note counter *after* we check the current measure's branch condition.
|
||||||
# This is because the TJA spec says:
|
# This is because the TJA spec says:
|
||||||
@ -322,8 +321,15 @@ def convert_tja_to_fumen(tja):
|
|||||||
fumen.header.b432_b435_has_branches = int(all([len(b) for b in processed_tja_branches.values()]))
|
fumen.header.b432_b435_has_branches = int(all([len(b) for b in processed_tja_branches.values()]))
|
||||||
fumen.header.set_hp_bytes(total_notes['normal'], tja.course, tja.level)
|
fumen.header.set_hp_bytes(total_notes['normal'], tja.course, tja.level)
|
||||||
|
|
||||||
# If song has only drumroll branching conditions, then only drumrolls should contribute to branching
|
# If song has only drumroll branching conditions (plus percentage conditions that force a level up/level down),
|
||||||
if all([condition[0] == 'r' for condition in branch_conditions]):
|
# then set the header bytes so that only drumrolls contribute to branching.
|
||||||
|
drumroll_only = branch_conditions != [] and all([
|
||||||
|
(condition[0] == 'r') or
|
||||||
|
(condition[0] == 'p' and condition[1] == 0.0 and condition[2] == 0.0) or
|
||||||
|
(condition[0] == 'p' and condition[1] > 1.00 and condition[2] > 1.00)
|
||||||
|
for condition in branch_conditions
|
||||||
|
])
|
||||||
|
if drumroll_only:
|
||||||
fumen.header.b468_b471_branch_points_good = 0
|
fumen.header.b468_b471_branch_points_good = 0
|
||||||
fumen.header.b484_b487_branch_points_good_big = 0
|
fumen.header.b484_b487_branch_points_good_big = 0
|
||||||
fumen.header.b472_b475_branch_points_ok = 0
|
fumen.header.b472_b475_branch_points_ok = 0
|
||||||
@ -331,6 +337,16 @@ def convert_tja_to_fumen(tja):
|
|||||||
fumen.header.b496_b499_branch_points_balloon = 0
|
fumen.header.b496_b499_branch_points_balloon = 0
|
||||||
fumen.header.b500_b503_branch_points_kusudama = 0
|
fumen.header.b500_b503_branch_points_kusudama = 0
|
||||||
|
|
||||||
|
# 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_conditions != [] and all([
|
||||||
|
(condition[0] != 'r')
|
||||||
|
for condition in branch_conditions
|
||||||
|
])
|
||||||
|
if percentage_only:
|
||||||
|
fumen.header.b480_b483_branch_points_drumroll = 0
|
||||||
|
fumen.header.b492_b495_branch_points_drumroll_big = 0
|
||||||
|
|
||||||
# Compute the ratio between normal and professional/master branches (just in case the note counts differ)
|
# Compute the ratio between normal and professional/master branches (just in case the note counts differ)
|
||||||
if total_notes['professional']:
|
if total_notes['professional']:
|
||||||
fumen.header.b460_b463_normal_professional_ratio = int(65536 * (total_notes['normal'] / total_notes['professional']))
|
fumen.header.b460_b463_normal_professional_ratio = int(65536 * (total_notes['normal'] / total_notes['professional']))
|
||||||
|
@ -79,16 +79,18 @@ def test_converted_tja_vs_cached_fumen(id_song, tmp_path, entry_point):
|
|||||||
assert_song_property(co_song.header, ca_song.header, 'b456_b459_normal_normal_ratio')
|
assert_song_property(co_song.header, ca_song.header, 'b456_b459_normal_normal_ratio')
|
||||||
assert_song_property(co_song.header, ca_song.header, 'b460_b463_normal_professional_ratio')
|
assert_song_property(co_song.header, ca_song.header, 'b460_b463_normal_professional_ratio')
|
||||||
assert_song_property(co_song.header, ca_song.header, 'b464_b467_normal_master_ratio')
|
assert_song_property(co_song.header, ca_song.header, 'b464_b467_normal_master_ratio')
|
||||||
# Ignore branch points for now to focus on HP bytes
|
# NB: KAGEKIYO's branching condition is very unique (BIG only), which cannot be expressed in a TJA file
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b468_b471_branch_points_good')
|
# So, skip checking the `branch_point` header values for KAGEKIYO.
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b472_b475_branch_points_ok')
|
if id_song != 'genpe':
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b476_b479_branch_points_bad')
|
assert_song_property(co_song.header, ca_song.header, 'b468_b471_branch_points_good')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b480_b483_branch_points_drumroll')
|
assert_song_property(co_song.header, ca_song.header, 'b472_b475_branch_points_ok')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b484_b487_branch_points_good_big')
|
assert_song_property(co_song.header, ca_song.header, 'b476_b479_branch_points_bad')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b488_b491_branch_points_ok_big')
|
assert_song_property(co_song.header, ca_song.header, 'b480_b483_branch_points_drumroll')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b492_b495_branch_points_drumroll_big')
|
assert_song_property(co_song.header, ca_song.header, 'b484_b487_branch_points_good_big')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b496_b499_branch_points_balloon')
|
assert_song_property(co_song.header, ca_song.header, 'b488_b491_branch_points_ok_big')
|
||||||
# assert_song_property(co_song.header, ca_song.header, 'b500_b503_branch_points_kusudama')
|
assert_song_property(co_song.header, ca_song.header, 'b492_b495_branch_points_drumroll_big')
|
||||||
|
assert_song_property(co_song.header, ca_song.header, 'b496_b499_branch_points_balloon')
|
||||||
|
assert_song_property(co_song.header, ca_song.header, 'b500_b503_branch_points_kusudama')
|
||||||
# 2. Check song metadata
|
# 2. Check song metadata
|
||||||
assert_song_property(co_song, ca_song, 'score_init')
|
assert_song_property(co_song, ca_song, 'score_init')
|
||||||
assert_song_property(co_song, ca_song, 'score_diff')
|
assert_song_property(co_song, ca_song, 'score_diff')
|
||||||
|
Loading…
Reference in New Issue
Block a user