Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some cleaning from type checking and linting #1

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions worlds/kdl3/Locations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typing
from BaseClasses import Location
from BaseClasses import Location, Region
from .Names import LocationName

if typing.TYPE_CHECKING:
Expand All @@ -10,7 +10,7 @@ class KDL3Location(Location):
game: str = "Kirby's Dream Land 3"
room: typing.Optional["Room"] = None

def __init__(self, player: int, name: str, address: typing.Optional[int], parent):
def __init__(self, player: int, name: str, address: typing.Optional[int], parent: typing.Union[Region, None]):
super().__init__(player, name, address, parent)
self.event = not address

Expand Down
2 changes: 1 addition & 1 deletion worlds/kdl3/Names/EnemyAbilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@
'Haboki': 'Clean Ability',
}

enemy_restrictive: List[Tuple[Set, Set]] = [
enemy_restrictive: List[Tuple[Set[str], Set[str]]] = [
# abilities, enemies, set_all (False to set any)
({"Burning Ability", "Stone Ability"}, {"Rocky", "Sparky", "Babut", "Squishy", }), # Ribbon Field 5 - 7
# Sand Canyon 6
Expand Down
12 changes: 6 additions & 6 deletions worlds/kdl3/Names/LocationName.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@

# Boss Names
boss_names = {
"Whispy Woods": 0x770200,
"Acro": 0x770201,
"Pon & Con": 0x770202,
"Ado": 0x770203,
"King Dedede": 0x770204
}
"Whispy Woods": 0x770200,
"Acro": 0x770201,
"Pon & Con": 0x770202,
"Ado": 0x770203,
"King Dedede": 0x770204
}

# Goal Mapping
goals = {
Expand Down
Empty file added worlds/kdl3/Names/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions worlds/kdl3/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Goal(Choice):
default = 0

@classmethod
def get_option_name(cls, value) -> str:
def get_option_name(cls, value: int) -> str:
if cls.auto_display_name and value == 2:
return cls.name_lookup[value].upper()
else:
Expand Down Expand Up @@ -81,9 +81,9 @@ class BossShuffle(PlandoBosses):
Singularity: All (non-Zero) bosses will be replaced with a single boss
Supports plando placement.
"""
bosses = LocationName.boss_names.keys()
bosses = frozenset(LocationName.boss_names.keys())

locations = LocationName.level_names.keys()
locations = frozenset(LocationName.level_names.keys())

duplicate_bosses = True

Expand Down Expand Up @@ -355,7 +355,7 @@ class VirtualConsoleChanges(Choice):
default = 1


kdl3_options: typing.Dict[str, type(Option)] = {
kdl3_options: typing.Dict[str, typing.Type[Option[typing.Any]]] = {
"death_link": DeathLink,
"game_language": GameLanguage,
"goal": Goal,
Expand Down
2 changes: 1 addition & 1 deletion worlds/kdl3/Rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def read_bytes(self, offset: int, length: int):
def write_byte(self, offset: int, value: int):
self.file[offset] = value

def write_bytes(self, offset: int, values):
def write_bytes(self, offset: int, values: bytes) -> None:
self.file[offset:offset + len(values)] = values

def write_to_file(self, file: str):
Expand Down
2 changes: 1 addition & 1 deletion worlds/kdl3/Room.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import struct
import typing

from BaseClasses import Region, ItemClassification

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -53,6 +52,7 @@ def patch(self, rom: "RomData"):
load_len = len(self.entity_load)
for consumable in self.consumables:
location = next(x for x in self.locations if x.name == consumable["name"])
assert location.item
is_progression = location.item.classification & ItemClassification.progression
if load_len == 8:
# edge case, there is exactly 1 room with 8 entities and only 1 consumable among them
Expand Down
39 changes: 22 additions & 17 deletions worlds/kdl3/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def can_reach_cutter(state: "CollectionState", player: int) -> bool:
return state.has("Cutter", player) and state.has("Cutter Ability", player)


ability_map = {
ability_map: dict[str, typing.Callable[[CollectionState, int], bool]] = {
"No Ability": lambda state, player: True,
"Burning Ability": can_reach_burning,
"Stone Ability": can_reach_stone,
Expand Down Expand Up @@ -130,8 +130,10 @@ def set_rules(world: "KDL3World") -> None:
add_rule(world.multiworld.get_location(LocationName.ripple_field_toad, world.player),
lambda state: can_reach_needle(state, world.player))
add_rule(world.multiworld.get_location(LocationName.ripple_field_mama_pitch, world.player),
lambda state: can_reach_pitch(state, world.player) and can_reach_kine(state, world.player)
and can_reach_burning(state, world.player) and can_reach_stone(state, world.player))
lambda state: (can_reach_pitch(state, world.player) and
can_reach_kine(state, world.player) and
can_reach_burning(state, world.player) and
can_reach_stone(state, world.player)))

# Level 3
add_rule(world.multiworld.get_location(LocationName.sand_canyon_5, world.player),
Expand Down Expand Up @@ -162,8 +164,9 @@ def set_rules(world: "KDL3World") -> None:
add_rule(world.multiworld.get_location(LocationName.iceberg_samus, world.player),
lambda state: can_reach_ice(state, world.player))
add_rule(world.multiworld.get_location(LocationName.iceberg_name, world.player),
lambda state: can_reach_coo(state, world.player) and can_reach_burning(state, world.player)
and can_reach_chuchu(state, world.player))
lambda state: (can_reach_coo(state, world.player) and
can_reach_burning(state, world.player) and
can_reach_chuchu(state, world.player)))
# ChuChu is guaranteed here, but we use this for consistency
add_rule(world.multiworld.get_location(LocationName.iceberg_shiro, world.player),
lambda state: can_reach_nago(state, world.player))
Expand Down Expand Up @@ -191,11 +194,13 @@ def set_rules(world: "KDL3World") -> None:
add_rule(world.multiworld.get_location(LocationName.ripple_field_5_m1, world.player),
lambda state: can_reach_kine(state, world.player))
add_rule(world.multiworld.get_location(LocationName.ripple_field_5_u1, world.player),
lambda state: can_reach_kine(state, world.player)
and can_reach_burning(state, world.player) and can_reach_stone(state, world.player))
lambda state: (can_reach_kine(state, world.player) and
can_reach_burning(state, world.player) and
can_reach_stone(state, world.player)))
add_rule(world.multiworld.get_location(LocationName.ripple_field_5_m2, world.player),
lambda state: can_reach_kine(state, world.player)
and can_reach_burning(state, world.player) and can_reach_stone(state, world.player))
lambda state: (can_reach_kine(state, world.player) and
can_reach_burning(state, world.player) and
can_reach_stone(state, world.player)))
add_rule(world.multiworld.get_location(LocationName.sand_canyon_4_u1, world.player),
lambda state: can_reach_clean(state, world.player))
add_rule(world.multiworld.get_location(LocationName.sand_canyon_4_m2, world.player),
Expand Down Expand Up @@ -247,15 +252,15 @@ def set_rules(world: "KDL3World") -> None:
LocationName.iceberg_dedede],
range(1, 6)):
set_rule(world.multiworld.get_location(boss_flag, world.player),
lambda state, i=i: state.has("Heart Star", world.player, world.boss_requirements[i - 1])
and can_reach_level(state, world.player, i + 1,
world.multiworld.open_world[world.player],
world.multiworld.ow_boss_requirement[world.player]))
lambda state, i=i: (state.has("Heart Star", world.player, world.boss_requirements[i - 1]) and
can_reach_level(state, world.player, i + 1,
world.multiworld.open_world[world.player],
world.multiworld.ow_boss_requirement[world.player])))
set_rule(world.multiworld.get_location(purification, world.player),
lambda state, i=i: state.has("Heart Star", world.player, world.boss_requirements[i - 1])
and can_reach_level(state, world.player, i + 1,
world.multiworld.open_world[world.player],
world.multiworld.ow_boss_requirement[world.player]))
lambda state, i=i: (state.has("Heart Star", world.player, world.boss_requirements[i - 1]) and
can_reach_level(state, world.player, i + 1,
world.multiworld.open_world[world.player],
world.multiworld.ow_boss_requirement[world.player])))

if world.multiworld.strict_bosses[world.player]:
for level in range(2, 6):
Expand Down