From c5a564bfc9bcf422d04c9016f56d65260b007c67 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Dec 2025 07:10:05 -0500 Subject: Refactor AccessRequirements --- apworld/regions.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'apworld/regions.py') 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 @@ from typing import TYPE_CHECKING -import BaseClasses -from BaseClasses import Region, ItemClassification, Entrance +from BaseClasses import Region, ItemClassification, Entrance, EntranceType from entrance_rando import randomize_entrances from .items import Lingo2Item -from .locations import Lingo2Location -from .player_logic import AccessRequirements -from .rules import make_location_lambda +from .locations import Lingo2Location, Lingo2Entrance +from .rules import AccessRequirements if TYPE_CHECKING: from . import Lingo2World @@ -21,13 +19,13 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di reqs = location.reqs.copy() reqs.remove_room(new_region.name) - new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], - location.code, new_region) - new_location.access_rule = make_location_lambda(reqs, world, regions) + new_location = Lingo2Location.non_event_location(world, location.code, new_region) + new_location.set_access_rule(reqs, regions) new_region.locations.append(new_location) for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): - new_location = Lingo2Location(world.player, event_name, None, new_region) + new_location = Lingo2Location.event_location(world, event_name, new_region) + if world.for_tracker and item_name == "Victory": new_location.goal = True @@ -41,12 +39,11 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di if port.no_shuffle: continue - new_location = Lingo2Location(world.player, f"Worldport {port.id} Entered", None, new_region) + new_location = Lingo2Location.event_location(world, f"Worldport {port.id} Entered", new_region) new_location.port_id = port.id if port.HasField("required_door"): - new_location.access_rule = \ - make_location_lambda(world.player_logic.get_door_open_reqs(port.required_door), world, regions) + new_location.set_access_rule(world.player_logic.get_door_open_reqs(port.required_door), regions) new_region.locations.append(new_location) @@ -141,8 +138,8 @@ def create_regions(world: "Lingo2World"): # what regions are dead ends. continue - connection = Entrance(world.player, connection_name, regions[from_region]) - connection.access_rule = make_location_lambda(reqs, world, regions) + connection = Lingo2Entrance(world, connection_name, regions[from_region]) + connection.set_access_rule(reqs, regions) regions[from_region].exits.append(connection) connection.connect(regions[to_region]) @@ -182,13 +179,13 @@ def shuffle_entrances(world: "Lingo2World"): from_region = world.multiworld.get_region(from_region_name, world.player) to_region = world.multiworld.get_region(to_region_name, world.player) - connection = Entrance(world.player, f"{from_region_name} - {chosen_port.display_name}", from_region) + connection = Lingo2Entrance(world, f"{from_region_name} - {chosen_port.display_name}", from_region) from_region.exits.append(connection) connection.connect(to_region) if chosen_port.HasField("required_door"): door_reqs = world.player_logic.get_door_open_reqs(chosen_port.required_door) - connection.access_rule = make_location_lambda(door_reqs, world, None) + connection.set_access_rule(door_reqs, None) for region in door_reqs.get_referenced_rooms(): world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), @@ -202,14 +199,15 @@ def shuffle_entrances(world: "Lingo2World"): port_id_by_name[connection_name] = port.id entrance = port_region.create_er_target(connection_name) - entrance.randomization_type = BaseClasses.EntranceType.TWO_WAY + entrance.randomization_type = EntranceType.TWO_WAY - er_exit = port_region.create_exit(connection_name) - er_exit.randomization_type = BaseClasses.EntranceType.TWO_WAY + er_exit = Lingo2Entrance(world, connection_name, port_region) + port_region.exits.append(er_exit) + er_exit.randomization_type = EntranceType.TWO_WAY if port.HasField("required_door"): door_reqs = world.player_logic.get_door_open_reqs(port.required_door) - er_exit.access_rule = make_location_lambda(door_reqs, world, None) + er_exit.set_access_rule(door_reqs, None) for region in door_reqs.get_referenced_rooms(): 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"): from_region = world.multiworld.get_region(from_region_name, world.player) to_region = world.multiworld.get_region(to_region_name, world.player) - connection = Entrance(world.player, f"{from_region_name} - {from_port.display_name}", from_region) + connection = Lingo2Entrance(world, f"{from_region_name} - {from_port.display_name}", from_region) reqs = AccessRequirements() if from_port.HasField("required_door"): @@ -246,7 +244,7 @@ def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"): reqs.items.add(f"Worldport {fpid} Entered") if not reqs.is_empty(): - connection.access_rule = make_location_lambda(reqs, world, None) + connection.set_access_rule(reqs, None) for region in reqs.get_referenced_rooms(): world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), -- cgit 1.4.1