summary refs log tree commit diff stats
path: root/utils/pickle_static_data.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/pickle_static_data.py')
-rw-r--r--utils/pickle_static_data.py124
1 files changed, 110 insertions, 14 deletions
diff --git a/utils/pickle_static_data.py b/utils/pickle_static_data.py index e40c21c..92bcb7a 100644 --- a/utils/pickle_static_data.py +++ b/utils/pickle_static_data.py
@@ -6,8 +6,8 @@ import sys
6sys.path.append(os.path.join("worlds", "lingo")) 6sys.path.append(os.path.join("worlds", "lingo"))
7sys.path.append(".") 7sys.path.append(".")
8sys.path.append("..") 8sys.path.append("..")
9from datatypes import Door, DoorType, EntranceType, Painting, Panel, Progression, Room, RoomAndDoor, RoomAndPanel,\ 9from datatypes import Door, DoorType, EntranceType, Painting, Panel, PanelDoor, Progression, Room, RoomAndDoor,\
10 RoomEntrance 10 RoomAndPanel, RoomAndPanelDoor, RoomEntrance
11 11
12import hashlib 12import hashlib
13import pickle 13import pickle
@@ -18,10 +18,12 @@ import Utils
18ALL_ROOMS: List[Room] = [] 18ALL_ROOMS: List[Room] = []
19DOORS_BY_ROOM: Dict[str, Dict[str, Door]] = {} 19DOORS_BY_ROOM: Dict[str, Dict[str, Door]] = {}
20PANELS_BY_ROOM: Dict[str, Dict[str, Panel]] = {} 20PANELS_BY_ROOM: Dict[str, Dict[str, Panel]] = {}
21PANEL_DOORS_BY_ROOM: Dict[str, Dict[str, PanelDoor]] = {}
21PAINTINGS: Dict[str, Painting] = {} 22PAINTINGS: Dict[str, Painting] = {}
22 23
23PROGRESSIVE_ITEMS: List[str] = [] 24PROGRESSIVE_ITEMS: Set[str] = set()
24PROGRESSION_BY_ROOM: Dict[str, Dict[str, Progression]] = {} 25PROGRESSIVE_DOORS_BY_ROOM: Dict[str, Dict[str, Progression]] = {}
26PROGRESSIVE_PANELS_BY_ROOM: Dict[str, Dict[str, Progression]] = {}
25 27
26PAINTING_ENTRANCES: int = 0 28PAINTING_ENTRANCES: int = 0
27PAINTING_EXIT_ROOMS: Set[str] = set() 29PAINTING_EXIT_ROOMS: Set[str] = set()
@@ -37,8 +39,13 @@ PANEL_LOCATION_IDS: Dict[str, Dict[str, int]] = {}
37DOOR_LOCATION_IDS: Dict[str, Dict[str, int]] = {} 39DOOR_LOCATION_IDS: Dict[str, Dict[str, int]] = {}
38DOOR_ITEM_IDS: Dict[str, Dict[str, int]] = {} 40DOOR_ITEM_IDS: Dict[str, Dict[str, int]] = {}
39DOOR_GROUP_ITEM_IDS: Dict[str, int] = {} 41DOOR_GROUP_ITEM_IDS: Dict[str, int] = {}
42PANEL_DOOR_ITEM_IDS: Dict[str, Dict[str, int]] = {}
43PANEL_GROUP_ITEM_IDS: Dict[str, int] = {}
40PROGRESSIVE_ITEM_IDS: Dict[str, int] = {} 44PROGRESSIVE_ITEM_IDS: Dict[str, int] = {}
41 45
46# This doesn't need to be stored in the datafile.
47PANEL_DOOR_BY_PANEL_BY_ROOM: Dict[str, Dict[str, str]] = {}
48
42 49
43def hash_file(path): 50def hash_file(path):
44 md5 = hashlib.md5() 51 md5 = hashlib.md5()
@@ -53,7 +60,7 @@ def hash_file(path):
53 60
54def load_static_data(ll1_path, ids_path): 61def load_static_data(ll1_path, ids_path):
55 global PAINTING_EXITS, SPECIAL_ITEM_IDS, PANEL_LOCATION_IDS, DOOR_LOCATION_IDS, DOOR_ITEM_IDS, \ 62 global PAINTING_EXITS, SPECIAL_ITEM_IDS, PANEL_LOCATION_IDS, DOOR_LOCATION_IDS, DOOR_ITEM_IDS, \
56 DOOR_GROUP_ITEM_IDS, PROGRESSIVE_ITEM_IDS 63 DOOR_GROUP_ITEM_IDS, PROGRESSIVE_ITEM_IDS, PANEL_DOOR_ITEM_IDS, PANEL_GROUP_ITEM_IDS
57 64
58 # Load in all item and location IDs. These are broken up into groups based on the type of item/location. 65 # Load in all item and location IDs. These are broken up into groups based on the type of item/location.
59 with open(ids_path, "r") as file: 66 with open(ids_path, "r") as file:
@@ -86,6 +93,17 @@ def load_static_data(ll1_path, ids_path):
86 for item_name, item_id in config["door_groups"].items(): 93 for item_name, item_id in config["door_groups"].items():
87 DOOR_GROUP_ITEM_IDS[item_name] = item_id 94 DOOR_GROUP_ITEM_IDS[item_name] = item_id
88 95
96 if "panel_doors" in config:
97 for room_name, panel_doors in config["panel_doors"].items():
98 PANEL_DOOR_ITEM_IDS[room_name] = {}
99
100 for panel_door, item_id in panel_doors.items():
101 PANEL_DOOR_ITEM_IDS[room_name][panel_door] = item_id
102
103 if "panel_groups" in config:
104 for item_name, item_id in config["panel_groups"].items():
105 PANEL_GROUP_ITEM_IDS[item_name] = item_id
106
89 if "progression" in config: 107 if "progression" in config:
90 for item_name, item_id in config["progression"].items(): 108 for item_name, item_id in config["progression"].items():
91 PROGRESSIVE_ITEM_IDS[item_name] = item_id 109 PROGRESSIVE_ITEM_IDS[item_name] = item_id
@@ -147,6 +165,46 @@ def process_entrance(source_room, doors, room_obj):
147 room_obj.entrances.append(RoomEntrance(source_room, door, entrance_type)) 165 room_obj.entrances.append(RoomEntrance(source_room, door, entrance_type))
148 166
149 167
168def process_panel_door(room_name, panel_door_name, panel_door_data):
169 global PANEL_DOORS_BY_ROOM, PANEL_DOOR_BY_PANEL_BY_ROOM
170
171 panels: List[RoomAndPanel] = list()
172 for panel in panel_door_data["panels"]:
173 if isinstance(panel, dict):
174 panels.append(RoomAndPanel(panel["room"], panel["panel"]))
175 else:
176 panels.append(RoomAndPanel(room_name, panel))
177
178 for panel in panels:
179 PANEL_DOOR_BY_PANEL_BY_ROOM.setdefault(panel.room, {})[panel.panel] = RoomAndPanelDoor(room_name,
180 panel_door_name)
181
182 if "item_name" in panel_door_data:
183 item_name = panel_door_data["item_name"]
184 else:
185 panel_per_room = dict()
186 for panel in panels:
187 panel_room_name = room_name if panel.room is None else panel.room
188 panel_per_room.setdefault(panel_room_name, []).append(panel.panel)
189
190 room_strs = list()
191 for door_room_str, door_panels_str in panel_per_room.items():
192 room_strs.append(door_room_str + " - " + ", ".join(door_panels_str))
193
194 if len(panels) == 1:
195 item_name = f"{room_strs[0]} (Panel)"
196 else:
197 item_name = " and ".join(room_strs) + " (Panels)"
198
199 if "panel_group" in panel_door_data:
200 panel_group = panel_door_data["panel_group"]
201 else:
202 panel_group = None
203
204 panel_door_obj = PanelDoor(item_name, panel_group)
205 PANEL_DOORS_BY_ROOM[room_name][panel_door_name] = panel_door_obj
206
207
150def process_panel(room_name, panel_name, panel_data): 208def process_panel(room_name, panel_name, panel_data):
151 global PANELS_BY_ROOM 209 global PANELS_BY_ROOM
152 210
@@ -227,13 +285,18 @@ def process_panel(room_name, panel_name, panel_data):
227 else: 285 else:
228 non_counting = False 286 non_counting = False
229 287
288 if room_name in PANEL_DOOR_BY_PANEL_BY_ROOM and panel_name in PANEL_DOOR_BY_PANEL_BY_ROOM[room_name]:
289 panel_door = PANEL_DOOR_BY_PANEL_BY_ROOM[room_name][panel_name]
290 else:
291 panel_door = None
292
230 if "location_name" in panel_data: 293 if "location_name" in panel_data:
231 location_name = panel_data["location_name"] 294 location_name = panel_data["location_name"]
232 else: 295 else:
233 location_name = None 296 location_name = None
234 297
235 panel_obj = Panel(required_rooms, required_doors, required_panels, colors, check, event, exclude_reduce, 298 panel_obj = Panel(required_rooms, required_doors, required_panels, colors, check, event, exclude_reduce,
236 achievement, non_counting, location_name) 299 achievement, non_counting, panel_door, location_name)
237 PANELS_BY_ROOM[room_name][panel_name] = panel_obj 300 PANELS_BY_ROOM[room_name][panel_name] = panel_obj
238 301
239 302
@@ -325,7 +388,7 @@ def process_door(room_name, door_name, door_data):
325 painting_ids = [] 388 painting_ids = []
326 389
327 door_type = DoorType.NORMAL 390 door_type = DoorType.NORMAL
328 if door_name.endswith(" Sunwarp"): 391 if room_name == "Sunwarps":
329 door_type = DoorType.SUNWARP 392 door_type = DoorType.SUNWARP
330 elif room_name == "Pilgrim Antechamber" and door_name == "Sun Painting": 393 elif room_name == "Pilgrim Antechamber" and door_name == "Sun Painting":
331 door_type = DoorType.SUN_PAINTING 394 door_type = DoorType.SUN_PAINTING
@@ -404,11 +467,11 @@ def process_sunwarp(room_name, sunwarp_data):
404 SUNWARP_EXITS[sunwarp_data["dots"] - 1] = room_name 467 SUNWARP_EXITS[sunwarp_data["dots"] - 1] = room_name
405 468
406 469
407def process_progression(room_name, progression_name, progression_doors): 470def process_progressive_door(room_name, progression_name, progression_doors):
408 global PROGRESSIVE_ITEMS, PROGRESSION_BY_ROOM 471 global PROGRESSIVE_ITEMS, PROGRESSIVE_DOORS_BY_ROOM
409 472
410 # Progressive items are configured as a list of doors. 473 # Progressive items are configured as a list of doors.
411 PROGRESSIVE_ITEMS.append(progression_name) 474 PROGRESSIVE_ITEMS.add(progression_name)
412 475
413 progression_index = 1 476 progression_index = 1
414 for door in progression_doors: 477 for door in progression_doors:
@@ -419,11 +482,31 @@ def process_progression(room_name, progression_name, progression_doors):
419 door_room = room_name 482 door_room = room_name
420 door_door = door 483 door_door = door
421 484
422 room_progressions = PROGRESSION_BY_ROOM.setdefault(door_room, {}) 485 room_progressions = PROGRESSIVE_DOORS_BY_ROOM.setdefault(door_room, {})
423 room_progressions[door_door] = Progression(progression_name, progression_index) 486 room_progressions[door_door] = Progression(progression_name, progression_index)
424 progression_index += 1 487 progression_index += 1
425 488
426 489
490def process_progressive_panel(room_name, progression_name, progression_panel_doors):
491 global PROGRESSIVE_ITEMS, PROGRESSIVE_PANELS_BY_ROOM
492
493 # Progressive items are configured as a list of panel doors.
494 PROGRESSIVE_ITEMS.add(progression_name)
495
496 progression_index = 1
497 for panel_door in progression_panel_doors:
498 if isinstance(panel_door, Dict):
499 panel_door_room = panel_door["room"]
500 panel_door_door = panel_door["panel_door"]
501 else:
502 panel_door_room = room_name
503 panel_door_door = panel_door
504
505 room_progressions = PROGRESSIVE_PANELS_BY_ROOM.setdefault(panel_door_room, {})
506 room_progressions[panel_door_door] = Progression(progression_name, progression_index)
507 progression_index += 1
508
509
427def process_room(room_name, room_data): 510def process_room(room_name, room_data):
428 global ALL_ROOMS 511 global ALL_ROOMS
429 512
@@ -433,6 +516,12 @@ def process_room(room_name, room_data):
433 for source_room, doors in room_data["entrances"].items(): 516 for source_room, doors in room_data["entrances"].items():
434 process_entrance(source_room, doors, room_obj) 517 process_entrance(source_room, doors, room_obj)
435 518
519 if "panel_doors" in room_data:
520 PANEL_DOORS_BY_ROOM[room_name] = dict()
521
522 for panel_door_name, panel_door_data in room_data["panel_doors"].items():
523 process_panel_door(room_name, panel_door_name, panel_door_data)
524
436 if "panels" in room_data: 525 if "panels" in room_data:
437 PANELS_BY_ROOM[room_name] = dict() 526 PANELS_BY_ROOM[room_name] = dict()
438 527
@@ -454,8 +543,11 @@ def process_room(room_name, room_data):
454 process_sunwarp(room_name, sunwarp_data) 543 process_sunwarp(room_name, sunwarp_data)
455 544
456 if "progression" in room_data: 545 if "progression" in room_data:
457 for progression_name, progression_doors in room_data["progression"].items(): 546 for progression_name, pdata in room_data["progression"].items():
458 process_progression(room_name, progression_name, progression_doors) 547 if "doors" in pdata:
548 process_progressive_door(room_name, progression_name, pdata["doors"])
549 if "panel_doors" in pdata:
550 process_progressive_panel(room_name, progression_name, pdata["panel_doors"])
459 551
460 ALL_ROOMS.append(room_obj) 552 ALL_ROOMS.append(room_obj)
461 553
@@ -492,8 +584,10 @@ if __name__ == '__main__':
492 "ALL_ROOMS": ALL_ROOMS, 584 "ALL_ROOMS": ALL_ROOMS,
493 "DOORS_BY_ROOM": DOORS_BY_ROOM, 585 "DOORS_BY_ROOM": DOORS_BY_ROOM,
494 "PANELS_BY_ROOM": PANELS_BY_ROOM, 586 "PANELS_BY_ROOM": PANELS_BY_ROOM,
587 "PANEL_DOORS_BY_ROOM": PANEL_DOORS_BY_ROOM,
495 "PROGRESSIVE_ITEMS": PROGRESSIVE_ITEMS, 588 "PROGRESSIVE_ITEMS": PROGRESSIVE_ITEMS,
496 "PROGRESSION_BY_ROOM": PROGRESSION_BY_ROOM, 589 "PROGRESSIVE_DOORS_BY_ROOM": PROGRESSIVE_DOORS_BY_ROOM,
590 "PROGRESSIVE_PANELS_BY_ROOM": PROGRESSIVE_PANELS_BY_ROOM,
497 "PAINTING_ENTRANCES": PAINTING_ENTRANCES, 591 "PAINTING_ENTRANCES": PAINTING_ENTRANCES,
498 "PAINTING_EXIT_ROOMS": PAINTING_EXIT_ROOMS, 592 "PAINTING_EXIT_ROOMS": PAINTING_EXIT_ROOMS,
499 "PAINTING_EXITS": PAINTING_EXITS, 593 "PAINTING_EXITS": PAINTING_EXITS,
@@ -506,6 +600,8 @@ if __name__ == '__main__':
506 "DOOR_LOCATION_IDS": DOOR_LOCATION_IDS, 600 "DOOR_LOCATION_IDS": DOOR_LOCATION_IDS,
507 "DOOR_ITEM_IDS": DOOR_ITEM_IDS, 601 "DOOR_ITEM_IDS": DOOR_ITEM_IDS,
508 "DOOR_GROUP_ITEM_IDS": DOOR_GROUP_ITEM_IDS, 602 "DOOR_GROUP_ITEM_IDS": DOOR_GROUP_ITEM_IDS,
603 "PANEL_DOOR_ITEM_IDS": PANEL_DOOR_ITEM_IDS,
604 "PANEL_GROUP_ITEM_IDS": PANEL_GROUP_ITEM_IDS,
509 "PROGRESSIVE_ITEM_IDS": PROGRESSIVE_ITEM_IDS, 605 "PROGRESSIVE_ITEM_IDS": PROGRESSIVE_ITEM_IDS,
510 } 606 }
511 607