Skip to content

Commit

Permalink
use an update_itempool method for gathering items
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysintreble committed Oct 29, 2023
1 parent 1f5a215 commit 4087403
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
11 changes: 11 additions & 0 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def get_all_state(self, use_cache: bool = True) -> CollectionState:
return cached.copy()

ret = CollectionState(self)
self.update_itempool()

for item in self.itempool:
self.worlds[item.player].collect(ret, item)
Expand Down Expand Up @@ -415,6 +416,16 @@ def find_items_in_locations(self, items: Set[str], player: int, resolve_group_lo
def create_item(self, item_name: str, player: int) -> Item:
return self.worlds[player].create_item(item_name)

def update_itempool(self) -> None:
updated_itempools = {player for player, world in self.worlds.items()
if isinstance(getattr(world, "itempool", None), Counter) and world.itempool}
items_to_add = []
for player in updated_itempools:
items_to_add += [self.create_item(item, player)
for item, count in self.worlds[player].itempool.items() for _ in range(count)]
self.worlds[player].itempool = Counter()
self.itempool += items_to_add

def push_precollected(self, item: Item):
self.precollected_items[item.player].append(item)
self.state.collect(item, True)
Expand Down
2 changes: 1 addition & 1 deletion test/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from BaseClasses import MultiWorld, CollectionState
from worlds.AutoWorld import call_all, World

gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill", "create_filler_items")
gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill")


def setup_solo_multiworld(world_type: Type[World], steps: Tuple[str, ...] = gen_steps) -> MultiWorld:
Expand Down
16 changes: 4 additions & 12 deletions worlds/AutoWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,9 @@ def call_all(multiworld: "MultiWorld", method_name: str, *args: Any) -> None:
# TODO remove when all worlds on new API
if not isinstance(getattr(sub_world, "itempool", None), Counter):
continue
count = len(multiworld.get_unfilled_locations(player)) - sum(sub_world.itempool.values())
sub_world.itempool = Counter()
call_single(multiworld, method_name, player, count)
multiworld.itempool += [sub_world.create_item(item_name)
for item_name, count in sub_world.itempool.items() for _ in range(count)]
call_single(multiworld, method_name, player, args[0][player])
continue
call_single(multiworld, method_name, player, *args)
# this is here for unit tests
if method_name == "create_items":
sub_world = multiworld.worlds[player]
# items need to be created so that state can collect them
if isinstance(getattr(sub_world, "itempool", None), Counter):
multiworld.itempool += [sub_world.create_item(item_name)
for item_name, count in sub_world.itempool.items() for _ in range(count)]
if __debug__:
new_items = multiworld.itempool[prev_item_count:]
for i, item in enumerate(new_items):
Expand All @@ -158,6 +147,9 @@ def call_all(multiworld: "MultiWorld", method_name: str, *args: Any) -> None:
if stage_callable:
stage_callable(multiworld, *args)

if "item" in method_name:
multiworld.update_itempool()


def call_stage(multiworld: "MultiWorld", method_name: str, *args: Any) -> None:
world_types = {multiworld.worlds[player].__class__ for player in multiworld.player_ids}
Expand Down

0 comments on commit 4087403

Please sign in to comment.