From 39342ad5d585a874d16ba397e211af58a0257c6b Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 9 Jan 2025 17:00:21 +0100 Subject: [PATCH] review concerns --- BaseClasses.py | 3 ++- Fill.py | 10 +++++----- Main.py | 2 +- worlds/AutoWorld.py | 16 +++++++++++----- worlds/subnautica/__init__.py | 4 ++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index e19ba5f777..aa56b44c9c 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -373,7 +373,8 @@ class MultiWorld(): items_to_add.append(AutoWorld.call_single(self, "create_item", item_player, group["replacement_items"][player])) else: - items_to_add.append(AutoWorld.call_single(self, "create_filler", item_player)) + items_to_add.append(AutoWorld.call_single(self, "create_filler", item_player, + "item_link")) self.random.shuffle(items_to_add) self.itempool.extend(items_to_add[:itemcount - len(self.itempool)]) diff --git a/Fill.py b/Fill.py index 9fb190784f..20962b727a 100644 --- a/Fill.py +++ b/Fill.py @@ -7,7 +7,7 @@ from collections import Counter, deque from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld from Options import Accessibility -from worlds.AutoWorld import call_all +from worlds.AutoWorld import call_all, FillerReason from worlds.generic.Rules import add_item_rule @@ -316,7 +316,7 @@ def remaining_fill(multiworld: MultiWorld, for item in unplaced_items: logging.debug(f"Moved {item} to start_inventory to prevent fill failure.") multiworld.push_precollected(item) - last_batch.append(multiworld.worlds[item.player].create_filler("panic_fill")) + last_batch.append(multiworld.worlds[item.player].create_filler(FillerReason.panic_fill)) remaining_fill(multiworld, locations, unplaced_items, name + " Start Inventory Retry") else: raise FillError(f"No more spots to place {len(unplaced_items)} items. Remaining locations are invalid.\n" @@ -521,7 +521,7 @@ def distribute_items_restrictive(multiworld: MultiWorld, for item in progitempool: logging.debug(f"Moved {item} to start_inventory to prevent fill failure.") multiworld.push_precollected(item) - filleritempool.append(multiworld.worlds[item.player].create_filler("panic_fill")) + filleritempool.append(multiworld.worlds[item.player].create_filler(FillerReason.panic_fill)) logging.warning(f"{len(progitempool)} items moved to start inventory," f" due to failure in Progression fill step.") progitempool[:] = [] @@ -545,7 +545,7 @@ def distribute_items_restrictive(multiworld: MultiWorld, inaccessible_location_rules(multiworld, multiworld.state, defaultlocations) remaining_fill(multiworld, excludedlocations, filleritempool, "Remaining Excluded", - move_unplaceable_to_start_inventory=panic_method=="start_inventory") + move_unplaceable_to_start_inventory=panic_method == "start_inventory") if excludedlocations: raise FillError( @@ -557,7 +557,7 @@ def distribute_items_restrictive(multiworld: MultiWorld, restitempool = filleritempool + usefulitempool remaining_fill(multiworld, defaultlocations, restitempool, - move_unplaceable_to_start_inventory=panic_method=="start_inventory") + move_unplaceable_to_start_inventory=panic_method == "start_inventory") unplaced = restitempool unfilled = defaultlocations diff --git a/Main.py b/Main.py index 087dfef408..8a61a862c6 100644 --- a/Main.py +++ b/Main.py @@ -181,7 +181,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No logger.warning(f"{player_name} tried to remove items from their pool that don't exist: {unfound_items}") needed_items = target_per_player[player] - sum(unfound_items.values()) - new_itempool += [multiworld.worlds[player].create_filler("start_inventory_from_pool") + new_itempool += [multiworld.worlds[player].create_filler(AutoWorld.FillerReason.start_inventory_from_pool) for _ in range(needed_items)] assert len(multiworld.itempool) == len(new_itempool), "Item Pool amounts should not change." diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index bfd5e479c3..eef33ac4c0 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -1,5 +1,6 @@ from __future__ import annotations +import enum import hashlib import logging import pathlib @@ -17,10 +18,15 @@ if TYPE_CHECKING: from BaseClasses import MultiWorld, Item, Location, Tutorial, Region, Entrance from . import GamesPackage from settings import Group - from typing import Literal - reason_type = Optional[Literal["item_link", "panic_fill", "start_inventory_from_pool", "world"]] -else: - reason_type = Optional[str] + + +class FillerReason(enum.StrEnum): + undefined = enum.auto() + item_link = enum.auto() + panic_fill = enum.auto() + start_inventory_from_pool = enum.auto() + world = enum.auto() + perf_logger = logging.getLogger("performance") @@ -531,7 +537,7 @@ class World(metaclass=AutoWorldRegister): return False # following methods should not need to be overridden. - def create_filler(self, reason: reason_type = None) -> "Item": + def create_filler(self, reason: FillerReason = FillerReason.undefined) -> "Item": return self.create_item(self.get_filler_item_name()) # convenience methods diff --git a/worlds/subnautica/__init__.py b/worlds/subnautica/__init__.py index 8e7decb6fc..3270af0e0f 100644 --- a/worlds/subnautica/__init__.py +++ b/worlds/subnautica/__init__.py @@ -5,7 +5,7 @@ import itertools from typing import List, Dict, Any, cast from BaseClasses import Region, Location, Item, Tutorial, ItemClassification -from worlds.AutoWorld import World, WebWorld +from worlds.AutoWorld import World, WebWorld, FillerReason from . import items from . import locations from . import creatures @@ -142,7 +142,7 @@ class SubnauticaWorld(World): # resource bundle filler for _ in range(extras): - item = self.create_filler("world") + item = self.create_filler(FillerReason.world) item = cast(SubnauticaItem, item) pool.append(item)