__init__.py
: Refactor repeatable steps into function
This commit is contained in:
parent
86c8909b0f
commit
c108475026
@ -21,26 +21,29 @@ def main(argv=None):
|
|||||||
)
|
)
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
fnameTJA = getattr(args, "file.tja")
|
fnameTJA = getattr(args, "file.tja")
|
||||||
|
|
||||||
# Convert TJA data to fumen data
|
|
||||||
parsedSongsTJA = parseTJA(fnameTJA)
|
|
||||||
parsedSongsFumen = {course: convertTJAToFumen(tjaData)
|
|
||||||
for course, tjaData in parsedSongsTJA.items()}
|
|
||||||
|
|
||||||
# Generate output filenames
|
|
||||||
baseName = os.path.splitext(fnameTJA)[0]
|
baseName = os.path.splitext(fnameTJA)[0]
|
||||||
outputFilenames = []
|
|
||||||
for courseName, fumenData in parsedSongsFumen.items():
|
# Parse lines in TJA file
|
||||||
if len(parsedSongsTJA) == 1:
|
parsedTJACourses = parseTJA(fnameTJA)
|
||||||
outputName = f"{baseName}.bin"
|
|
||||||
else:
|
# Convert parsed TJA courses to Fumen data, and write each course to `.bin` files
|
||||||
splitName = courseName.split("P") # e.g. 'OniP2' -> ['Oni', '2'], 'Oni' -> ['Oni']
|
for parsedCourse in parsedTJACourses.items():
|
||||||
outputName = f"{baseName}_{COURSE_IDS[splitName[0]]}"
|
convert_and_write(parsedCourse, baseName, singleCourse=(len(parsedTJACourses) == 1))
|
||||||
if len(splitName) == 2:
|
|
||||||
outputName += f"_{splitName[1]}" # Add "_1" or "_2" if P1/P2 chart
|
|
||||||
outputName += ".bin"
|
def convert_and_write(parsedCourse, baseName, singleCourse=False):
|
||||||
outputFilenames.append(outputName)
|
courseName, tjaData = parsedCourse
|
||||||
writeFumen(outputName, fumenData)
|
fumenData = convertTJAToFumen(tjaData)
|
||||||
|
# Add course ID (e.g. '_x', '_x_1', '_x_2') to the output file's base name
|
||||||
|
outputName = baseName
|
||||||
|
if singleCourse:
|
||||||
|
pass # Replicate tja2bin.exe behavior by excluding course ID if there's only one course
|
||||||
|
else:
|
||||||
|
splitName = courseName.split("P") # e.g. 'OniP2' -> ['Oni', '2'], 'Oni' -> ['Oni']
|
||||||
|
outputName += f"_{COURSE_IDS[splitName[0]]}"
|
||||||
|
if len(splitName) == 2:
|
||||||
|
outputName += f"_{splitName[1]}" # Add "_1" or "_2" if P1/P2 chart
|
||||||
|
writeFumen(f"{outputName}.bin", fumenData)
|
||||||
|
|
||||||
|
|
||||||
# NB: This entry point is necessary for the Pyinstaller executable
|
# NB: This entry point is necessary for the Pyinstaller executable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user