1
0
mirror of synced 2025-02-03 13:13:26 +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): def writeFumen(path_out, song):
# Fetch the byte order (little/big endian) with open(path_out, "wb") as file:
order = song.header.order file.write(song.header.raw_bytes)
# Write the header for measureNumber in range(len(song.measures)):
file = open(path_out, "wb") measure = song.measures[measureNumber]
file.write(song.header.raw_bytes) # Write header padding bytes measureStruct = [measure.bpm, measure.fumenOffsetStart, int(measure.gogo), int(measure.barline)]
measureStruct.extend([measure.padding1] + measure.branchInfo + [measure.padding2])
writeStruct(file, song.header.order, format_string="ffBBHiiiiiii", value_list=measureStruct)
# Write measure data for branchNumber in range(len(branchNames)):
file.seek(0x208) branch = measure.branches[branchNames[branchNumber]]
for measureNumber in range(len(song.measures)): branchStruct = [branch.length, branch.padding, branch.speed]
measure = song.measures[measureNumber] writeStruct(file, song.header.order, format_string="HHf", value_list=branchStruct)
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)
for branchNumber in range(len(branchNames)): for noteNumber in range(branch.length):
branch = measure.branches[branchNames[branchNumber]] note = branch.notes[noteNumber]
branchStruct = [branch.length, branch.padding, branch.speed] noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
writeStruct(file, order, format_string="HHf", value_list=branchStruct) if note.hits:
noteStruct.extend([note.hits, note.hitsPadding, note.duration])
else:
noteStruct.extend([note.scoreInit, note.scoreDiff * 4, note.duration])
writeStruct(file, song.header.order, format_string="ififHHf", value_list=noteStruct)
for noteNumber in range(branch.length): if note.type.lower() == "drumroll":
note = branch.notes[noteNumber] file.write(note.drumrollBytes)
noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
# Balloon hits
if note.hits:
noteStruct.extend([note.hits, note.hitsPadding])
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)
if note.type.lower() == "drumroll":
file.write(note.drumrollBytes)
file.close()