From 581ccddab81e43d53161fba04b3b29801cd9d718 Mon Sep 17 00:00:00 2001 From: biosp4rk <37962487+biosp4rk@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:59:04 -0700 Subject: [PATCH 1/3] Update break/line info for meta chars --- src/mars_patcher/text.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/mars_patcher/text.py b/src/mars_patcher/text.py index 5bd7ae9..fbf3485 100644 --- a/src/mars_patcher/text.py +++ b/src/mars_patcher/text.py @@ -125,15 +125,9 @@ def encode_text( escaped = False markup_tag: list[str] | None = None - def handle_break() -> None: - nonlocal prev_break, width_since_break, line_width, line_number - prev_break = len(text) - width_since_break = 0 - if char_val in NEWLINE_CHARS: - line_width = 0 - line_number += 1 - for char in string: + is_meta_char = False + if not escaped: # Check for escaped character if char == "\\": @@ -157,23 +151,27 @@ def handle_break() -> None: char_val = char_map.get(f"[{tag_str}]") if char_val is None: raise ValueError(f"Invalid markup tag '{tag_str}'") - if char_val in NEWLINE_CHARS: - handle_break() - text.append(char_val) + is_meta_char = True markup_tag = None else: + # Still parsing markup tag markup_tag.append(char) - continue + continue else: escaped = False - char_val = char_map[char] - char_width = get_char_width(rom, char_widths_addr, char_val) - line_width += char_width - width_since_break += char_width + if not is_meta_char: + char_val = char_map[char] + char_width = get_char_width(rom, char_widths_addr, char_val) + line_width += char_width + width_since_break += char_width if char_val in BREAKING_CHARS: - handle_break() + prev_break = len(text) + width_since_break = 0 + if char_val in NEWLINE_CHARS: + line_width = 0 + line_number += 1 extra_char = None @@ -206,6 +204,8 @@ def handle_break() -> None: else: text.append(extra_char) + if char_val is None: + raise ValueError("Tried to append null char_val") text.append(char_val) if markup_tag is not None: From 5b78980f6295387e4f402b015cd4a266fcd03243 Mon Sep 17 00:00:00 2001 From: biosp4rk <37962487+biosp4rk@users.noreply.github.com> Date: Wed, 10 Sep 2025 14:13:01 -0700 Subject: [PATCH 2/3] Handle NEXT char --- src/mars_patcher/text.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/mars_patcher/text.py b/src/mars_patcher/text.py index fbf3485..1805af6 100644 --- a/src/mars_patcher/text.py +++ b/src/mars_patcher/text.py @@ -126,8 +126,6 @@ def encode_text( markup_tag: list[str] | None = None for char in string: - is_meta_char = False - if not escaped: # Check for escaped character if char == "\\": @@ -151,20 +149,27 @@ def encode_text( char_val = char_map.get(f"[{tag_str}]") if char_val is None: raise ValueError(f"Invalid markup tag '{tag_str}'") - is_meta_char = True + if char_val in NEWLINE_CHARS: + prev_break = len(text) + width_since_break = 0 + line_width = 0 + if char_val == NEXT: + line_number = 0 + else: + line_number += 1 + text.append(char_val) markup_tag = None else: # Still parsing markup tag markup_tag.append(char) - continue + continue else: escaped = False - if not is_meta_char: - char_val = char_map[char] - char_width = get_char_width(rom, char_widths_addr, char_val) - line_width += char_width - width_since_break += char_width + char_val = char_map[char] + char_width = get_char_width(rom, char_widths_addr, char_val) + line_width += char_width + width_since_break += char_width if char_val in BREAKING_CHARS: prev_break = len(text) From 6df91bfa6205fa3a2b1e59c4b407104d75a5fede Mon Sep 17 00:00:00 2001 From: biosp4rk <37962487+biosp4rk@users.noreply.github.com> Date: Wed, 10 Sep 2025 14:14:34 -0700 Subject: [PATCH 3/3] Remove char_val None check --- src/mars_patcher/text.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mars_patcher/text.py b/src/mars_patcher/text.py index 1805af6..7ea7221 100644 --- a/src/mars_patcher/text.py +++ b/src/mars_patcher/text.py @@ -209,8 +209,6 @@ def encode_text( else: text.append(extra_char) - if char_val is None: - raise ValueError("Tried to append null char_val") text.append(char_val) if markup_tag is not None: