Skip to content

Commit

Permalink
fix tests and some worlds directly accessing the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysintreble committed Oct 9, 2024
1 parent 0d44bba commit 4add621
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ def append(self, region: Region):
region_cache[region.name] = region

def extend(self, regions: Iterable[Region]):
# TODO
if self.multiworld is not None:
region_cache = self.multiworld.worlds[regions[0].player].regions.region_cache
else:
region_cache = self.region_cache
for region in regions:
# TODO
if self.multiworld is not None:
region_cache = self.multiworld.worlds[region.player].regions.region_cache
else:
region_cache = self.region_cache
assert region.name not in region_cache, f"{region.name} already exists in region cache."
region_cache[region.name] = region

Expand Down
4 changes: 3 additions & 1 deletion test/general/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from argparse import Namespace
from typing import List, Optional, Tuple, Type, Union

from tornado.gen import multi

from BaseClasses import CollectionState, Item, ItemClassification, Location, MultiWorld, Region
from worlds import network_data_package
from worlds.AutoWorld import World, call_all
Expand Down Expand Up @@ -73,7 +75,7 @@ def generate_test_multiworld(players: int = 1) -> MultiWorld:
:return: The generated test multiworld
"""
multiworld = setup_multiworld([TestWorld] * players, seed=0)
multiworld.regions += [Region("Menu", player_id + 1, multiworld) for player_id in range(players)]
multiworld.regions += [Region("Menu", player_id, multiworld) for player_id in multiworld.player_ids]

return multiworld

Expand Down
6 changes: 2 additions & 4 deletions test/general/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from typing import Callable, Dict, Optional

from BaseClasses import CollectionState, MultiWorld, Region
from test.general import TestWorld, setup_solo_multiworld


class TestHelpers(unittest.TestCase):
multiworld: MultiWorld
player: int = 1

def setUp(self) -> None:
self.multiworld = MultiWorld(self.player)
self.multiworld.game[self.player] = "helper_test_game"
self.multiworld.player_name = {1: "Tester"}
self.multiworld.set_seed()
self.multiworld = setup_solo_multiworld(TestWorld, ())

def test_region_helpers(self) -> None:
"""Tests `Region.add_locations()` and `Region.add_exits()` have correct behavior"""
Expand Down
12 changes: 6 additions & 6 deletions worlds/aquaria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ class AquariaWorld(World):
options: AquariaOptions
"Every options of the world"

regions: AquariaRegions
_regions: AquariaRegions
"Used to manage Regions"

exclude: List[str]

def __init__(self, multiworld: MultiWorld, player: int):
"""Initialisation of the Aquaria World"""
super(AquariaWorld, self).__init__(multiworld, player)
self.regions = AquariaRegions(multiworld, player)
self._regions = AquariaRegions(multiworld, player)
self.ingredients_substitution = []
self.exclude = []

def create_regions(self) -> None:
"""
Create every Region in `regions`
"""
self.regions.add_regions_to_world()
self.regions.connect_regions()
self.regions.add_event_locations()
self._regions.add_regions_to_world()
self._regions.connect_regions()
self._regions.add_event_locations()

def create_item(self, name: str) -> AquariaItem:
"""
Expand Down Expand Up @@ -177,7 +177,7 @@ def set_rules(self) -> None:
Launched when the Multiworld generator is ready to generate rules
"""

self.regions.adjusting_rules(self.options)
self._regions.adjusting_rules(self.options)
self.multiworld.completion_condition[self.player] = lambda \
state: state.has("Victory", self.player)

Expand Down
2 changes: 1 addition & 1 deletion worlds/dark_souls_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ def _add_location_rule(self, location: Union[str, List[str]], rule: Union[Collec
def _add_entrance_rule(self, region: str, rule: Union[CollectionRule, str]) -> None:
"""Sets a rule for the entrance to the given region."""
assert region in location_tables
if not any(region == reg for reg in self.multiworld.regions.region_cache[self.player]): return
if not any(region == reg for reg in self.regions.region_cache): return
if isinstance(rule, str):
if " -> " not in rule:
assert item_dictionary[rule].classification == ItemClassification.progression
Expand Down
6 changes: 3 additions & 3 deletions worlds/oot/Dungeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def __init__(self, world, name, hint, font_color):
self.small_keys = []
self.dungeon_items = []

for region in world.multiworld.regions:
if region.player == world.player and region.dungeon == self.name:
for region in world.regions.get_regions():
if region.dungeon == self.name:
region.dungeon = self
self.regions.append(region)
self.regions.append(region)


def copy(self, new_world):
Expand Down
2 changes: 1 addition & 1 deletion worlds/oot/LocationList.py
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ def location_is_viewable(loc_name, correct_chest_appearances, fast_chests):
# Sets all Drop locations to a unique name in order to avoid name issues and to identify locations in the spoiler
# Also cause them to not be shown in the list of locations, only in playthrough
def set_drop_location_names(ootworld):
for region in ootworld.regions:
for region in ootworld._regions:
for location in region.locations:
if location.type == 'Drop':
location.name = location.parent_region.name + " " + location.name
Expand Down
14 changes: 7 additions & 7 deletions worlds/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def generate_early(self):
option_value = result.current_key
setattr(self, option_name, option_value)

self.regions = [] # internal caches of regions for this world, used later
self._regions = [] # internal caches of regions for this world, used later
self._regions_cache = {}

self.shop_prices = {}
Expand Down Expand Up @@ -586,7 +586,7 @@ def load_regions_from_json(self, file_path):
new_region.exits.append(new_exit)

self.multiworld.regions.append(new_region)
self.regions.append(new_region)
self._regions.append(new_region)
self._regions_cache[new_region.name] = new_region


Expand Down Expand Up @@ -624,7 +624,7 @@ def set_scrub_prices(self):
def random_shop_prices(self):
shop_item_indexes = ['7', '5', '8', '6']
self.shop_prices = {}
for region in self.regions:
for region in self._regions:
if self.shopsanity == 'random':
shop_item_count = self.random.randint(0, 4)
else:
Expand Down Expand Up @@ -756,7 +756,7 @@ def create_regions(self):
self.set_scrub_prices()

# Bind entrances to vanilla
for region in self.regions:
for region in self._regions:
for exit in region.exits:
exit.connect(self.get_region(exit.vanilla_connected_region))

Expand Down Expand Up @@ -1121,7 +1121,7 @@ def hint_type_players(hint_type: str) -> set:
items_by_region = {}
for player in barren_hint_players:
items_by_region[player] = {}
for r in multiworld.worlds[player].regions:
for r in multiworld.worlds[player]._regions:
items_by_region[player][r._hint_text] = {'dungeon': False, 'weight': 0, 'is_barren': True}
for d in multiworld.worlds[player].dungeons:
items_by_region[player][d.hint_text] = {'dungeon': True, 'weight': 0, 'is_barren': True}
Expand Down Expand Up @@ -1265,7 +1265,7 @@ def get_entrance_to_region(region):
if entrance.name in hint_entrances:
return entrance
if region.dungeon is not None:
for r in region.dungeon.regions:
for r in region.dungeon._regions:
for e in r.entrances:
if e.name in hint_entrances:
return e
Expand All @@ -1275,7 +1275,7 @@ def get_entrance_to_region(region):

if (self.shuffle_interior_entrances != 'off' or self.shuffle_dungeon_entrances
or self.shuffle_grotto_entrances or self.shuffle_bosses != 'off'):
for region in self.regions:
for region in self._regions:
if not any(bool(loc.address) for loc in region.locations): # check if region has any non-event locations
continue
main_entrance = get_entrance_to_region(region)
Expand Down
2 changes: 1 addition & 1 deletion worlds/pokemon_rb/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ def create_regions(world):
lambda state: logic.can_fly(state, world, player) and state.has("Town Map", player), one_way=True,
name="Town Map Fly Location")

cache = multiworld.regions.entrance_cache[world.player].copy()
cache = world.regions.entrance_cache.copy()
if world.options.badgesanity or world.options.door_shuffle in ("off", "simple"):
badges = None
badge_locs = None
Expand Down
4 changes: 2 additions & 2 deletions worlds/sc2/test/test_Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ class TestGridGeneration(Sc2TestBase):
}

def test_size_matches_exclusions(self):
self.assertNotIn(MissionTables.SC2Mission.ZERO_HOUR.mission_name, self.multiworld.regions)
self.assertNotIn(MissionTables.SC2Mission.ZERO_HOUR.mission_name, self.world.regions)
# WoL has 29 missions. -1 for Zero Hour being excluded, +1 for the automatically-added menu location
self.assertEqual(len(self.multiworld.regions), 29)
self.assertEqual(len(self.world.regions), 29)
2 changes: 1 addition & 1 deletion worlds/sm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def create_regions(self):
for src, dest in self.variaRando.randoExec.areaGraph.InterAreaTransitions:
src_region = self.multiworld.get_region(src.Name, self.player)
dest_region = self.multiworld.get_region(dest.Name, self.player)
if src.Name + "->" + dest.Name not in self.multiworld.regions.entrance_cache[self.player]:
if src.Name + "->" + dest.Name not in self.regions.entrance_cache:
src_region.exits.append(Entrance(self.player, src.Name + "->" + dest.Name, src_region))
srcDestEntrance = self.multiworld.get_entrance(src.Name + "->" + dest.Name, self.player)
srcDestEntrance.connect(dest_region)
Expand Down
2 changes: 1 addition & 1 deletion worlds/stardew_valley/stardew_rule/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Reach(BaseStardewRule):
player: int

def __call__(self, state: CollectionState) -> bool:
if self.resolution_hint == 'Region' and self.spot not in state.multiworld.regions.region_cache[self.player]:
if self.resolution_hint == 'Region' and self.spot not in state.multiworld.worlds[self.player].regions.region_cache:
return False
return state.can_reach(self.spot, self.resolution_hint, self.player)

Expand Down

0 comments on commit 4add621

Please sign in to comment.