tja2fumen.py
: Refactor main steps into main()
function
This commit is contained in:
parent
7239a00e76
commit
35159ea793
@ -6,27 +6,25 @@ 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 = {
|
|
||||||
"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
|
# Parse fumen
|
||||||
inputFile = open(arguments["input_fumen"], "rb")
|
inputFile = open(fnameFumen, "rb")
|
||||||
parsedSongFumen = readFumen(inputFile)
|
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")
|
outputFile = open(outputName, "wb")
|
||||||
writeFumen(outputFile, parsedSongFumen)
|
writeFumen(outputFile, parsedSongFumen)
|
||||||
# Read output file back in to validate that the rewritten song is a perfect match
|
# 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)
|
print(False if checkMismatchedBytes(inputFile.name, outputFile.name) else True)
|
||||||
|
else:
|
||||||
|
parsedSongFumen = None
|
||||||
|
|
||||||
|
if fnameTJA:
|
||||||
# Parse tja
|
# Parse tja
|
||||||
inputFile = open(arguments["input_tja"], "r", encoding="utf-8-sig")
|
inputFile = open(fnameTJA, "r", encoding="utf-8-sig")
|
||||||
parsedSongsTJA = parseTJA(inputFile)
|
parsedSongsTJA = parseTJA(inputFile)
|
||||||
|
|
||||||
# Try converting the Oni TJA chart to match the Oni fumen
|
# Try converting the Oni TJA chart to match the Oni fumen
|
||||||
@ -34,3 +32,13 @@ if __name__ == "__main__":
|
|||||||
outputName = inputFile.name.split('.')[0] + ".bin"
|
outputName = inputFile.name.split('.')[0] + ".bin"
|
||||||
outputFile = open(outputName, "wb")
|
outputFile = open(outputName, "wb")
|
||||||
writeFumen(outputFile, convertedTJA)
|
writeFumen(outputFile, convertedTJA)
|
||||||
|
else:
|
||||||
|
convertedTJA = None
|
||||||
|
|
||||||
|
return parsedSongFumen, 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