diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-08 18:35:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-08 17:35:12 -0600 |
| commit | bbbbc71bee25cfd22c5304f98f5a7881383585a3 (patch) | |
| tree | d27581db7b8db03da4b731fe8c2d5072d3162cf8 /locations.py | |
| download | lingo-apworld-bbbbc71bee25cfd22c5304f98f5a7881383585a3.tar.gz lingo-apworld-bbbbc71bee25cfd22c5304f98f5a7881383585a3.tar.bz2 lingo-apworld-bbbbc71bee25cfd22c5304f98f5a7881383585a3.zip | |
Lingo: New game (#1806)
Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com> Co-authored-by: Fabian Dill <Berserker66@users.noreply.github.com> Co-authored-by: Phar <zach@alliware.com>
Diffstat (limited to 'locations.py')
| -rw-r--r-- | locations.py | 80 |
1 files changed, 80 insertions, 0 deletions
| diff --git a/locations.py b/locations.py new file mode 100644 index 0000000..5903d60 --- /dev/null +++ b/locations.py | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | from enum import Flag, auto | ||
| 2 | from typing import Dict, List, NamedTuple | ||
| 3 | |||
| 4 | from BaseClasses import Location | ||
| 5 | from .static_logic import DOORS_BY_ROOM, PANELS_BY_ROOM, RoomAndPanel, get_door_location_id, get_panel_location_id | ||
| 6 | |||
| 7 | |||
| 8 | class LocationClassification(Flag): | ||
| 9 | normal = auto() | ||
| 10 | reduced = auto() | ||
| 11 | insanity = auto() | ||
| 12 | |||
| 13 | |||
| 14 | class LocationData(NamedTuple): | ||
| 15 | """ | ||
| 16 | LocationData for a location in Lingo | ||
| 17 | """ | ||
| 18 | code: int | ||
| 19 | room: str | ||
| 20 | panels: List[RoomAndPanel] | ||
| 21 | classification: LocationClassification | ||
| 22 | |||
| 23 | def panel_ids(self): | ||
| 24 | ids = set() | ||
| 25 | for panel in self.panels: | ||
| 26 | effective_room = self.room if panel.room is None else panel.room | ||
| 27 | panel_data = PANELS_BY_ROOM[effective_room][panel.panel] | ||
| 28 | ids = ids | set(panel_data.internal_ids) | ||
| 29 | return ids | ||
| 30 | |||
| 31 | |||
| 32 | class LingoLocation(Location): | ||
| 33 | """ | ||
| 34 | Location from the game Lingo | ||
| 35 | """ | ||
| 36 | game: str = "Lingo" | ||
| 37 | |||
| 38 | |||
| 39 | ALL_LOCATION_TABLE: Dict[str, LocationData] = {} | ||
| 40 | |||
| 41 | |||
| 42 | def load_location_data(): | ||
| 43 | global ALL_LOCATION_TABLE | ||
| 44 | |||
| 45 | for room_name, panels in PANELS_BY_ROOM.items(): | ||
| 46 | for panel_name, panel in panels.items(): | ||
| 47 | location_name = f"{room_name} - {panel_name}" | ||
| 48 | |||
| 49 | classification = LocationClassification.insanity | ||
| 50 | if panel.check: | ||
| 51 | classification |= LocationClassification.normal | ||
| 52 | |||
| 53 | if not panel.exclude_reduce: | ||
| 54 | classification |= LocationClassification.reduced | ||
| 55 | |||
| 56 | ALL_LOCATION_TABLE[location_name] = \ | ||
| 57 | LocationData(get_panel_location_id(room_name, panel_name), room_name, | ||
| 58 | [RoomAndPanel(None, panel_name)], classification) | ||
| 59 | |||
| 60 | for room_name, doors in DOORS_BY_ROOM.items(): | ||
| 61 | for door_name, door in doors.items(): | ||
| 62 | if door.skip_location or door.event or door.panels is None: | ||
| 63 | continue | ||
| 64 | |||
| 65 | location_name = door.location_name | ||
| 66 | classification = LocationClassification.normal | ||
| 67 | if door.include_reduce: | ||
| 68 | classification |= LocationClassification.reduced | ||
| 69 | |||
| 70 | if location_name in ALL_LOCATION_TABLE: | ||
| 71 | new_id = ALL_LOCATION_TABLE[location_name].code | ||
| 72 | classification |= ALL_LOCATION_TABLE[location_name].classification | ||
| 73 | else: | ||
| 74 | new_id = get_door_location_id(room_name, door_name) | ||
| 75 | |||
| 76 | ALL_LOCATION_TABLE[location_name] = LocationData(new_id, room_name, door.panels, classification) | ||
| 77 | |||
| 78 | |||
| 79 | # Initialize location data on the module scope. | ||
| 80 | load_location_data() | ||
