Files
Jonathan Tinney 7971961166
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
add schedule I, sonic 1/frontiers/heroes, spirit island
2026-04-02 23:46:36 -07:00

60 lines
2.1 KiB
Python

import json
from pathlib import Path
import Utils
from ..RomData import RomData
from ..text.decoding import parse_text_dict, parse_all_texts
def load_vanilla_dict_data(seasons: bool) -> None | dict[str, str]:
"""
Gets the vanilla dict, this is always assumed to already exist
"""
game_name = "seasons" if seasons else "ages"
text_dir = Path(Utils.cache_path("oos_ooa/text"))
vanilla_text_file = text_dir.joinpath(f"{game_name}_dict.json")
return json.load(open(vanilla_text_file, encoding="utf-8"))
def load_vanilla_text_data(seasons: bool) -> None | dict[str, str]:
game_name = "seasons" if seasons else "ages"
text_dir = Path(Utils.cache_path("oos_ooa/text"))
vanilla_text_file = text_dir.joinpath(f"{game_name}_texts_vanilla.json")
if not vanilla_text_file.is_file():
return None
return json.load(open(vanilla_text_file, encoding="utf-8"))
def save_vanilla_text_data(dictionary: dict[str, str],
texts: dict[str, str],
seasons: bool) -> None:
text_dir = Path(Utils.cache_path("oos_ooa/text"))
text_dir.mkdir(parents=True, exist_ok=True)
game_name = "seasons" if seasons else "ages"
dict_file = text_dir.joinpath(f"{game_name}_dict.json")
text_file = text_dir.joinpath(f"{game_name}_texts_vanilla.json")
with dict_file.open("w", encoding="utf-8") as f:
json.dump(dictionary, f, ensure_ascii=False)
with text_file.open("w", encoding="utf-8") as f:
json.dump(texts, f, ensure_ascii=False)
def get_text_data(rom_data: RomData, get_dictionary: bool, seasons: bool) -> tuple[None | dict[str, str], dict[str, str]]:
result = load_vanilla_text_data(seasons)
if result is not None:
if get_dictionary:
dictionary = load_vanilla_dict_data(seasons)
else:
dictionary = None
return dictionary, result
dictionary = parse_text_dict(rom_data, seasons)
texts = parse_all_texts(rom_data, dictionary, seasons)
save_vanilla_text_data(dictionary, texts, seasons)
return dictionary, texts