AutoWorld: Add "stage" methods and implement LttP Dungeon fill as an example.

This commit is contained in:
Fabian Dill
2021-08-09 06:50:11 +02:00
parent 95350a1fa9
commit 01d88c362a
4 changed files with 79 additions and 103 deletions

View File

@@ -5,7 +5,7 @@ from BaseClasses import MultiWorld, Item, CollectionState
class AutoWorldRegister(type):
world_types:Dict[str, World] = {}
world_types: Dict[str, World] = {}
def __new__(cls, name, bases, dct):
# filter out any events
@@ -20,7 +20,6 @@ class AutoWorldRegister(type):
dct["location_names"] = frozenset(dct["location_name_to_id"])
dct["all_names"] = dct["item_names"] | dct["location_names"] | set(dct.get("item_name_groups", {}))
# construct class
new_class = super().__new__(cls, name, bases, dct)
if "game" in dct:
@@ -45,8 +44,14 @@ def call_single(world: MultiWorld, method_name: str, player: int, *args):
def call_all(world: MultiWorld, method_name: str, *args):
world_types = set()
for player in world.player_ids:
world_types.add(world.worlds[player].__class__)
call_single(world, method_name, player, *args)
for world_type in world_types:
stage_callable = getattr(world_type, f"stage_{method_name}", None)
if stage_callable:
stage_callable(world)
class World(metaclass=AutoWorldRegister):
@@ -54,7 +59,7 @@ class World(metaclass=AutoWorldRegister):
A Game should have its own subclass of World in which it defines the required data structures."""
options: dict = {} # link your Options mapping
game: str # name the game
game: str # name the game
topology_present: bool = False # indicate if world type has any meaningful layout/pathing
all_names: Set[str] = frozenset() # gets automatically populated with all item, item group and location names
@@ -91,6 +96,9 @@ class World(metaclass=AutoWorldRegister):
self.player = player
# overridable methods that get called by Main.py, sorted by execution order
# can also be implemented as a classmethod and called "stage_<original_name",
# in that case the MultiWorld object is passed as an argument and it gets called once for the entire multiworld.
# An example of this can be found in alttp as stage_pre_fill
def generate_early(self):
pass
@@ -106,6 +114,10 @@ class World(metaclass=AutoWorldRegister):
def generate_basic(self):
pass
def pre_fill(self):
"""Optional method that is supposed to be used for special fill stages. This is run *after* plando."""
pass
def generate_output(self, output_directory: str):
"""This method gets called from a threadpool, do not use world.random here.
If you need any last-second randomization, use MultiWorld.slot_seeds[slot] instead."""