diff options
Diffstat (limited to 'apworld/tracker.py')
| -rw-r--r-- | apworld/tracker.py | 41 |
1 files changed, 38 insertions, 3 deletions
| diff --git a/apworld/tracker.py b/apworld/tracker.py index 7239b65..a84c3f8 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 |
| @@ -47,7 +47,10 @@ class Tracker: | |||
| 47 | self.world.create_regions() | 47 | self.world.create_regions() |
| 48 | 48 | ||
| 49 | if self.world.options.shuffle_worldports: | 49 | if self.world.options.shuffle_worldports: |
| 50 | port_pairings = {int(fp): int(tp) for fp, tp in slot_data["port_pairings"].items()} | 50 | port_pairings = { |
| 51 | self.world.static_logic.port_id_by_ap_id[int(fp)]: self.world.static_logic.port_id_by_ap_id[int(tp)] | ||
| 52 | for fp, tp in slot_data["port_pairings"].items() | ||
| 53 | } | ||
| 51 | connect_ports_from_ut(port_pairings, self.world) | 54 | connect_ports_from_ut(port_pairings, self.world) |
| 52 | 55 | ||
| 53 | self.refresh_state() | 56 | self.refresh_state() |
| @@ -93,6 +96,7 @@ class Tracker: | |||
| 93 | PLAYER_NUM), prevent_sweep=True) | 96 | PLAYER_NUM), prevent_sweep=True) |
| 94 | 97 | ||
| 95 | self.state.sweep_for_advancements() | 98 | self.state.sweep_for_advancements() |
| 99 | self.state.update_reachable_regions(PLAYER_NUM) | ||
| 96 | 100 | ||
| 97 | self.accessible_locations = set() | 101 | self.accessible_locations = set() |
| 98 | self.accessible_worldports = set() | 102 | self.accessible_worldports = set() |
| @@ -110,3 +114,34 @@ class Tracker: | |||
| 110 | elif hasattr(location, "goal") and location.goal: | 114 | elif hasattr(location, "goal") and location.goal: |
| 111 | if not self.manager.goaled: | 115 | if not self.manager.goaled: |
| 112 | self.goal_accessible = True | 116 | self.goal_accessible = True |
| 117 | |||
| 118 | def get_path_to_location(self, location_id: int) -> list[str] | None: | ||
| 119 | location_name = self.world.location_id_to_name.get(location_id) | ||
| 120 | location = self.multiworld.get_location(location_name, PLAYER_NUM) | ||
| 121 | return self.get_logical_path(location.parent_region) | ||
| 122 | |||
| 123 | def get_path_to_port(self, port_id: int) -> list[str] | None: | ||
| 124 | port = self.world.static_logic.objects.ports[port_id] | ||
| 125 | region_name = self.world.static_logic.get_room_region_name(port.room_id) | ||
| 126 | region = self.multiworld.get_region(region_name, PLAYER_NUM) | ||
| 127 | return self.get_logical_path(region) | ||
| 128 | |||
| 129 | def get_path_to_goal(self): | ||
| 130 | room_id = self.world.player_logic.goal_room_id | ||
| 131 | region_name = self.world.static_logic.get_room_region_name(room_id) | ||
| 132 | region = self.multiworld.get_region(region_name, PLAYER_NUM) | ||
| 133 | return self.get_logical_path(region) | ||
| 134 | |||
| 135 | def get_logical_path(self, region: Region) -> list[str] | None: | ||
| 136 | if region not in self.state.path: | ||
| 137 | return None | ||
| 138 | |||
| 139 | def flist_to_iter(path_value) -> Iterator[str]: | ||
| 140 | while path_value: | ||
| 141 | region_or_entrance, path_value = path_value | ||
| 142 | yield region_or_entrance | ||
| 143 | |||
| 144 | reversed_path = self.state.path.get(region) | ||
| 145 | flat_path = reversed(list(map(str, flist_to_iter(reversed_path)))) | ||
| 146 | |||
| 147 | return list(flat_path)[1::2] | ||
