diff options
Diffstat (limited to 'apworld/tracker.py')
| -rw-r--r-- | apworld/tracker.py | 35 |
1 files changed, 33 insertions, 2 deletions
| diff --git a/apworld/tracker.py b/apworld/tracker.py index 7239b65..c65317c 100644 --- a/apworld/tracker.py +++ b/apworld/tracker.py | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | from typing import TYPE_CHECKING | 1 | from typing import TYPE_CHECKING, Iterator |
| 2 | 2 | ||
| 3 | from BaseClasses import MultiWorld, CollectionState, ItemClassification | 3 | from BaseClasses import MultiWorld, CollectionState, ItemClassification, Region, Entrance |
| 4 | from NetUtils import NetworkItem | 4 | from NetUtils import NetworkItem |
| 5 | from . import Lingo2World, Lingo2Item | 5 | from . import Lingo2World, Lingo2Item |
| 6 | from .regions import connect_ports_from_ut | 6 | from .regions import connect_ports_from_ut |
| @@ -110,3 +110,34 @@ class Tracker: | |||
| 110 | elif hasattr(location, "goal") and location.goal: | 110 | elif hasattr(location, "goal") and location.goal: |
| 111 | if not self.manager.goaled: | 111 | if not self.manager.goaled: |
| 112 | self.goal_accessible = True | 112 | self.goal_accessible = True |
| 113 | |||
| 114 | def get_path_to_location(self, location_id: int) -> list[str] | None: | ||
| 115 | location_name = self.world.location_id_to_name.get(location_id) | ||
| 116 | location = self.multiworld.get_location(location_name, PLAYER_NUM) | ||
| 117 | return self.get_logical_path(location.parent_region) | ||
| 118 | |||
| 119 | def get_path_to_port(self, port_id: int) -> list[str] | None: | ||
| 120 | port = self.world.static_logic.objects.ports[port_id] | ||
| 121 | region_name = self.world.static_logic.get_room_region_name(port.room_id) | ||
| 122 | region = self.multiworld.get_region(region_name, PLAYER_NUM) | ||
| 123 | return self.get_logical_path(region) | ||
| 124 | |||
| 125 | def get_path_to_goal(self): | ||
| 126 | room_id = self.world.player_logic.goal_room_id | ||
| 127 | region_name = self.world.static_logic.get_room_region_name(room_id) | ||
| 128 | region = self.multiworld.get_region(region_name, PLAYER_NUM) | ||
| 129 | return self.get_logical_path(region) | ||
| 130 | |||
| 131 | def get_logical_path(self, region: Region) -> list[str] | None: | ||
| 132 | if region not in self.state.path: | ||
| 133 | return None | ||
| 134 | |||
| 135 | def flist_to_iter(path_value) -> Iterator[str]: | ||
| 136 | while path_value: | ||
| 137 | region_or_entrance, path_value = path_value | ||
| 138 | yield region_or_entrance | ||
| 139 | |||
| 140 | reversed_path = self.state.path.get(region) | ||
| 141 | flat_path = reversed(list(map(str, flist_to_iter(reversed_path)))) | ||
| 142 | |||
| 143 | return list(flat_path)[1::2] | ||
