diff --git a/Messages.py b/Messages.py index c1035bd0c..3afd0c22e 100644 --- a/Messages.py +++ b/Messages.py @@ -226,7 +226,8 @@ def normalize_jp_controller_tokens(text: str) -> str: for code, token in SCJP.items(): if code < 0x10000: REVERSE_MAP_JP[code] = token - json.dump([CHARACTER_MAP_JP, REVERSE_MAP_JP], open(data_path('generated/jp_char_map.otrx'), mode="w")) + with open(data_path('generated/jp_char_map.otrx'), mode="w", encoding="utf-8") as stream: + json.dump([CHARACTER_MAP_JP, REVERSE_MAP_JP], stream) for code, token in SCJP.items(): if code < len(REVERSE_MAP_JP): diff --git a/Patches.py b/Patches.py index 00d0b3bf7..ab1be1af6 100644 --- a/Patches.py +++ b/Patches.py @@ -59,9 +59,14 @@ def patch_rom(spoiler: Spoiler, world: World, rom: Rom) -> Rom: lang = world.language # Binary patches of certain assets. + with open(data_path("bin_patch.json"), mode="r", encoding="utf-8") as stream: + bin_patch_data = json.load(stream) + bin_patches = [ - (os.path.join(lang.path, x), int(y[0], base=16)) for x, y in json.load(open(data_path("bin_patch.json"))).items() if x in lang.data.keys() - ] + (os.path.join(lang.path, x), int(y[0], base=16)) + for x, y in bin_patch_data.items() + if x in lang.data.keys() + ] for (bin_path, write_address) in bin_patches: with open(bin_path, 'rb') as stream: diff --git a/Unittest.py b/Unittest.py index 11e187365..dc5ae7680 100644 --- a/Unittest.py +++ b/Unittest.py @@ -1081,13 +1081,19 @@ def extract_first_second_level_keys(data: dict) -> list: class TestLanguageFile(unittest.TestCase): def test_langfiles(self): base_keys = extract_first_second_level_keys(data.lang.property_build.lang_info) - bin_patch = list(json.load(open(data_path("bin_patch.json"), encoding='utf-8')).keys()) + ["blue_fire_arrow_item_name_jap.ia4", "blue_fire_arrow_item_name_eng.ia4"] + with open(data_path("bin_patch.json"), mode="r", encoding="utf-8") as stream: + bin_patch = list(json.load(stream).keys()) + [ + "blue_fire_arrow_item_name_jap.ia4", + "blue_fire_arrow_item_name_eng.ia4", + ] for lang in os.listdir(lang_path()): if os.path.isdir(os.path.join(lang_path(), lang)) and lang != "__pycache__": lang_files = os.listdir(os.path.join(lang_path(), lang)) self.assertIn("property.json", lang_files, msg = "\n{}: property.json is not included".format(lang)) lang_files.remove("property.json") - property_keys = extract_first_second_level_keys(json.load(open(os.path.join(lang_path(), lang, "property.json"), encoding='utf-8'))) + property_path = os.path.join(lang_path(), lang, "property.json") + with open(property_path, mode="r", encoding="utf-8") as stream: + property_keys = extract_first_second_level_keys(json.load(stream)) only_in_base = list(sorted(set(base_keys) - set(property_keys))) only_in_lang = list(sorted(set(property_keys) - set(base_keys))) diff_keys = []