diff --git a/worlds/witness/data/static_logic.py b/worlds/witness/data/static_logic.py index 58f2e894e849..6cc4e1431d07 100644 --- a/worlds/witness/data/static_logic.py +++ b/worlds/witness/data/static_logic.py @@ -106,6 +106,7 @@ def read_logic_file(self, lines: List[str]) -> None: "entityType": location_id, "locationType": None, "area": current_area, + "order": len(self.ENTITIES_BY_HEX), } self.ENTITIES_BY_NAME[self.ENTITIES_BY_HEX[entity_hex]["checkName"]] = self.ENTITIES_BY_HEX[entity_hex] @@ -186,6 +187,7 @@ def read_logic_file(self, lines: List[str]) -> None: "entityType": entity_type, "locationType": location_type, "area": current_area, + "order": len(self.ENTITIES_BY_HEX), } self.ENTITY_ID_TO_NAME[entity_hex] = full_entity_name diff --git a/worlds/witness/regions.py b/worlds/witness/regions.py index 1df438f68b0d..a1f7df8a310c 100644 --- a/worlds/witness/regions.py +++ b/worlds/witness/regions.py @@ -114,7 +114,7 @@ def create_regions(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic if k not in player_logic.UNREACHABLE_REGIONS } - event_locations_per_region = defaultdict(list) + event_locations_per_region = defaultdict(dict) for event_location, event_item_and_entity in player_logic.EVENT_ITEM_PAIRS.items(): region = static_witness_logic.ENTITIES_BY_HEX[event_item_and_entity[1]]["region"] @@ -122,20 +122,33 @@ def create_regions(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic region_name = "Entry" else: region_name = region["name"] - event_locations_per_region[region_name].append(event_location) + order = self.reference_logic.ENTITIES_BY_HEX[event_item_and_entity[1]]["order"] + event_locations_per_region[region_name][event_location] = order for region_name, region in regions_to_create.items(): - locations_for_this_region = [ - self.reference_logic.ENTITIES_BY_HEX[panel]["checkName"] for panel in region["entities"] - if self.reference_logic.ENTITIES_BY_HEX[panel]["checkName"] - in self.player_locations.CHECK_LOCATION_TABLE + location_entities_for_this_region = [ + self.reference_logic.ENTITIES_BY_HEX[entity] for entity in region["entities"] ] + locations_for_this_region = { + entity["checkName"]: entity["order"] for entity in location_entities_for_this_region + if entity["checkName"] in self.player_locations.CHECK_LOCATION_TABLE + } - locations_for_this_region += event_locations_per_region[region_name] + events = event_locations_per_region[region_name] + locations_for_this_region.update(events) + + # First, sort by keys. + locations_for_this_region = dict(sorted(locations_for_this_region.items())) + + # Then, sort by game order (values) + locations_for_this_region = dict(sorted( + locations_for_this_region.items(), + key=lambda location_name_and_order: location_name_and_order[1] + )) all_locations = all_locations | set(locations_for_this_region) - new_region = create_region(world, region_name, self.player_locations, locations_for_this_region) + new_region = create_region(world, region_name, self.player_locations, list(locations_for_this_region)) regions_by_name[region_name] = new_region