diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-12-13 07:10:05 -0500 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-12-13 07:10:05 -0500 |
| commit | c5a564bfc9bcf422d04c9016f56d65260b007c67 (patch) | |
| tree | 9360c9d81c59418510c9beb1048a8ec93c10bfa2 /apworld/regions.py | |
| parent | b5cff95338c2ce6c35d0cc5a01ac51476885e4de (diff) | |
| download | lingo2-archipelago-loc-refactor.tar.gz lingo2-archipelago-loc-refactor.tar.bz2 lingo2-archipelago-loc-refactor.zip | |
Refactor AccessRequirements loc-refactor
Diffstat (limited to 'apworld/regions.py')
| -rw-r--r-- | apworld/regions.py | 42 |
1 files changed, 20 insertions, 22 deletions
| diff --git a/apworld/regions.py b/apworld/regions.py index 1118603..d5bdd46 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
| @@ -1,12 +1,10 @@ | |||
| 1 | from typing import TYPE_CHECKING | 1 | from typing import TYPE_CHECKING |
| 2 | 2 | ||
| 3 | import BaseClasses | 3 | from BaseClasses import Region, ItemClassification, Entrance, EntranceType |
| 4 | from BaseClasses import Region, ItemClassification, Entrance | ||
| 5 | from entrance_rando import randomize_entrances | 4 | from entrance_rando import randomize_entrances |
| 6 | from .items import Lingo2Item | 5 | from .items import Lingo2Item |
| 7 | from .locations import Lingo2Location | 6 | from .locations import Lingo2Location, Lingo2Entrance |
| 8 | from .player_logic import AccessRequirements | 7 | from .rules import AccessRequirements |
| 9 | from .rules import make_location_lambda | ||
| 10 | 8 | ||
| 11 | if TYPE_CHECKING: | 9 | if TYPE_CHECKING: |
| 12 | from . import Lingo2World | 10 | from . import Lingo2World |
| @@ -21,13 +19,13 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di | |||
| 21 | reqs = location.reqs.copy() | 19 | reqs = location.reqs.copy() |
| 22 | reqs.remove_room(new_region.name) | 20 | reqs.remove_room(new_region.name) |
| 23 | 21 | ||
| 24 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], | 22 | new_location = Lingo2Location.non_event_location(world, location.code, new_region) |
| 25 | location.code, new_region) | 23 | new_location.set_access_rule(reqs, regions) |
| 26 | new_location.access_rule = make_location_lambda(reqs, world, regions) | ||
| 27 | new_region.locations.append(new_location) | 24 | new_region.locations.append(new_location) |
| 28 | 25 | ||
| 29 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): | 26 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): |
| 30 | new_location = Lingo2Location(world.player, event_name, None, new_region) | 27 | new_location = Lingo2Location.event_location(world, event_name, new_region) |
| 28 | |||
| 31 | if world.for_tracker and item_name == "Victory": | 29 | if world.for_tracker and item_name == "Victory": |
| 32 | new_location.goal = True | 30 | new_location.goal = True |
| 33 | 31 | ||
| @@ -41,12 +39,11 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di | |||
| 41 | if port.no_shuffle: | 39 | if port.no_shuffle: |
| 42 | continue | 40 | continue |
| 43 | 41 | ||
| 44 | new_location = Lingo2Location(world.player, f"Worldport {port.id} Entered", None, new_region) | 42 | new_location = Lingo2Location.event_location(world, f"Worldport {port.id} Entered", new_region) |
| 45 | new_location.port_id = port.id | 43 | new_location.port_id = port.id |
| 46 | 44 | ||
| 47 | if port.HasField("required_door"): | 45 | if port.HasField("required_door"): |
| 48 | new_location.access_rule = \ | 46 | new_location.set_access_rule(world.player_logic.get_door_open_reqs(port.required_door), regions) |
| 49 | make_location_lambda(world.player_logic.get_door_open_reqs(port.required_door), world, regions) | ||
| 50 | 47 | ||
| 51 | new_region.locations.append(new_location) | 48 | new_region.locations.append(new_location) |
| 52 | 49 | ||
| @@ -141,8 +138,8 @@ def create_regions(world: "Lingo2World"): | |||
| 141 | # what regions are dead ends. | 138 | # what regions are dead ends. |
| 142 | continue | 139 | continue |
| 143 | 140 | ||
| 144 | connection = Entrance(world.player, connection_name, regions[from_region]) | 141 | connection = Lingo2Entrance(world, connection_name, regions[from_region]) |
| 145 | connection.access_rule = make_location_lambda(reqs, world, regions) | 142 | connection.set_access_rule(reqs, regions) |
| 146 | 143 | ||
| 147 | regions[from_region].exits.append(connection) | 144 | regions[from_region].exits.append(connection) |
| 148 | connection.connect(regions[to_region]) | 145 | connection.connect(regions[to_region]) |
| @@ -182,13 +179,13 @@ def shuffle_entrances(world: "Lingo2World"): | |||
| 182 | from_region = world.multiworld.get_region(from_region_name, world.player) | 179 | from_region = world.multiworld.get_region(from_region_name, world.player) |
| 183 | to_region = world.multiworld.get_region(to_region_name, world.player) | 180 | to_region = world.multiworld.get_region(to_region_name, world.player) |
| 184 | 181 | ||
| 185 | connection = Entrance(world.player, f"{from_region_name} - {chosen_port.display_name}", from_region) | 182 | connection = Lingo2Entrance(world, f"{from_region_name} - {chosen_port.display_name}", from_region) |
| 186 | from_region.exits.append(connection) | 183 | from_region.exits.append(connection) |
| 187 | connection.connect(to_region) | 184 | connection.connect(to_region) |
| 188 | 185 | ||
| 189 | if chosen_port.HasField("required_door"): | 186 | if chosen_port.HasField("required_door"): |
| 190 | door_reqs = world.player_logic.get_door_open_reqs(chosen_port.required_door) | 187 | door_reqs = world.player_logic.get_door_open_reqs(chosen_port.required_door) |
| 191 | connection.access_rule = make_location_lambda(door_reqs, world, None) | 188 | connection.set_access_rule(door_reqs, None) |
| 192 | 189 | ||
| 193 | for region in door_reqs.get_referenced_rooms(): | 190 | for region in door_reqs.get_referenced_rooms(): |
| 194 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), | 191 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), |
| @@ -202,14 +199,15 @@ def shuffle_entrances(world: "Lingo2World"): | |||
| 202 | port_id_by_name[connection_name] = port.id | 199 | port_id_by_name[connection_name] = port.id |
| 203 | 200 | ||
| 204 | entrance = port_region.create_er_target(connection_name) | 201 | entrance = port_region.create_er_target(connection_name) |
| 205 | entrance.randomization_type = BaseClasses.EntranceType.TWO_WAY | 202 | entrance.randomization_type = EntranceType.TWO_WAY |
| 206 | 203 | ||
| 207 | er_exit = port_region.create_exit(connection_name) | 204 | er_exit = Lingo2Entrance(world, connection_name, port_region) |
| 208 | er_exit.randomization_type = BaseClasses.EntranceType.TWO_WAY | 205 | port_region.exits.append(er_exit) |
| 206 | er_exit.randomization_type = EntranceType.TWO_WAY | ||
| 209 | 207 | ||
| 210 | if port.HasField("required_door"): | 208 | if port.HasField("required_door"): |
| 211 | door_reqs = world.player_logic.get_door_open_reqs(port.required_door) | 209 | door_reqs = world.player_logic.get_door_open_reqs(port.required_door) |
| 212 | er_exit.access_rule = make_location_lambda(door_reqs, world, None) | 210 | er_exit.set_access_rule(door_reqs, None) |
| 213 | 211 | ||
| 214 | for region in door_reqs.get_referenced_rooms(): | 212 | for region in door_reqs.get_referenced_rooms(): |
| 215 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), | 213 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), |
| @@ -236,7 +234,7 @@ def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"): | |||
| 236 | from_region = world.multiworld.get_region(from_region_name, world.player) | 234 | from_region = world.multiworld.get_region(from_region_name, world.player) |
| 237 | to_region = world.multiworld.get_region(to_region_name, world.player) | 235 | to_region = world.multiworld.get_region(to_region_name, world.player) |
| 238 | 236 | ||
| 239 | connection = Entrance(world.player, f"{from_region_name} - {from_port.display_name}", from_region) | 237 | connection = Lingo2Entrance(world, f"{from_region_name} - {from_port.display_name}", from_region) |
| 240 | 238 | ||
| 241 | reqs = AccessRequirements() | 239 | reqs = AccessRequirements() |
| 242 | if from_port.HasField("required_door"): | 240 | if from_port.HasField("required_door"): |
| @@ -246,7 +244,7 @@ def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"): | |||
| 246 | reqs.items.add(f"Worldport {fpid} Entered") | 244 | reqs.items.add(f"Worldport {fpid} Entered") |
| 247 | 245 | ||
| 248 | if not reqs.is_empty(): | 246 | if not reqs.is_empty(): |
| 249 | connection.access_rule = make_location_lambda(reqs, world, None) | 247 | connection.set_access_rule(reqs, None) |
| 250 | 248 | ||
| 251 | for region in reqs.get_referenced_rooms(): | 249 | for region in reqs.get_referenced_rooms(): |
| 252 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), | 250 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), |
