From 77db14386b19c58aeabeb50e28bfde27169b8f7d Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 28 Feb 2024 20:20:34 +0100 Subject: [PATCH] Use the new csv files for nscripter generation --- src/orig.py | 32 +++++++++++++++++++++++--------- src/parser.py | 4 +--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/orig.py b/src/orig.py index a037b42..1304c72 100755 --- a/src/orig.py +++ b/src/orig.py @@ -14,6 +14,8 @@ import fix debug_current_line = -1 def process_sections(): + output_path = config.get('output_path') + output_filepath = os.path.join(config.get('output_path'), 'out.txt') outfile = open(output_filepath, 'w', encoding='shift_jisx0213') origfile = open(fix.open_onikakushi(), 'r', encoding='shift_jisx0213') @@ -29,14 +31,27 @@ def process_sections(): outfile.write(line) - if section_name in flow.onik: - print("entering", section_name) - write_translated( - outfile, - origfile, - flow.onik[section_name], - ) - print("finished section: ", section_name) + # Try to look for a {section_name}.csv file + # csv_paths will contain the array of CSV paths to translation files + csv_path = os.path.join(output_path, 'trans', section_name + '.csv') + csv_paths = [ csv_path ] + if not os.path.exists(csv_path): + # Not found, try to look for a {section_name}/*.csv folder with files + csv_path = os.path.join(output_path, 'trans', section_name) + if not os.path.isdir(csv_path): + continue + + root, _, files = next(os.walk(csv_path)) + csv_paths = [os.path.join(root, x) for x in files] + csv_paths.sort() + + print("entering", section_name) + write_translated( + outfile, + origfile, + csv_paths, + ) + print("finished section: ", section_name) else: outfile.write(line) @@ -76,7 +91,6 @@ def swap_line_text(tokens, translation_lines: list[parser.OutputLine]) -> (str, def write_translated(outfile, origfile, translation_file_paths): for transfilepath in translation_file_paths: print(f'- reading "{transfilepath}"') - parser.parse_to_csv(transfilepath) structure = parser.parse_to_structure(transfilepath) for line in origfile: diff --git a/src/parser.py b/src/parser.py index ae8286a..94ec408 100755 --- a/src/parser.py +++ b/src/parser.py @@ -143,12 +143,10 @@ def parse_to_csv(): def parse_to_structure(filename: str) -> list[OutputLine]: - out_path = config.get('output_path') - csvname = os.path.join(out_path, filename + ".csv") escapechar = config.get('csv_escapechar') delchar = config.get('csv_delchar') - with open(csvname, 'r') as csvfile: + with open(filename, 'r') as csvfile: csv_reader = csv.reader( csvfile, delimiter=delchar,