1
0
mirror of synced 2025-01-24 23:13:40 +01:00

tja2fumen.py: Refactor main steps into main() function

This commit is contained in:
Viv 2023-06-02 16:33:46 -04:00
parent 7239a00e76
commit 35159ea793

View File

@ -6,31 +6,39 @@ from utils import checkMismatchedBytes
tja2fumen_version = "v0.1" tja2fumen_version = "v0.1"
if __name__ == "__main__": def main(fnameFumen=None, fnameTJA=None, validate=False):
# arguments = parser.parse_args() if fnameFumen:
arguments = { # Parse fumen
"input_fumen": "test-data/ia6cho_m.bin", # NB: Contains only oni chart inputFile = open(fnameFumen, "rb")
"input_tja": "test-data/Rokuchounen to Ichiya Monogatari.tja", # NB: Contains 5 charts parsedSongFumen = readFumen(inputFile)
}
# Parse fumen
inputFile = open(arguments["input_fumen"], "rb")
parsedSongFumen = readFumen(inputFile)
# Steps to validate the `writeFumen` function to make sure it reproduces correct output # Steps to validate the `writeFumen` function to make sure it reproduces correct output
validate = False if validate:
if validate: outputName = inputFile.name.split('.')[0] + "_rebuilt.bin"
outputName = inputFile.name.split('.')[0] + "_rebuilt.bin" outputFile = open(outputName, "wb")
writeFumen(outputFile, parsedSongFumen)
# Read output file back in to validate that the rewritten song is a perfect match
print(False if checkMismatchedBytes(inputFile.name, outputFile.name) else True)
else:
parsedSongFumen = None
if fnameTJA:
# Parse tja
inputFile = open(fnameTJA, "r", encoding="utf-8-sig")
parsedSongsTJA = parseTJA(inputFile)
# Try converting the Oni TJA chart to match the Oni fumen
convertedTJA = convertTJAToFumen(parsedSongFumen, parsedSongsTJA['Oni'])
outputName = inputFile.name.split('.')[0] + ".bin"
outputFile = open(outputName, "wb") outputFile = open(outputName, "wb")
writeFumen(outputFile, parsedSongFumen) writeFumen(outputFile, convertedTJA)
# Read output file back in to validate that the rewritten song is a perfect match else:
print(False if checkMismatchedBytes(inputFile.name, outputFile.name) else True) convertedTJA = None
# Parse tja return parsedSongFumen, convertedTJA
inputFile = open(arguments["input_tja"], "r", encoding="utf-8-sig")
parsedSongsTJA = parseTJA(inputFile)
# Try converting the Oni TJA chart to match the Oni fumen
convertedTJA = convertTJAToFumen(parsedSongFumen, parsedSongsTJA['Oni']) if __name__ == "__main__":
outputName = inputFile.name.split('.')[0] + ".bin" fnameFumen = "test-data/ia6cho_m.bin" # NB: Contains only oni chart
outputFile = open(outputName, "wb") fnameTJA = "test-data/Rokuchounen to Ichiya Monogatari.tja" # NB: Contains 5 charts
writeFumen(outputFile, convertedTJA) fumen, tja = main(fnameFumen, fnameTJA)