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):
|
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
|
|
||||||
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)):
|
for measureNumber in range(len(song.measures)):
|
||||||
measure = song.measures[measureNumber]
|
measure = song.measures[measureNumber]
|
||||||
measureStruct = [measure.bpm, measure.fumenOffsetStart, int(measure.gogo), int(measure.barline)]
|
measureStruct = [measure.bpm, measure.fumenOffsetStart, int(measure.gogo), int(measure.barline)]
|
||||||
measureStruct.extend([measure.padding1] + measure.branchInfo + [measure.padding2])
|
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)):
|
for branchNumber in range(len(branchNames)):
|
||||||
branch = measure.branches[branchNames[branchNumber]]
|
branch = measure.branches[branchNames[branchNumber]]
|
||||||
branchStruct = [branch.length, branch.padding, branch.speed]
|
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):
|
for noteNumber in range(branch.length):
|
||||||
note = branch.notes[noteNumber]
|
note = branch.notes[noteNumber]
|
||||||
noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
|
noteStruct = [typeNotes[note.type], note.pos, note.item, note.padding]
|
||||||
# Balloon hits
|
|
||||||
if note.hits:
|
if note.hits:
|
||||||
noteStruct.extend([note.hits, note.hitsPadding])
|
noteStruct.extend([note.hits, note.hitsPadding, note.duration])
|
||||||
else:
|
else:
|
||||||
noteStruct.extend([note.scoreInit, note.scoreDiff * 4])
|
noteStruct.extend([note.scoreInit, note.scoreDiff * 4, note.duration])
|
||||||
# Drumroll or balloon duration
|
writeStruct(file, song.header.order, format_string="ififHHf", value_list=noteStruct)
|
||||||
noteStruct.append(note.duration)
|
|
||||||
writeStruct(file, order, format_string="ififHHf", value_list=noteStruct)
|
|
||||||
if note.type.lower() == "drumroll":
|
if note.type.lower() == "drumroll":
|
||||||
file.write(note.drumrollBytes)
|
file.write(note.drumrollBytes)
|
||||||
file.close()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user