From 5e7295cf7223f0952e13079e9d677278c6115e7a Mon Sep 17 00:00:00 2001 From: dusk Date: Sun, 18 Feb 2024 20:28:09 +0100 Subject: [PATCH] Get symbols from each line --- src/orig.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/test.py diff --git a/src/orig.py b/src/orig.py index 2bc44ac..d1c2824 100755 --- a/src/orig.py +++ b/src/orig.py @@ -44,6 +44,49 @@ def process_sections(): origfile.close() +def get_symbols(line: str) -> list[str]: + res = [] + + inbetween = 0 + i = 0 + while i < len(line): + if line[i] in ['@', '/', '¥']: + if inbetween > 0: + res.append(line[i]) + else: + res[-1] += line[i] + inbetween = 0 + elif line[i:i+3] == '!sd': + if inbetween > 0: + res.append(line[i:i+3]) + else: + res[-1] += line[i:i+3] + inbetween = 0 + i += 3 + elif line[i:i+2] in ['!d', '!w', '!s']: + x = i + i += 2 + while i < len(line): + if line[i].isdigit(): + i += 1 + continue + + if inbetween > 0: + res.append(line[x:i]) + else: + res[-1] += line[x:i] + inbetween = 0 + break + elif line[i] == '!': + raise Exception('Unhandled symbol', line) + else: + inbetween += 1 + + i += 1 + + return res + + # Given a set of translation files, the original file and the output file # replace the japanese lines with the translated ones in a given section. def write_translated(outfile, origfile, translation_file_paths): @@ -52,6 +95,7 @@ def write_translated(outfile, origfile, translation_file_paths): structure = parser.parse_to_structure(transfilepath) for i, line in enumerate(origfile): + # Check if the current line is a dialogue line or not found = False for start, end in japanese_ranges: if start <= ord(line[0]) <= end: @@ -65,6 +109,10 @@ def write_translated(outfile, origfile, translation_file_paths): # equivalent to the given original line. amount = line.count("@") + line.count("¥") + line.count('/') + symbols = get_symbols(line) + print(symbols, line, end='') + continue + outfile.write('`') _printed_line = "" diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..f8fe1ab --- /dev/null +++ b/src/test.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +def split_line(line: str) -> list[str]: + res = [] + + i = 0 + while i < len(line): + if line[i] in ['@', '/', '¥']: + res.append(line[i]) + elif line[i:i+3] == '!sd': + res.append(line[i:i+3]) + i += 3 + elif line[i:i+2] in ['!d', '!w']: + print("tefntyuf") + x = i + i += 2 + while i < len(line): + if line[i].isdigit(): + print(x, i) + i += 1 + continue + + res.append(line[x:i]) + break + + i += 1 + + return res