From 0548205840841e657c81083b0c4e8e1c5467b4a6 Mon Sep 17 00:00:00 2001 From: Capypara Date: Sun, 28 Jul 2024 13:07:16 +0200 Subject: [PATCH] Typing and linting fixes for #527 --- skytemple_files/common/sprite_util.py | 10 ++++++++-- skytemple_files/patch/handler/expand_poke_list.py | 3 --- skytemple_files/patch/handler/sprite_size.py | 15 ++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/skytemple_files/common/sprite_util.py b/skytemple_files/common/sprite_util.py index 2d0b2a57..4a9a4a80 100644 --- a/skytemple_files/common/sprite_util.py +++ b/skytemple_files/common/sprite_util.py @@ -20,6 +20,8 @@ import math +from range_typed_integers import u8 + from skytemple_files.common.types.file_types import FileType from skytemple_files.container.bin_pack.model import BinPack from skytemple_files.data.md.protocol import MdEntryProtocol @@ -37,7 +39,7 @@ def check_and_correct_monster_sprite_size( monster_bin: BinPack, sprite_size_table: list[MonsterSpriteDataTableEntry], is_expand_poke_list_patch_applied: bool = False, -) -> bool: +) -> list[tuple[str, u8, u8]]: """ Check that the data in the Pokémon sprite-size metadata table matches the currently selected sprite of the Pokémon. @@ -51,7 +53,11 @@ def check_and_correct_monster_sprite_size( - sprite_size_table: Sprite size metadata table - is_expand_poke_list_patch_applied: Whether ExpandPokeList is applied. - Returns True if a change was performed. + Returns a list of changes if a change was performed. Each element contains a tuple: + - Change description (localized) + - Old value + - New value + If changes were performed the data in the following input parameters may be modified and should be written back to ROM: diff --git a/skytemple_files/patch/handler/expand_poke_list.py b/skytemple_files/patch/handler/expand_poke_list.py index f0a4c970..dc24b106 100644 --- a/skytemple_files/patch/handler/expand_poke_list.py +++ b/skytemple_files/patch/handler/expand_poke_list.py @@ -168,9 +168,6 @@ def apply(self, apply: Callable[[], None], rom: NintendoDSRom, config: Pmd2Data) table_mf = JP_TABLE_MF table_sp = JP_TABLE_SP if not self.is_applied(rom, config): - bincfg = config.bin_sections.arm9 - binary = bytearray(get_binary_from_rom(rom, bincfg)) - # Apply the patch for filename in get_files_from_rom_with_extension(rom, "str"): bin_before = rom.getFileByName(filename) diff --git a/skytemple_files/patch/handler/sprite_size.py b/skytemple_files/patch/handler/sprite_size.py index 61b785df..e649ed3b 100644 --- a/skytemple_files/patch/handler/sprite_size.py +++ b/skytemple_files/patch/handler/sprite_size.py @@ -28,11 +28,10 @@ GAME_VERSION_EOS, Pmd2Data, ) -from skytemple_files.common.types.file_types import FileType from skytemple_files.common.util import get_binary_from_rom, read_u32 from skytemple_files.data.md.handler import MdHandler from skytemple_files.patch.category import PatchCategory -from skytemple_files.patch.handler.abstract import AbstractPatchHandler, DependantPatch +from skytemple_files.patch.handler.abstract import AbstractPatchHandler PATCH_CHECK_ADDR_APPLIED_US = 0x527E4 PATCH_CHECK_ADDR_APPLIED_EU = 0x52B1C @@ -47,9 +46,7 @@ def name(self) -> str: @property def description(self) -> str: - return _( - """Changes Sprite Size and Sprite File Size values to be in each Pokémon's data.""" - ) + return _("""Changes Sprite Size and Sprite File Size values to be in each Pokémon's data.""") @property def author(self) -> str: @@ -62,7 +59,7 @@ def version(self) -> str: @property def category(self) -> PatchCategory: return PatchCategory.IMPROVEMENT_TWEAK - + def is_applied(self, rom: NintendoDSRom, config: Pmd2Data) -> bool: if config.game_version == GAME_VERSION_EOS: if config.game_region == GAME_REGION_US: @@ -77,7 +74,7 @@ def apply(self, apply: Callable[[], None], rom: NintendoDSRom, config: Pmd2Data) if not self.is_applied(rom, config): bincfg = config.bin_sections.arm9 binary = bytearray(get_binary_from_rom(rom, bincfg)) - + md_bin = rom.getFileByName("BALANCE/monster.md") md_model = MdHandler.deserialize(md_bin) block2 = bincfg.data.MONSTER_SPRITE_DATA @@ -86,8 +83,8 @@ def apply(self, apply: Callable[[], None], rom: NintendoDSRom, config: Pmd2Data) + binary[block2.address : block2.address + block2.length] ) for i, e in enumerate(md_model.entries): - e.unk17 = data[i*2] - e.unk18 = data[i*2 + 1] + e.unk17 = data[i * 2] + e.unk18 = data[i * 2 + 1] rom.setFileByName("BALANCE/monster.md", MdHandler.serialize(md_model)) try: apply()