From d95175754d2d84ab4d5f5181c23be1705feb8b49 Mon Sep 17 00:00:00 2001 From: Viv Date: Sat, 10 Feb 2024 13:31:59 -0500 Subject: [PATCH] `parsers.py`: Handle typos for data before first `COURSE:` Fixes https://github.com/vivaria/tja2fumen/issues/70. --- src/tja2fumen/parsers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tja2fumen/parsers.py b/src/tja2fumen/parsers.py index 35041f5..64625cf 100644 --- a/src/tja2fumen/parsers.py +++ b/src/tja2fumen/parsers.py @@ -5,6 +5,7 @@ Functions for parsing TJA files (.tja) and Fumen files (.bin) import os import re import struct +import warnings from copy import deepcopy from typing import BinaryIO, Any, List, Dict, Tuple @@ -141,7 +142,11 @@ def split_tja_lines_into_courses(lines: List[str]) -> TJASong: # Case 3: For other commands and data, simply copy as-is (parse later) else: - parsed_tja.courses[current_course].data.append(line) + if current_course: + parsed_tja.courses[current_course].data.append(line) + else: + warnings.warn(f"Data encountered before first COURSE: " + f"'{line}' (Check for typos in TJA)") # If a .tja has "STYLE: Double" but no "STYLE: Single", then it will be # missing data for the "single player" chart. To fix this, we copy over