Core: change signatures in autoworld from world to multiworld (#1273)
This commit is contained in:
parent
f0e9080108
commit
111c3186bd
4
Main.py
4
Main.py
|
@ -211,8 +211,8 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
||||||
items_to_add = []
|
items_to_add = []
|
||||||
for player in group["players"]:
|
for player in group["players"]:
|
||||||
if group["replacement_items"][player]:
|
if group["replacement_items"][player]:
|
||||||
items_to_add.append(AutoWorld.call_single(world, "create_item", player,
|
items_to_add.append(
|
||||||
group["replacement_items"][player]))
|
AutoWorld.call_single(world, "create_item", player, group["replacement_items"][player]))
|
||||||
else:
|
else:
|
||||||
items_to_add.append(AutoWorld.call_single(world, "create_filler", player))
|
items_to_add.append(AutoWorld.call_single(world, "create_filler", player))
|
||||||
world.random.shuffle(items_to_add)
|
world.random.shuffle(items_to_add)
|
||||||
|
|
|
@ -72,39 +72,39 @@ class AutoLogicRegister(type):
|
||||||
return new_class
|
return new_class
|
||||||
|
|
||||||
|
|
||||||
def call_single(world: "MultiWorld", method_name: str, player: int, *args: Any) -> Any:
|
def call_single(multiworld: "MultiWorld", method_name: str, player: int, *args: Any) -> Any:
|
||||||
method = getattr(world.worlds[player], method_name)
|
method = getattr(multiworld.worlds[player], method_name)
|
||||||
return method(*args)
|
return method(*args)
|
||||||
|
|
||||||
|
|
||||||
def call_all(world: "MultiWorld", method_name: str, *args: Any) -> None:
|
def call_all(multiworld: "MultiWorld", method_name: str, *args: Any) -> None:
|
||||||
world_types: Set[AutoWorldRegister] = set()
|
world_types: Set[AutoWorldRegister] = set()
|
||||||
for player in world.player_ids:
|
for player in multiworld.player_ids:
|
||||||
prev_item_count = len(world.itempool)
|
prev_item_count = len(multiworld.itempool)
|
||||||
world_types.add(world.worlds[player].__class__)
|
world_types.add(multiworld.worlds[player].__class__)
|
||||||
call_single(world, method_name, player, *args)
|
call_single(multiworld, method_name, player, *args)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
new_items = world.itempool[prev_item_count:]
|
new_items = multiworld.itempool[prev_item_count:]
|
||||||
for i, item in enumerate(new_items):
|
for i, item in enumerate(new_items):
|
||||||
for other in new_items[i+1:]:
|
for other in new_items[i+1:]:
|
||||||
assert item is not other, (
|
assert item is not other, (
|
||||||
f"Duplicate item reference of \"{item.name}\" in \"{world.worlds[player].game}\" "
|
f"Duplicate item reference of \"{item.name}\" in \"{multiworld.worlds[player].game}\" "
|
||||||
f"of player \"{world.player_name[player]}\". Please make a copy instead.")
|
f"of player \"{multiworld.player_name[player]}\". Please make a copy instead.")
|
||||||
|
|
||||||
# TODO: investigate: Iterating through a set is not a deterministic order.
|
# TODO: investigate: Iterating through a set is not a deterministic order.
|
||||||
# If any random is used, this could make unreproducible seed.
|
# If any random is used, this could make unreproducible seed.
|
||||||
for world_type in world_types:
|
for world_type in world_types:
|
||||||
stage_callable = getattr(world_type, f"stage_{method_name}", None)
|
stage_callable = getattr(world_type, f"stage_{method_name}", None)
|
||||||
if stage_callable:
|
if stage_callable:
|
||||||
stage_callable(world, *args)
|
stage_callable(multiworld, *args)
|
||||||
|
|
||||||
|
|
||||||
def call_stage(world: "MultiWorld", method_name: str, *args: Any) -> None:
|
def call_stage(multiworld: "MultiWorld", method_name: str, *args: Any) -> None:
|
||||||
world_types = {world.worlds[player].__class__ for player in world.player_ids}
|
world_types = {multiworld.worlds[player].__class__ for player in multiworld.player_ids}
|
||||||
for world_type in world_types:
|
for world_type in world_types:
|
||||||
stage_callable = getattr(world_type, f"stage_{method_name}", None)
|
stage_callable = getattr(world_type, f"stage_{method_name}", None)
|
||||||
if stage_callable:
|
if stage_callable:
|
||||||
stage_callable(world, *args)
|
stage_callable(multiworld, *args)
|
||||||
|
|
||||||
|
|
||||||
class WebWorld:
|
class WebWorld:
|
||||||
|
@ -196,8 +196,8 @@ class World(metaclass=AutoWorldRegister):
|
||||||
zip_path: ClassVar[Optional[pathlib.Path]] = None # If loaded from a .apworld, this is the Path to it.
|
zip_path: ClassVar[Optional[pathlib.Path]] = None # If loaded from a .apworld, this is the Path to it.
|
||||||
__file__: ClassVar[str] # path it was loaded from
|
__file__: ClassVar[str] # path it was loaded from
|
||||||
|
|
||||||
def __init__(self, world: "MultiWorld", player: int):
|
def __init__(self, multiworld: "MultiWorld", player: int):
|
||||||
self.multiworld = world
|
self.multiworld = multiworld
|
||||||
self.player = player
|
self.player = player
|
||||||
|
|
||||||
# overridable methods that get called by Main.py, sorted by execution order
|
# overridable methods that get called by Main.py, sorted by execution order
|
||||||
|
|
Loading…
Reference in New Issue