From 653d84738a2c0b96d6484805032e16d2516b647b Mon Sep 17 00:00:00 2001 From: dusk Date: Sun, 18 Feb 2024 22:52:25 +0100 Subject: [PATCH] Fix until chapter 2 --- src/flow.py | 74 ++++++++++++++++++++++++++--------------------------- src/orig.py | 45 +++++++++++++++++--------------- 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/src/flow.py b/src/flow.py index c45e745..c5ef58f 100644 --- a/src/flow.py +++ b/src/flow.py @@ -5,42 +5,42 @@ onik = { 'onik_000.txt', 'onik_001.txt', 'onik_002.txt', - 'onik_003.txt', - 'onik_004.txt', - 'onik_005.txt', - 'onik_009.txt', - 'onik_009_02.txt', - 'onik_010.txt', - 'onik_011.txt', - 'onik_012.txt', - 'onik_013.txt', - 'onik_014.txt', - 'onik_014_02.txt', - 'onik_015.txt', - 'onik_015_02.txt', - 'onik_015_03.txt', + # 'onik_003.txt', + # 'onik_004.txt', + # 'onik_005.txt', + # 'onik_009.txt', + # 'onik_009_02.txt', + # 'onik_010.txt', + # 'onik_011.txt', + # 'onik_012.txt', + # 'onik_013.txt', + # 'onik_014.txt', + # 'onik_014_02.txt', + # 'onik_015.txt', + # 'onik_015_02.txt', + # 'onik_015_03.txt', ], - "Opening" : [ 'onik_op.txt' ], - "Sub_Tips_001" : [ 'onik_tips_01.txt' ], - "Sub_Tips_002" : [ 'onik_tips_02.txt' ], - "Sub_Tips_003" : [ 'onik_tips_03.txt' ], - "Sub_Tips_004" : [ 'onik_tips_04.txt' ], - "Sub_Tips_005" : [ 'onik_tips_05.txt' ], - "Sub_Tips_006" : [ 'onik_tips_06.txt' ], - "Sub_Tips_006" : [ 'onik_tips_06.txt' ], - "Sub_Tips_007" : [ 'onik_tips_07.txt' ], - "Sub_Tips_008" : [ 'onik_tips_08.txt' ], - "Sub_Tips_009" : [ 'onik_tips_09.txt' ], - "Sub_Tips_010" : [ 'onik_tips_10.txt' ], - "Sub_Tips_011" : [ 'onik_tips_11.txt' ], - "Sub_Tips_012" : [ 'onik_tips_12.txt' ], - "Sub_Tips_013" : [ 'onik_tips_13.txt' ], - "Sub_Tips_014" : [ 'onik_tips_14.txt' ], - "Sub_Tips_015" : [ 'onik_tips_15.txt' ], - "Sub_Tips_016" : [ 'onik_tips_16.txt' ], - "Sub_Tips_016" : [ 'onik_tips_16.txt' ], - "Sub_Tips_017" : [ 'onik_tips_17.txt' ], - "Sub_Tips_018" : [ 'onik_tips_18.txt' ], - "Sub_Tips_019" : [ 'onik_tips_19.txt' ], - "Sub_Tips_020" : [ 'onik_tips_20.txt' ], + # "Opening" : [ 'onik_op.txt' ], + # "Sub_Tips_001" : [ 'onik_tips_01.txt' ], + # "Sub_Tips_002" : [ 'onik_tips_02.txt' ], + # "Sub_Tips_003" : [ 'onik_tips_03.txt' ], + # "Sub_Tips_004" : [ 'onik_tips_04.txt' ], + # "Sub_Tips_005" : [ 'onik_tips_05.txt' ], + # "Sub_Tips_006" : [ 'onik_tips_06.txt' ], + # "Sub_Tips_006" : [ 'onik_tips_06.txt' ], + # "Sub_Tips_007" : [ 'onik_tips_07.txt' ], + # "Sub_Tips_008" : [ 'onik_tips_08.txt' ], + # "Sub_Tips_009" : [ 'onik_tips_09.txt' ], + # "Sub_Tips_010" : [ 'onik_tips_10.txt' ], + # "Sub_Tips_011" : [ 'onik_tips_11.txt' ], + # "Sub_Tips_012" : [ 'onik_tips_12.txt' ], + # "Sub_Tips_013" : [ 'onik_tips_13.txt' ], + # "Sub_Tips_014" : [ 'onik_tips_14.txt' ], + # "Sub_Tips_015" : [ 'onik_tips_15.txt' ], + # "Sub_Tips_016" : [ 'onik_tips_16.txt' ], + # "Sub_Tips_016" : [ 'onik_tips_16.txt' ], + # "Sub_Tips_017" : [ 'onik_tips_17.txt' ], + # "Sub_Tips_018" : [ 'onik_tips_18.txt' ], + # "Sub_Tips_019" : [ 'onik_tips_19.txt' ], + # "Sub_Tips_020" : [ 'onik_tips_20.txt' ], } diff --git a/src/orig.py b/src/orig.py index 210e89a..24f2e1a 100755 --- a/src/orig.py +++ b/src/orig.py @@ -7,6 +7,7 @@ from unidecode import unidecode import config import parser import flow +import fix japanese_ranges = [ (0x4E00, 0x9FFF), # Kanji @@ -14,17 +15,22 @@ japanese_ranges = [ (0x30A0, 0x30FF), # Katakana (0xFF00, 0xFFEF), # Full-width Roman characters and symbols (0x3000, 0x303F), # CJK symbols and punctuation (including 「」) + (8220, 8220), # The character “ ] +debug_current_line = -1 def process_sections(): output_filepath = os.path.join(config.get('output_path'), 'out.txt') outfile = open(output_filepath, 'w', encoding='shift_jisx0213') - origfile = open(config.get('original_path'), 'r', encoding='shift_jisx0213') + origfile = open(fix.open_onikakushi(), 'r', encoding='shift_jisx0213') sections = dict() for line in origfile: + global debug_current_line + debug_current_line += 1 + if line.startswith('*'): section_name = line[1:].split(' ', 1)[0].replace('\n','') @@ -52,6 +58,7 @@ def get_symbols(line: str) -> list[str]: while i < len(line): if line[i] in ['@', '/', '¥']: symbol = line[i] + i += 1 elif line[i:i+3] == '!sd': symbol = line[i:i+3] i += 3 @@ -64,27 +71,23 @@ def get_symbols(line: str) -> list[str]: continue symbol = line[x:i] - - # The i is going to get incremented - # later, gotta have to account that - i -= 1 break elif line[i] == '!': raise Exception('Unhandled symbol', line) else: # It's not a symbol, it's a regular character + #print(line[i]) inbetween += 1 i += 1 continue # Only reaches this if it's a symbol + #print(symbol) if inbetween > 0: res.append(symbol) else: res[-1] += symbol inbetween = 0 - i += 1 - return res @@ -95,7 +98,10 @@ def write_translated(outfile, origfile, translation_file_paths): print(f'- reading "{transfilepath}"') structure = parser.parse_to_structure(transfilepath) - for i, line in enumerate(origfile): + for line in origfile: + global debug_current_line + debug_current_line += 1 + # Check if the current line is a dialogue line or not found = False for start, end in japanese_ranges: @@ -103,27 +109,23 @@ def write_translated(outfile, origfile, translation_file_paths): found = True if found: - # The amount of lines may not coincide because the original - # might have one line for what we have multiple lines. Count - # the number of appearances of the end-of-command symbols - # (@ and ¥) to determine how many of the translated lines is - # equivalent to the given original line. - amount = line.count("@") + line.count("¥") + line.count('/') - symbols = get_symbols(line) - print("\n-", transfilepath, symbols) + print("\n-", debug_current_line, transfilepath, symbols) outfile.write('`') - _printed_line = "" + _printed_line_jp = "" + _printed_line_en = "" while True: - _printed_line += structure[0].text_jp + _printed_line_jp += structure[0].text_jp + _printed_line_en += structure[0].text_en outfile.write( unidecode(structure.pop(0).text_en) ) if len(symbols) > 0: - _printed_line += symbols[0] + _printed_line_jp += symbols[0] + _printed_line_en += symbols[0] outfile.write(symbols.pop(0)) if len(symbols) <= 0: @@ -131,9 +133,12 @@ def write_translated(outfile, origfile, translation_file_paths): outfile.write('\n') - print(">", _printed_line) + print(">", _printed_line_en) + print(">", _printed_line_jp) print("<", line, end='') + if _printed_line_jp+'\n' != line: + raise Exception('UGABUNGA') # Used up all of the structures, this chapter has ended. # Got to the next one