101 lines
3.5 KiB
Python
101 lines
3.5 KiB
Python
from BaseClasses import Location
|
|
from .Data import location_table, event_table
|
|
from .Game import starting_index, game_name
|
|
from typing import Any
|
|
|
|
|
|
######################
|
|
# Generate location lookups
|
|
######################
|
|
|
|
count = starting_index
|
|
victory_names: list[str] = []
|
|
|
|
# add sequential generated ids to the lists
|
|
for key, _ in enumerate(location_table):
|
|
if "victory" in location_table[key] and location_table[key]["victory"]:
|
|
victory_names.append(location_table[key]["name"])
|
|
|
|
if "id" in location_table[key]:
|
|
item_id = location_table[key]["id"]
|
|
if item_id >= count:
|
|
count = item_id
|
|
else:
|
|
raise ValueError(f"{location_table[key]['name']} has an invalid ID. ID must be at least {count + 1}")
|
|
|
|
location_table[key]["id"] = count
|
|
|
|
if "region" not in location_table[key]:
|
|
location_table[key]["region"] = "Manual" # all locations are in the same region for Manual
|
|
|
|
if isinstance(location_table[key].get("category", []), str):
|
|
location_table[key]["category"] = [location_table[key]["category"]]
|
|
|
|
count += 1
|
|
|
|
if not victory_names:
|
|
# Add the game completion location, which will have the Victory item assigned to it automatically
|
|
location_table.append({
|
|
"id": count + 1,
|
|
"name": "__Manual Game Complete__",
|
|
"region": "Manual",
|
|
"requires": []
|
|
# "category": custom_victory_location["category"] if "category" in custom_victory_location else []
|
|
})
|
|
victory_names.append("__Manual Game Complete__")
|
|
|
|
location_id_to_name: dict[int, str] = {}
|
|
location_name_to_location: dict[str, dict[str, Any]] = {}
|
|
location_name_groups: dict[str, set[str]] = {}
|
|
event_name_to_event: dict[str, dict[str, Any]] = {}
|
|
event_name_groups: dict[str, set[str]] = {}
|
|
|
|
for loc in location_table:
|
|
loc_name = loc.get("name", f"Unnamed Location {loc['id']}")
|
|
location_id_to_name[loc["id"]] = loc_name
|
|
location_name_to_location[loc_name] = loc
|
|
|
|
for c in loc.get("category", []):
|
|
if c not in location_name_groups:
|
|
location_name_groups[c] = set()
|
|
location_name_groups[c].add(loc_name)
|
|
|
|
|
|
# location_id_to_name[None] = "__Manual Game Complete__"
|
|
location_name_to_id = {name: id for id, name in location_id_to_name.items()}
|
|
|
|
id = 0
|
|
for key, event in enumerate(event_table):
|
|
event_name = f"{id}_{event['name']}".upper().replace(" ", "_")
|
|
while event_name in location_name_to_location:
|
|
id += 1
|
|
event_name = f"{id}_{event['name']}".upper().replace(" ", "_")
|
|
if "location_name" in event:
|
|
if event["location_name"] in location_name_to_location:
|
|
raise Exception(f"Cannot define event {event['location_name']} with the same name as a location.")
|
|
event_name_to_event[event["location_name"]] = event
|
|
else:
|
|
event_name_to_event[event_name] = event
|
|
event_name_to_event[event_name]["location_name"] = event_name
|
|
event_table[key]["location_name"] = event_name
|
|
if 'visible' not in event:
|
|
event_name_to_event[event_name]['visible'] = False
|
|
event_table[key]['visible'] = False
|
|
if 'region' not in event:
|
|
event_name_to_event[event_name]['region'] = "Manual"
|
|
event_table[key]['region'] = "Manual"
|
|
for c in event.get("category", []):
|
|
if c not in event_name_groups:
|
|
event_name_groups[c] = set()
|
|
event_name_groups[c].add(event['name'])
|
|
|
|
id += 1
|
|
|
|
######################
|
|
# Location classes
|
|
######################
|
|
|
|
|
|
class ManualLocation(Location):
|
|
game = game_name
|