1
0
mirror of synced 2025-01-23 22:54:08 +01:00

writers.py: Condense writeFumen

This commit is contained in:
Viv 2023-07-19 17:47:40 -04:00
parent e38fc4d666
commit 077d07d023

View File

@ -3,37 +3,28 @@ from tja2fumen.constants import branchNames, typeNotes
def writeFumen(path_out, song):
# Fetch the byte order (little/big endian)
order = song.header.order
with open(path_out, "wb") as file:
file.write(song.header.raw_bytes)
# Write the header
file = open(path_out, "wb")
file.write(song.header.raw_bytes) # Write header padding bytes
# Write measure data
file.seek(0x208)
for measureNumber in range(len(song.measures)):
measure = song.measures[measureNumber]
measureStruct = [measure.bpm, measure.fumenOffsetStart, int(measure.gogo), int(measure.barline)]
measureStruct.extend([measure.padding1] + measure.branchInfo + [measure.padding2])
writeStruct(file, order, format_string="ffBBHiiiiiii", value_list=measureStruct)
writeStruct(file, song.header.order, format_string="ffBBHiiiiiii", value_list=measureStruct)
for branchNumber in range(len(branchNames)):
branch = measure.branches[branchNames[branchNumber]]
branchStruct = [branch.length, branch.padding, branch.speed]
writeStruct(file, order, format_string="HHf", value_list=branchStruct)
writeStruct(file, song.header.order, format_string="HHf", value_list=branchStruct)
for noteNumber in range(branch.length):
note = branch.notes[noteNumber]
noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
# Balloon hits
if note.hits:
noteStruct.extend([note.hits, note.hitsPadding])
noteStruct.extend([note.hits, note.hitsPadding, note.duration])
else:
noteStruct.extend([note.scoreInit, note.scoreDiff * 4])
# Drumroll or balloon duration
noteStruct.append(note.duration)
writeStruct(file, order, format_string="ififHHf", value_list=noteStruct)
noteStruct.extend([note.scoreInit, note.scoreDiff * 4, note.duration])
writeStruct(file, song.header.order, format_string="ififHHf", value_list=noteStruct)
if note.type.lower() == "drumroll":
file.write(note.drumrollBytes)
file.close()