From 16559e75955e783363d50304809b74b701356f6f Mon Sep 17 00:00:00 2001 From: Ian Robinson Date: Wed, 24 Dec 2025 08:48:05 -0500 Subject: [PATCH] Core: allow abstract world classes (#5468) --- worlds/AutoWorld.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 8bd6ffaf3c..e1435b3a68 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -47,27 +47,31 @@ class AutoWorldRegister(type): def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> AutoWorldRegister: if "web" in dct: assert isinstance(dct["web"], WebWorld), "WebWorld has to be instantiated." - # filter out any events - dct["item_name_to_id"] = {name: id for name, id in dct["item_name_to_id"].items() if id} - dct["location_name_to_id"] = {name: id for name, id in dct["location_name_to_id"].items() if id} - # build reverse lookups - dct["item_id_to_name"] = {code: name for name, code in dct["item_name_to_id"].items()} - dct["location_id_to_name"] = {code: name for name, code in dct["location_name_to_id"].items()} - # build rest - dct["item_names"] = frozenset(dct["item_name_to_id"]) - dct["item_name_groups"] = {group_name: frozenset(group_set) for group_name, group_set - in dct.get("item_name_groups", {}).items()} - dct["item_name_groups"]["Everything"] = dct["item_names"] - - dct["location_names"] = frozenset(dct["location_name_to_id"]) - dct["location_name_groups"] = {group_name: frozenset(group_set) for group_name, group_set - in dct.get("location_name_groups", {}).items()} - dct["location_name_groups"]["Everywhere"] = dct["location_names"] - dct["all_item_and_group_names"] = frozenset(dct["item_names"] | set(dct.get("item_name_groups", {}))) - - # move away from get_required_client_version function if "game" in dct: + assert "item_name_to_id" in dct, f"{name}: item_name_to_id is required" + assert "location_name_to_id" in dct, f"{name}: location_name_to_id is required" + + # filter out any events + dct["item_name_to_id"] = {name: id for name, id in dct["item_name_to_id"].items() if id} + dct["location_name_to_id"] = {name: id for name, id in dct["location_name_to_id"].items() if id} + # build reverse lookups + dct["item_id_to_name"] = {code: name for name, code in dct["item_name_to_id"].items()} + dct["location_id_to_name"] = {code: name for name, code in dct["location_name_to_id"].items()} + + # build rest + dct["item_names"] = frozenset(dct["item_name_to_id"]) + dct["item_name_groups"] = {group_name: frozenset(group_set) for group_name, group_set + in dct.get("item_name_groups", {}).items()} + dct["item_name_groups"]["Everything"] = dct["item_names"] + + dct["location_names"] = frozenset(dct["location_name_to_id"]) + dct["location_name_groups"] = {group_name: frozenset(group_set) for group_name, group_set + in dct.get("location_name_groups", {}).items()} + dct["location_name_groups"]["Everywhere"] = dct["location_names"] + dct["all_item_and_group_names"] = frozenset(dct["item_names"] | set(dct.get("item_name_groups", {}))) + + # move away from get_required_client_version function assert "get_required_client_version" not in dct, f"{name}: required_client_version is an attribute now" # set minimum required_client_version from bases if "required_client_version" in dct and bases: