Fixing starting newlines

This commit is contained in:
GearsProgress 2026-03-19 19:38:46 -04:00
parent b4dd515502
commit e10d4cc044
4 changed files with 22 additions and 11 deletions

View File

@ -166,8 +166,8 @@ void setup(const u16 *debug_charset)
text_data_table general_text(general_text_table_buffer); text_data_table general_text(general_text_table_buffer);
general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
ptgb_write_textbox(general_text.get_text_entry(GENERAL_connecting), true, true, ptgb_write_textbox(general_text.get_text_entry(GENERAL_connecting), true, false,
GENERAL_INDEX, GENERAL_connecting, true); GENERAL_INDEX, GENERAL_connecting, false);
} }
} }

View File

@ -127,7 +127,7 @@ int text_loop(int script)
if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB) if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB)
{ {
ptgb_write_textbox(curr_text, false, true, ptgb_write_textbox(curr_text, false, true,
PTGB_INDEX, curr_line.get_text_entry_index(), true); PTGB_INDEX, curr_line.get_text_entry_index(), false);
} }
// wait_for_user_to_continue(); // wait_for_user_to_continue();
@ -149,6 +149,7 @@ int text_loop(int script)
if (text_exit) if (text_exit)
{ {
hide_textbox(); hide_textbox();
erase_textbox_tiles();
tte_erase_screen(); tte_erase_screen();
text_exit = false; text_exit = false;
return 0; return 0;
@ -198,13 +199,13 @@ int text_loop(int script)
} }
if (update_text) if (update_text)
{ {
if (text_key > text_section_lengths[text_section]) if (text_key >= text_section_lengths[text_section])
{ {
text_key = text_section_lengths[text_section]; text_key = text_section_lengths[text_section] - 1;
} }
if (text_section > NUM_TEXT_SECTIONS) if (text_section >= NUM_TEXT_SECTIONS)
{ {
text_section = NUM_TEXT_SECTIONS; text_section = NUM_TEXT_SECTIONS - 1;
} }
tte_set_pos(0, 0); tte_set_pos(0, 0);
tte_erase_rect(0, 0, 240, 160); tte_erase_rect(0, 0, 240, 160);
@ -269,6 +270,7 @@ void set_text_exit()
int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser,
int text_section, int text_key, bool eraseMainBox) int text_section, int text_key, bool eraseMainBox)
{ {
erase_textbox_tiles();
create_textbox_new(text_section, text_key, eraseMainBox); create_textbox_new(text_section, text_key, eraseMainBox);
int out = ptgb_write(text, instant, 9999, text_box_type_tables[text_section][text_key]); // This is kinda silly but it'll work. int out = ptgb_write(text, instant, 9999, text_box_type_tables[text_section][text_key]); // This is kinda silly but it'll work.
if (waitForUser) if (waitForUser)

View File

@ -317,13 +317,13 @@ def split_sentence_into_lines(sentence, offset, pixelsPerChar, pixelsInLine, cen
elif (sentence == "ɑ" or sentence == "Ω"): elif (sentence == "ɑ" or sentence == "Ω"):
if (sentence == "ɑ"): if (sentence == "ɑ"):
centered = True centered = True
# If this is the first thing being added to outStr, don't add a newline # Only advance when centering starts in the middle of an occupied line.
if (currLineCount != 0): if (currLineCount != 0 and offset != 0):
outStr += "Ň" outStr += "Ň"
else: else:
centered = False centered = False
# Only advance if we're not already at the end of the box. # Only advance when centered text actually occupied the current line.
if (currLineCount != numLines): if (currLineCount != numLines and offset != 0):
outStr += "Ň" outStr += "Ň"
currLine = "" currLine = ""
offset = 0 offset = 0
@ -411,6 +411,10 @@ def hash_file_bytes(path):
return h.digest() return h.digest()
def apply_escape_sequences(line, arr, escape_list): def apply_escape_sequences(line, arr, escape_list):
# Convert structural text controls to the formatter's internal sentinels
# before generic escape replacement so layout logic can see them reliably.
line = line.replace("{NEW}", 'Ň')
for token, char_indexes in escape_list: for token, char_indexes in escape_list:
if token in line: if token in line:
escape_string = "".join(arr[idx] for idx in char_indexes) escape_string = "".join(arr[idx] for idx in char_indexes)
@ -514,6 +518,7 @@ def convert_item(ogDict, lang):
outIndex += 1 outIndex += 1
# Make sure both kinds of newlines are being accounted for # Make sure both kinds of newlines are being accounted for
box = box.replace('Ş', 'Ň') box = box.replace('Ş', 'Ň')
leading_newlines = len(box) - len(box.lstrip('Ň'))
splitLines = box.split('Ň') splitLines = box.split('Ň')
outBox = "" outBox = ""
i = 1 i = 1
@ -528,6 +533,10 @@ def convert_item(ogDict, lang):
outBox += split + breakChar outBox += split + breakChar
outIndex += 1 outIndex += 1
i += 1 i += 1
if leading_newlines:
existing_leading_newlines = len(outBox) - len(outBox.lstrip('Ň'))
if existing_leading_newlines < leading_newlines:
outBox = ('Ň' * (leading_newlines - existing_leading_newlines)) + outBox
if (outBox and (outBox[:-1] == 'ȼ') or (outBox[:-1] == 'Ň')): if (outBox and (outBox[:-1] == 'ȼ') or (outBox[:-1] == 'Ň')):
newStr += f'{outBox[:-1]}ȼ' newStr += f'{outBox[:-1]}ȼ'
elif (outBox): elif (outBox):

Binary file not shown.