From 21f7c6c0adcdf85d81bba72fe967fa72cb92bb4d Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 5 Aug 2022 17:09:21 +0200 Subject: [PATCH] Core: optimize away Item.world (#840) * Core: optimize away Item.world * Update test/general/TestFill.py * Test: undo unnecessary changes * lttp: remove two more Item.world writes Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> --- BaseClasses.py | 18 ++++++++---------- Main.py | 3 --- test/general/TestFill.py | 3 +-- worlds/alttp/Dungeons.py | 1 - worlds/alttp/Rules.py | 1 - worlds/alttp/Shops.py | 1 - 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 68166172..66e96824 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -384,7 +384,6 @@ class MultiWorld(): return self.worlds[player].create_item(item_name) def push_precollected(self, item: Item): - item.world = self self.precollected_items[item.player].append(item) self.state.collect(item, True) @@ -392,7 +391,6 @@ class MultiWorld(): assert location.can_fill(self.state, item, False), f"Cannot place {item} into {location}." location.item = item item.location = location - item.world = self # try to not have this here anymore and create it with item? if collect: self.state.collect(item, location.event, location) @@ -1102,7 +1100,6 @@ class Location: self.item = item item.location = self self.event = item.advancement - self.item.world = self.parent_region.world self.locked = True def __repr__(self): @@ -1148,7 +1145,6 @@ class ItemClassification(IntFlag): class Item: location: Optional[Location] = None - world: Optional[MultiWorld] = None code: Optional[int] = None # an item with ID None is called an Event, and does not get written to multidata name: str game: str = "Generic" @@ -1175,11 +1171,11 @@ class Item: self.code = code @property - def hint_text(self): + def hint_text(self) -> str: return getattr(self, "_hint_text", self.name.replace("_", " ").replace("-", " ")) @property - def pedestal_hint_text(self): + def pedestal_hint_text(self) -> str: return getattr(self, "_pedestal_hint_text", self.name.replace("_", " ").replace("-", " ")) @property @@ -1205,7 +1201,7 @@ class Item: def __eq__(self, other): return self.name == other.name and self.player == other.player - def __lt__(self, other: Item): + def __lt__(self, other: Item) -> bool: if other.player != self.player: return other.player < self.player return self.name < other.name @@ -1213,11 +1209,13 @@ class Item: def __hash__(self): return hash((self.name, self.player)) - def __repr__(self): + def __repr__(self) -> str: return self.__str__() - def __str__(self): - return self.world.get_name_string_for_object(self) if self.world else f'{self.name} (Player {self.player})' + def __str__(self) -> str: + if self.location: + return self.location.parent_region.world.get_name_string_for_object(self) + return f"{self.name} (Player {self.player})" class Spoiler(): diff --git a/Main.py b/Main.py index 3912e65c..3b094326 100644 --- a/Main.py +++ b/Main.py @@ -217,9 +217,6 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No logger.info("Running Item Plando") - for item in world.itempool: - item.world = world - distribute_planned(world) logger.info('Running Pre Main Fill.') diff --git a/test/general/TestFill.py b/test/general/TestFill.py index 5cec8952..189aafaf 100644 --- a/test/general/TestFill.py +++ b/test/general/TestFill.py @@ -49,8 +49,7 @@ class PlayerDefinition(object): region_name = "player" + str(self.id) + region_tag region = Region("player" + str(self.id) + region_tag, RegionType.Generic, "Region Hint", self.id, self.world) - self.locations += generate_locations(size, - self.id, None, region, region_tag) + self.locations += generate_locations(size, self.id, None, region, region_tag) entrance = Entrance(self.id, region_name + "_entrance", parent) parent.exits.append(entrance) diff --git a/worlds/alttp/Dungeons.py b/worlds/alttp/Dungeons.py index 861dce9a..8850786b 100644 --- a/worlds/alttp/Dungeons.py +++ b/worlds/alttp/Dungeons.py @@ -15,7 +15,6 @@ def create_dungeons(world, player): dungeon_items, player) for item in dungeon.all_items: item.dungeon = dungeon - item.world = world dungeon.boss = BossFactory(default_boss, player) if default_boss else None for region in dungeon.regions: world.get_region(region, player).dungeon = dungeon diff --git a/worlds/alttp/Rules.py b/worlds/alttp/Rules.py index 7e16d6e5..36e16cf5 100644 --- a/worlds/alttp/Rules.py +++ b/worlds/alttp/Rules.py @@ -935,7 +935,6 @@ def set_trock_key_rules(world, player): else: # A key is required in the Big Key Chest to prevent a possible softlock. Place an extra key to ensure 100% locations still works item = ItemFactory('Small Key (Turtle Rock)', player) - item.world = world location = world.get_location('Turtle Rock - Big Key Chest', player) location.place_locked_item(item) location.event = True diff --git a/worlds/alttp/Shops.py b/worlds/alttp/Shops.py index 5abbdd07..9a77e7d1 100644 --- a/worlds/alttp/Shops.py +++ b/worlds/alttp/Shops.py @@ -335,7 +335,6 @@ def create_shops(world, player: int): else: loc.item = ItemFactory(GetBeemizerItem(world, player, 'Nothing'), player) loc.shop_slot_disabled = True - loc.item.world = world shop.region.locations.append(loc) world.clear_location_cache()