From 5a2e477dba6062cf21bb4e9daa11e56edca89138 Mon Sep 17 00:00:00 2001 From: Jarno Westhof Date: Sat, 11 Dec 2021 14:16:55 +0100 Subject: [PATCH] Added sanity check to see if all locations can be assigned to regions --- worlds/timespinner/Regions.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/worlds/timespinner/Regions.py b/worlds/timespinner/Regions.py index 5a3423fc..237bbc3d 100644 --- a/worlds/timespinner/Regions.py +++ b/worlds/timespinner/Regions.py @@ -1,4 +1,4 @@ -from typing import List, Dict, Tuple, Optional, Callable +from typing import List, Set, Dict, Tuple, Optional, Callable from BaseClasses import MultiWorld, Region, Entrance, Location, RegionType from .Options import is_option_enabled from .Locations import LocationData @@ -6,7 +6,7 @@ from .Locations import LocationData def create_regions(world: MultiWorld, player: int, locations: Tuple[LocationData, ...], location_cache: List[Location], pyramid_keys_unlock: str): locations_per_region = get_locations_per_region(locations) - world.regions += [ + regions = [ create_region(world, player, locations_per_region, location_cache, 'Menu'), create_region(world, player, locations_per_region, location_cache, 'Tutorial'), create_region(world, player, locations_per_region, location_cache, 'Lake desolation'), @@ -45,6 +45,10 @@ def create_regions(world: MultiWorld, player: int, locations: Tuple[LocationData create_region(world, player, locations_per_region, location_cache, 'Space time continuum') ] + throwIfAnyLocationIsNotAssignedToARegion(regions, locations_per_region.keys()) + + world.regions += regions + connectStartingRegion(world, player) names: Dict[str, int] = {} @@ -150,6 +154,16 @@ def create_regions(world: MultiWorld, player: int, locations: Tuple[LocationData connect(world, player, names, 'Space time continuum', 'Caves of Banishment (upper)', lambda state: pyramid_keys_unlock == "GateCavesOfBanishment") +def throwIfAnyLocationIsNotAssignedToARegion(regions: List[Region], regionNames: Set[str]): + existingRegions = set() + + for region in regions: + existingRegions.add(region.name) + + if (regionNames - existingRegions): + raise Exception("Tiemspinner: the following regions are used in locations: {}, but no such region exists".format(regionNames - existingRegions)) + + def create_location(player: int, location_data: LocationData, region: Region, location_cache: List[Location]) -> Location: location = Location(player, location_data.name, location_data.code, region) location.access_rule = location_data.rule