From 181cc470795fcd5a3460333bfd3c397467bd7c7d Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Thu, 4 Aug 2022 14:10:58 +0200 Subject: [PATCH] Core: cleanup BaseClasses.Location This is just cleanup and has virtually no performance impact. --- BaseClasses.py | 19 +++++++++---------- worlds/alttp/Shops.py | 4 ++-- worlds/alttp/SubClasses.py | 13 +++++++++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index b550569e48..02a194eef5 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -1064,26 +1064,25 @@ class LocationProgressType(IntEnum): class Location: - # If given as integer, then this is the shop's inventory index - shop_slot: Optional[int] = None - shop_slot_disabled: bool = False + game: str = "Generic" + player: int + name: str + address: Optional[int] + parent_region: Optional[Region] event: bool = False locked: bool = False - game: str = "Generic" show_in_spoiler: bool = True - crystal: bool = False progress_type: LocationProgressType = LocationProgressType.DEFAULT always_allow = staticmethod(lambda item, state: False) access_rule = staticmethod(lambda state: True) item_rule = staticmethod(lambda item: True) item: Optional[Item] = None - parent_region: Optional[Region] - def __init__(self, player: int, name: str = '', address: int = None, parent=None): - self.name: str = name - self.address: Optional[int] = address + def __init__(self, player: int, name: str = '', address: Optional[int] = None, parent: Optional[Region] = None): + self.player = player + self.name = name + self.address = address self.parent_region = parent - self.player: int = player def can_fill(self, state: CollectionState, item: Item, check_access=True) -> bool: return self.always_allow(state, item) or (self.item_rule(item) and (not check_access or self.can_reach(state))) diff --git a/worlds/alttp/Shops.py b/worlds/alttp/Shops.py index 9a77e7d11a..f6233286f0 100644 --- a/worlds/alttp/Shops.py +++ b/worlds/alttp/Shops.py @@ -207,10 +207,10 @@ def ShopSlotFill(world): shops_per_sphere.append(current_shops_slots) candidates_per_sphere.append(current_candidates) for location in sphere: - if location.shop_slot is not None: + if isinstance(location, ALttPLocation) and location.shop_slot is not None: if not location.shop_slot_disabled: current_shops_slots.append(location) - elif not location.locked and not location.item.name in blacklist_words: + elif not location.locked and location.item.name not in blacklist_words: current_candidates.append(location) if cumu_weights: x = cumu_weights[-1] diff --git a/worlds/alttp/SubClasses.py b/worlds/alttp/SubClasses.py index b933c0740d..f54ab16e92 100644 --- a/worlds/alttp/SubClasses.py +++ b/worlds/alttp/SubClasses.py @@ -6,14 +6,19 @@ from BaseClasses import Location, Item, ItemClassification class ALttPLocation(Location): game: str = "A Link to the Past" + crystal: bool + player_address: Optional[int] + _hint_text: Optional[str] + shop_slot: Optional[int] = None + """If given as integer, shop_slot is the shop's inventory index.""" + shop_slot_disabled: bool = False - def __init__(self, player: int, name: str = '', address=None, crystal: bool = False, - hint_text: Optional[str] = None, parent=None, - player_address=None): + def __init__(self, player: int, name: str, address: Optional[int] = None, crystal: bool = False, + hint_text: Optional[str] = None, parent=None, player_address: Optional[int] = None): super(ALttPLocation, self).__init__(player, name, address, parent) self.crystal = crystal self.player_address = player_address - self._hint_text: str = hint_text + self._hint_text = hint_text class ALttPItem(Item):