diff --git a/src/forge_invar/tools/debug_img.py b/src/forge_invar/tools/debug_img.py index 26091ee..534e97b 100644 --- a/src/forge_invar/tools/debug_img.py +++ b/src/forge_invar/tools/debug_img.py @@ -7,6 +7,7 @@ from ..forge_data import ForgeData log = logging.getLogger(__name__) + def debug_image(im: Image.Image) -> None: im = im.resize((1280, 640)).convert("RGB") diff --git a/src/forge_invar/tools/gen_img.py b/src/forge_invar/tools/gen_img.py index 8896d95..e27487f 100644 --- a/src/forge_invar/tools/gen_img.py +++ b/src/forge_invar/tools/gen_img.py @@ -10,6 +10,7 @@ from ..display import BLANK_IMG, FONT_1, FONT_2 log = logging.getLogger(__name__) + def generate_loading_image() -> None: im = BLANK_IMG.copy() diff --git a/src/forge_invar/tools/sentences.py b/src/forge_invar/tools/sentences.py index 01d9d0b..16ee010 100644 --- a/src/forge_invar/tools/sentences.py +++ b/src/forge_invar/tools/sentences.py @@ -29,20 +29,23 @@ const int lengths[] = int[SENTENCE_COUNT]( log = logging.getLogger(__name__) + def read_mapping() -> dict[str, str]: - mapping = {' ': '0x20'} + mapping = {" ": "0x20"} with CP437_FILE.open() as cp437: for line in cp437: - if (match := re.match(r'.*// (0x\w\w), (.)$', line)): + if match := re.match(r".*// (0x\w\w), (.)$", line): mapping[match.group(2)] = match.group(1) return mapping + def read_sentences() -> list[str]: if SENTENCES_FILE.exists(): return SENTENCES_FILE.read_text().splitlines() log.warning("sentences.txt not found, using backup") return BACKUP_SENTENCES_FILE.read_text().splitlines() + def convert(sentence: str, mapping: dict[str, str], max_len: int) -> str: out = [] for i in range(max_len): @@ -55,6 +58,7 @@ def convert(sentence: str, mapping: dict[str, str], max_len: int) -> str: out += [mapping[sentence[i]]] return ", ".join(out) + def main(): mapping = read_mapping() sentences = read_sentences() @@ -66,15 +70,17 @@ def main(): len(sentences), max_len, "".join( - " " + convert(sentence, mapping, max_len) + ("," if i < len(sentences) - 1 else " ") + f" // {sentence}\n" + " " + + convert(sentence, mapping, max_len) + + ("," if i < len(sentences) - 1 else " ") + + f" // {sentence}\n" for i, sentence in enumerate(sentences) ), - " " + ", ".join(str(len(sentence)) for sentence in sentences) + "\n" + " " + ", ".join(str(len(sentence)) for sentence in sentences) + "\n", ) ) log.info(f"Wrote {len(sentences)} sentences to {TARGET_FILE}") - if __name__ == "__main__": main()