AutoWorld: automate item_names and location_names
This commit is contained in:
parent
4dde466364
commit
e098b3c504
|
@ -8,13 +8,19 @@ class AutoWorldRegister(type):
|
|||
world_types:Dict[str, World] = {}
|
||||
|
||||
def __new__(cls, name, bases, dct):
|
||||
dct["all_names"] = dct["item_names"] | dct["location_names"] | set(dct.get("item_name_groups", {}))
|
||||
# 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["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:
|
||||
|
@ -50,19 +56,14 @@ class World(metaclass=AutoWorldRegister):
|
|||
options: dict = {} # link your Options mapping
|
||||
game: str # name the game
|
||||
topology_present: bool = False # indicate if world type has any meaningful layout/pathing
|
||||
item_names: Set[str] = frozenset() # set of all potential item names
|
||||
# maps item group names to sets of items. Example: "Weapons" -> {"Sword", "Bow"}
|
||||
item_name_groups: Dict[str, Set[str]] = {}
|
||||
location_names: Set[str] = frozenset() # set of all potential location names
|
||||
all_names: Set[str] = frozenset() # gets automatically populated with all item, item group and location names
|
||||
|
||||
# map names to their IDs
|
||||
item_name_to_id: Dict[str, int] = {}
|
||||
location_name_to_id: Dict[str, int] = {}
|
||||
|
||||
# reverse, automatically generated
|
||||
item_id_to_name: Dict[int, str] = {}
|
||||
location_id_to_name: Dict[int, str] = {}
|
||||
# maps item group names to sets of items. Example: "Weapons" -> {"Sword", "Bow"}
|
||||
item_name_groups: Dict[str, Set[str]] = {}
|
||||
|
||||
data_version = 1 # increment this every time something in your world's names/id mappings changes.
|
||||
|
||||
|
@ -78,6 +79,13 @@ class World(metaclass=AutoWorldRegister):
|
|||
world: MultiWorld
|
||||
player: int
|
||||
|
||||
# automatically generated
|
||||
item_id_to_name: Dict[int, str]
|
||||
location_id_to_name: Dict[int, str]
|
||||
|
||||
item_names: Set[str] # set of all potential item names
|
||||
location_names: Set[str] # set of all potential location names
|
||||
|
||||
def __init__(self, world: MultiWorld, player: int):
|
||||
self.world = world
|
||||
self.player = player
|
||||
|
|
|
@ -19,8 +19,6 @@ class Factorio(World):
|
|||
static_nodes = {"automation", "logistics", "rocket-silo"}
|
||||
custom_recipes = {}
|
||||
additional_advancement_technologies = set()
|
||||
item_names = frozenset(tech_table)
|
||||
location_names = frozenset(base_tech_table)
|
||||
|
||||
item_name_to_id = tech_table
|
||||
location_name_to_id = base_tech_table
|
||||
|
|
|
@ -15,8 +15,6 @@ from ..AutoWorld import World, LogicMixin
|
|||
class HKWorld(World):
|
||||
game: str = "Hollow Knight"
|
||||
options = hollow_knight_options
|
||||
item_names: Set[str] = frozenset(item_table)
|
||||
location_names: Set[str] = frozenset(lookup_name_to_id)
|
||||
|
||||
item_name_to_id = {name: data.id for name, data in item_table.items() if data.type != "Event"}
|
||||
location_name_to_id = lookup_name_to_id
|
||||
|
|
|
@ -17,8 +17,6 @@ class MinecraftWorld(World):
|
|||
game: str = "Minecraft"
|
||||
options = minecraft_options
|
||||
topology_present = True
|
||||
item_names = frozenset(item_table)
|
||||
location_names = frozenset(advancement_table)
|
||||
|
||||
item_name_to_id = {name: data.code for name, data in item_table.items()}
|
||||
location_name_to_id = {name: data.id for name, data in advancement_table.items()}
|
||||
|
|
|
@ -14,9 +14,6 @@ class OriBlindForest(World):
|
|||
|
||||
topology_present = True
|
||||
|
||||
item_names = frozenset(item_table)
|
||||
location_names = frozenset(lookup_name_to_id)
|
||||
|
||||
item_name_to_id = item_table
|
||||
location_name_to_id = lookup_name_to_id
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ from ..AutoWorld import World
|
|||
|
||||
class SubnauticaWorld(World):
|
||||
game: str = "Subnautica"
|
||||
item_names: Set[str] = frozenset(items_lookup_name_to_id)
|
||||
location_names: Set[str] = frozenset(locations_lookup_name_to_id)
|
||||
|
||||
item_name_to_id = items_lookup_name_to_id
|
||||
location_name_to_id = locations_lookup_name_to_id
|
||||
|
|
Loading…
Reference in New Issue