Skip to content

Commit

Permalink
The Witness: Make location order in the spoiler log deterministic (#3895
Browse files Browse the repository at this point in the history
)

* Fix location order

* Update worlds/witness/data/static_logic.py

Co-authored-by: Exempt-Medic <[email protected]>

---------

Co-authored-by: Exempt-Medic <[email protected]>
  • Loading branch information
NewSoupVi and Exempt-Medic authored Dec 29, 2024
1 parent 0de1369 commit 8dbecf3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions worlds/witness/data/static_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions worlds/witness/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,41 @@ 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"]
if region is None:
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

Expand Down

0 comments on commit 8dbecf3

Please sign in to comment.