writers.py
: Condense writeFumen
This commit is contained in:
parent
e38fc4d666
commit
077d07d023
@ -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
|
||||
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, song.header.order, format_string="ffBBHiiiiiii", value_list=measureStruct)
|
||||
|
||||
# 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)
|
||||
for branchNumber in range(len(branchNames)):
|
||||
branch = measure.branches[branchNames[branchNumber]]
|
||||
branchStruct = [branch.length, branch.padding, branch.speed]
|
||||
writeStruct(file, song.header.order, format_string="HHf", value_list=branchStruct)
|
||||
|
||||
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)
|
||||
for noteNumber in range(branch.length):
|
||||
note = branch.notes[noteNumber]
|
||||
noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
|
||||
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):
|
||||
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])
|
||||
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()
|
||||
if note.type.lower() == "drumroll":
|
||||
file.write(note.drumrollBytes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user