mypy and softlock fix

This commit is contained in:
Silvris
2024-04-08 18:39:34 -05:00
parent 2ccefe733d
commit 6480cfa68f
4 changed files with 35 additions and 22 deletions

View File

@@ -1,5 +1,9 @@
import struct
from .Options import KirbyFlavorPreset, GooeyFlavorPreset
from typing import TYPE_CHECKING, Optional, Dict, List
if TYPE_CHECKING:
from . import KDL3World
kirby_flavor_presets = {
1: {
@@ -398,21 +402,21 @@ gooey_target_palettes = {
}
def get_kirby_palette(world):
def get_kirby_palette(world: "KDL3World") -> Optional[Dict[str, str]]:
palette = world.options.kirby_flavor_preset.value
if palette == KirbyFlavorPreset.option_custom:
return world.options.kirby_flavor.value
return kirby_flavor_presets.get(palette, None)
def get_gooey_palette(world):
def get_gooey_palette(world: "KDL3World") -> Optional[Dict[str, str]]:
palette = world.options.gooey_flavor_preset.value
if palette == GooeyFlavorPreset.option_custom:
return world.options.gooey_flavor.value
return gooey_flavor_presets.get(palette, None)
def rgb888_to_bgr555(red, green, blue) -> bytes:
def rgb888_to_bgr555(red: int, green: int, blue: int) -> bytes:
red = red >> 3
green = green >> 3
blue = blue >> 3
@@ -420,7 +424,7 @@ def rgb888_to_bgr555(red, green, blue) -> bytes:
return struct.pack("H", outcol)
def get_palette_bytes(palette, target, offset, factor) -> bytes:
def get_palette_bytes(palette: Dict[str, str], target: List[str], offset: int, factor: float) -> bytes:
output_data = bytearray()
for color in target:
hexcol = palette[color]

View File

@@ -1,8 +1,9 @@
# Small subfile to handle gifting info such as desired traits and giftbox management
import typing
from CommonClient import CommonContext
async def update_object(ctx, key: str, value: typing.Dict):
async def update_object(ctx: CommonContext, key: str, value: typing.Dict[str, typing.Any]) -> None:
await ctx.send_msgs([
{
"cmd": "Set",
@@ -16,7 +17,7 @@ async def update_object(ctx, key: str, value: typing.Dict):
])
async def pop_object(ctx, key: str, value: str):
async def pop_object(ctx: CommonContext, key: str, value: str) -> None:
await ctx.send_msgs([
{
"cmd": "Set",
@@ -30,14 +31,14 @@ async def pop_object(ctx, key: str, value: str):
])
async def initialize_giftboxes(ctx, giftbox_key: str, motherbox_key: str, is_open: bool):
async def initialize_giftboxes(ctx: CommonContext, giftbox_key: str, motherbox_key: str, is_open: bool) -> None:
ctx.set_notify(motherbox_key, giftbox_key)
await update_object(ctx, f"Giftboxes;{ctx.team}", {f"{ctx.slot}":
{
"IsOpen": is_open,
**kdl3_gifting_options
}})
ctx.gifting = is_open
setattr(ctx, "gifting", is_open)
kdl3_gifting_options = {

View File

@@ -110,7 +110,11 @@ def generate_rooms(world: "KDL3World", level_regions: typing.Dict[int, Region]):
else:
world.multiworld.get_location(world.location_id_to_name[world.player_levels[level][stage - 1]],
world.player).parent_region.add_exits([first_rooms[proper_stage].name])
level_regions[level].add_exits([first_rooms[0x770200 + level - 1].name])
if world.options.open_world:
level_regions[level].add_exits([first_rooms[0x770200 + level - 1].name])
else:
world.multiworld.get_location(world.location_id_to_name[world.player_levels[level][5]],
world.player).parent_region.add_exits([first_rooms[0x770200 + level - 1].name])
def generate_valid_levels(world: "KDL3World", enforce_world: bool, enforce_pattern: bool) -> dict:

View File

@@ -1,10 +1,10 @@
import struct
import typing
from BaseClasses import Region, ItemClassification
from typing import Optional, Dict, TYPE_CHECKING, List, Union
from BaseClasses import Region, ItemClassification, MultiWorld
from worlds.Files import APTokenTypes
from .ClientAddrs import consumable_addrs, star_addrs
if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from .Rom import KDL3ProcedurePatch
animal_map = {
@@ -23,14 +23,18 @@ class KDL3Room(Region):
stage: int = 0
room: int = 0
music: int = 0
default_exits: typing.List[typing.Dict[str, typing.Union[int, typing.List[str]]]]
animal_pointers: typing.List[int]
enemies: typing.List[str]
entity_load: typing.List[typing.List[int]]
consumables: typing.List[typing.Dict[str, typing.Union[int, str]]]
default_exits: List[Dict[str, Union[int, List[str]]]]
animal_pointers: List[int]
enemies: List[str]
entity_load: List[List[int]]
consumables: List[Dict[str, Union[int, str]]]
def __init__(self, name, player, multiworld, hint, level, stage, room, pointer, music, default_exits,
animal_pointers, enemies, entity_load, consumables, consumable_pointer):
def __init__(self, name: str, player: int, multiworld: MultiWorld, hint: Optional[str], level: int,
stage: int, room: int, pointer: int, music: int,
default_exits: List[Dict[str, Union[int, List[str]]]],
animal_pointers: List[int], enemies: List[str],
entity_load: List[List[int]],
consumables: List[Dict[str, Union[int, str]]], consumable_pointer: int) -> None:
super().__init__(name, player, multiworld, hint)
self.level = level
self.stage = stage
@@ -44,16 +48,16 @@ class KDL3Room(Region):
self.consumables = consumables
self.consumable_pointer = consumable_pointer
def patch(self, patch: "KDL3ProcedurePatch", consumables: bool, local_items: bool):
def patch(self, patch: "KDL3ProcedurePatch", consumables: bool, local_items: bool) -> None:
patch.write_token(APTokenTypes.WRITE, self.pointer + 2, self.music.to_bytes(1, "little"))
animals = [x.item.name for x in self.locations if "Animal" in x.name]
animals = [x.item.name for x in self.locations if "Animal" in x.name and x.item]
if len(animals) > 0:
for current_animal, address in zip(animals, self.animal_pointers):
patch.write_token(APTokenTypes.WRITE, self.pointer + address + 7,
animal_map[current_animal].to_bytes(1, "little"))
if local_items:
for location in self.locations:
if not location.address or location.item.player != self.player:
if not location.address or not location.item or location.item.player != self.player:
continue
item = location.item.code
item_idx = item & 0x00000F