From 90f3d7902f3f4a2ed7ca1f84a51db8311aafefae Mon Sep 17 00:00:00 2001 From: Viv Date: Sun, 4 Jun 2023 12:18:45 -0400 Subject: [PATCH] `main.py`: Remove `fumen`-parsing code and make TJA mandatory Fumen code was just for debugging purposes, and not necessary for TJA conversion. --- src/tja2fumen/converters.py | 2 +- src/tja2fumen/main.py | 42 +++++++++++-------------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/tja2fumen/converters.py b/src/tja2fumen/converters.py index 9a5ff2e..35bbcbc 100644 --- a/src/tja2fumen/converters.py +++ b/src/tja2fumen/converters.py @@ -97,7 +97,7 @@ def preprocessTJAMeasures(tja): return measuresCorrected -def convertTJAToFumen(fumen, tja): +def convertTJAToFumen(tja): # Hardcode currentBranch due to current lack of support for branching songs currentBranch = 'normal' # TODO: Program in branch support tja['measures'] = preprocessTJAMeasures(tja) diff --git a/src/tja2fumen/main.py b/src/tja2fumen/main.py index be08a26..ae12312 100644 --- a/src/tja2fumen/main.py +++ b/src/tja2fumen/main.py @@ -1,46 +1,28 @@ import argparse import os -from tja2fumen.parsers import readFumen, parseTJA +from tja2fumen.parsers import parseTJA from tja2fumen.writers import writeFumen from tja2fumen.converters import convertTJAToFumen -from tja2fumen.utils import checkMismatchedBytes from tja2fumen.constants import COURSE_IDS tja2fumen_version = "v0.1" -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 - 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 - +def main(fnameTJA): convertedTJAs = {} - if fnameTJA: - # Parse tja - try: - inputFile = open(fnameTJA, "r", encoding="utf-8-sig") - parsedSongsTJA = parseTJA(inputFile) - except UnicodeDecodeError: - inputFile = open(fnameTJA, "r", encoding="shift-jis") - parsedSongsTJA = parseTJA(inputFile) + try: + inputFile = open(fnameTJA, "r", encoding="utf-8-sig") + parsedSongsTJA = parseTJA(inputFile) + except UnicodeDecodeError: + inputFile = open(fnameTJA, "r", encoding="shift-jis") + parsedSongsTJA = parseTJA(inputFile) - for course, song in parsedSongsTJA.items(): - convertedTJA = convertTJAToFumen(parsedSongFumen, song) - convertedTJAs[course] = convertedTJA + for course, song in parsedSongsTJA.items(): + convertedTJA = convertTJAToFumen(song) + convertedTJAs[course] = convertedTJA - return parsedSongFumen, convertedTJAs + return convertedTJAs if __name__ == "__main__":