style: ruff format
This commit is contained in:
@@ -7,6 +7,7 @@ from ..forge_data import ForgeData
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def debug_image(im: Image.Image) -> None:
|
def debug_image(im: Image.Image) -> None:
|
||||||
im = im.resize((1280, 640)).convert("RGB")
|
im = im.resize((1280, 640)).convert("RGB")
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from ..display import BLANK_IMG, FONT_1, FONT_2
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def generate_loading_image() -> None:
|
def generate_loading_image() -> None:
|
||||||
im = BLANK_IMG.copy()
|
im = BLANK_IMG.copy()
|
||||||
|
|
||||||
|
|||||||
@@ -29,20 +29,23 @@ const int lengths[] = int[SENTENCE_COUNT](
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def read_mapping() -> dict[str, str]:
|
def read_mapping() -> dict[str, str]:
|
||||||
mapping = {' ': '0x20'}
|
mapping = {" ": "0x20"}
|
||||||
with CP437_FILE.open() as cp437:
|
with CP437_FILE.open() as cp437:
|
||||||
for line in 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)
|
mapping[match.group(2)] = match.group(1)
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
|
|
||||||
def read_sentences() -> list[str]:
|
def read_sentences() -> list[str]:
|
||||||
if SENTENCES_FILE.exists():
|
if SENTENCES_FILE.exists():
|
||||||
return SENTENCES_FILE.read_text().splitlines()
|
return SENTENCES_FILE.read_text().splitlines()
|
||||||
log.warning("sentences.txt not found, using backup")
|
log.warning("sentences.txt not found, using backup")
|
||||||
return BACKUP_SENTENCES_FILE.read_text().splitlines()
|
return BACKUP_SENTENCES_FILE.read_text().splitlines()
|
||||||
|
|
||||||
|
|
||||||
def convert(sentence: str, mapping: dict[str, str], max_len: int) -> str:
|
def convert(sentence: str, mapping: dict[str, str], max_len: int) -> str:
|
||||||
out = []
|
out = []
|
||||||
for i in range(max_len):
|
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]]]
|
out += [mapping[sentence[i]]]
|
||||||
return ", ".join(out)
|
return ", ".join(out)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
mapping = read_mapping()
|
mapping = read_mapping()
|
||||||
sentences = read_sentences()
|
sentences = read_sentences()
|
||||||
@@ -66,15 +70,17 @@ def main():
|
|||||||
len(sentences),
|
len(sentences),
|
||||||
max_len,
|
max_len,
|
||||||
"".join(
|
"".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)
|
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}")
|
log.info(f"Wrote {len(sentences)} sentences to {TARGET_FILE}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user