Region: Use Mapping type for adding locations/exits #5354

This commit is contained in:
Duck
2025-10-04 21:04:02 -06:00
committed by GitHub
parent a547c8dd7d
commit ec9145e61d

View File

@@ -1346,8 +1346,7 @@ class Region:
for entrance in self.entrances: # BFS might be better here, trying DFS for now. for entrance in self.entrances: # BFS might be better here, trying DFS for now.
return entrance.parent_region.get_connecting_entrance(is_main_entrance) return entrance.parent_region.get_connecting_entrance(is_main_entrance)
def add_locations(self, locations: Dict[str, Optional[int]], def add_locations(self, locations: Mapping[str, int | None], location_type: type[Location] | None = None) -> None:
location_type: Optional[type[Location]] = None) -> None:
""" """
Adds locations to the Region object, where location_type is your Location class and locations is a dict of Adds locations to the Region object, where location_type is your Location class and locations is a dict of
location names to address. location names to address.
@@ -1435,8 +1434,8 @@ class Region:
entrance.connect(self) entrance.connect(self)
return entrance return entrance
def add_exits(self, exits: Union[Iterable[str], Dict[str, Optional[str]]], def add_exits(self, exits: Iterable[str] | Mapping[str, str | None],
rules: Dict[str, Callable[[CollectionState], bool]] = None) -> List[Entrance]: rules: Mapping[str, Callable[[CollectionState], bool]] | None = None) -> List[Entrance]:
""" """
Connects current region to regions in exit dictionary. Passed region names must exist first. Connects current region to regions in exit dictionary. Passed region names must exist first.
@@ -1444,7 +1443,7 @@ class Region:
created entrances will be named "self.name -> connecting_region" created entrances will be named "self.name -> connecting_region"
:param rules: rules for the exits from this region. format is {"connecting_region": rule} :param rules: rules for the exits from this region. format is {"connecting_region": rule}
""" """
if not isinstance(exits, Dict): if not isinstance(exits, Mapping):
exits = dict.fromkeys(exits) exits = dict.fromkeys(exits)
return [ return [
self.connect( self.connect(