tja2fumen.py
: Refactor main steps into main()
function
This commit is contained in:
parent
7239a00e76
commit
35159ea793
@ -6,31 +6,39 @@ from utils import checkMismatchedBytes
|
||||
tja2fumen_version = "v0.1"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# arguments = parser.parse_args()
|
||||
arguments = {
|
||||
"input_fumen": "test-data/ia6cho_m.bin", # NB: Contains only oni chart
|
||||
"input_tja": "test-data/Rokuchounen to Ichiya Monogatari.tja", # NB: Contains 5 charts
|
||||
}
|
||||
# Parse fumen
|
||||
inputFile = open(arguments["input_fumen"], "rb")
|
||||
parsedSongFumen = readFumen(inputFile)
|
||||
def main(fnameFumen=None, fnameTJA=None, validate=False):
|
||||
if fnameFumen:
|
||||
# Parse fumen
|
||||
inputFile = open(fnameFumen, "rb")
|
||||
parsedSongFumen = readFumen(inputFile)
|
||||
|
||||
# Steps to validate the `writeFumen` function to make sure it reproduces correct output
|
||||
validate = False
|
||||
if validate:
|
||||
outputName = inputFile.name.split('.')[0] + "_rebuilt.bin"
|
||||
# Steps to validate the `writeFumen` function to make sure it reproduces correct output
|
||||
if validate:
|
||||
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")
|
||||
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)
|
||||
writeFumen(outputFile, convertedTJA)
|
||||
else:
|
||||
convertedTJA = None
|
||||
|
||||
# Parse tja
|
||||
inputFile = open(arguments["input_tja"], "r", encoding="utf-8-sig")
|
||||
parsedSongsTJA = parseTJA(inputFile)
|
||||
return parsedSongFumen, convertedTJA
|
||||
|
||||
# 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")
|
||||
writeFumen(outputFile, convertedTJA)
|
||||
|
||||
if __name__ == "__main__":
|
||||
fnameFumen = "test-data/ia6cho_m.bin" # NB: Contains only oni chart
|
||||
fnameTJA = "test-data/Rokuchounen to Ichiya Monogatari.tja" # NB: Contains 5 charts
|
||||
fumen, tja = main(fnameFumen, fnameTJA)
|
||||
|
Loading…
x
Reference in New Issue
Block a user