From 6d4ce0406782bb018ebbbfb763735ead6149f5b9 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 26 Jan 2024 23:51:11 +0100 Subject: [PATCH] Core/Subnautica: demonstrate a way to on-demand specify WebWorld --- worlds/AutoWorld.py | 8 +++++++- worlds/subnautica/__init__.py | 32 +++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index fdc50acc55..86f3bb9db7 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -39,7 +39,8 @@ 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." + assert isinstance(dct["web"], WebWorld) or isinstance(dct["web"], staticproperty), \ + "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} @@ -484,6 +485,11 @@ class LogicMixin(metaclass=AutoLogicRegister): pass +class staticproperty(staticmethod): + def __get__(self, *args): + return self.__func__() + + def data_package_checksum(data: "GamesPackage") -> str: """Calculates the data package checksum for a game from a dict""" assert "checksum" not in data, "Checksum already in data" diff --git a/worlds/subnautica/__init__.py b/worlds/subnautica/__init__.py index de4f4e33dc..802ac1f175 100644 --- a/worlds/subnautica/__init__.py +++ b/worlds/subnautica/__init__.py @@ -5,7 +5,8 @@ import itertools from typing import List, Dict, Any, cast from BaseClasses import Region, Entrance, Location, Item, Tutorial, ItemClassification -from worlds.AutoWorld import World, WebWorld +from worlds.AutoWorld import World, WebWorld, staticproperty +from Utils import cache_argsless from . import items from . import locations from . import creatures @@ -16,21 +17,26 @@ from .rules import set_rules logger = logging.getLogger("Subnautica") -class SubnaticaWeb(WebWorld): - tutorials = [Tutorial( - "Multiworld Setup Guide", - "A guide to setting up the Subnautica randomizer connected to an Archipelago Multiworld", - "English", - "setup_en.md", - "setup/en", - ["Berserker"] - )] - - all_locations = {data["name"]: loc_id for loc_id, data in locations.location_table.items()} all_locations.update(creatures.creature_locations) +@staticproperty +@cache_argsless +def web(): + class SubnaticaWeb(WebWorld): + tutorials = [Tutorial( + "Multiworld Setup Guide", + "A guide to setting up the Subnautica randomizer connected to an Archipelago Multiworld", + "English", + "setup_en.md", + "setup/en", + ["Berserker"] + )] + + return SubnaticaWeb() + + class SubnauticaWorld(World): """ Subnautica is an undersea exploration game. Stranded on an alien world, you become infected by @@ -38,7 +44,7 @@ class SubnauticaWorld(World): You must find a cure for yourself, build an escape rocket, and leave the planet. """ game = "Subnautica" - web = SubnaticaWeb() + web = web item_name_to_id = {data.name: item_id for item_id, data in items.item_table.items()} location_name_to_id = all_locations