From e27aeac2e5f9a1f70baeabe6ef0d0508db6d31a8 Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:59:07 -0400 Subject: [PATCH 01/24] HK: Update Setup Guide to use/mention Lumafly (#2308) --- worlds/hk/docs/setup_en.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/worlds/hk/docs/setup_en.md b/worlds/hk/docs/setup_en.md index adf975ff515e..fef0f051fec0 100644 --- a/worlds/hk/docs/setup_en.md +++ b/worlds/hk/docs/setup_en.md @@ -1,27 +1,27 @@ # Hollow Knight for Archipelago Setup Guide ## Required Software -* Download and unzip the Scarab+ Mod Manager from the [Scarab+ website](https://themulhima.github.io/Scarab/). +* Download and unzip the Lumafly Mod Manager from the [Lumafly website](https://themulhima.github.io/Lumafly/). * A legal copy of Hollow Knight. -## Installing the Archipelago Mod using Scarab+ -1. Launch Scarab+ and ensure it locates your Hollow Knight installation directory. +## Installing the Archipelago Mod using Lumafly +1. Launch Lumafly and ensure it locates your Hollow Knight installation directory. 2. Click the "Install" button near the "Archipelago" mod entry. * If desired, also install "Archipelago Map Mod" to use as an in-game tracker. 3. Launch the game, you're all set! -### What to do if Scarab+ fails to find your XBox Game Pass installation directory +### What to do if Lumafly fails to find your XBox Game Pass installation directory 1. Enter the XBox app and move your mouse over "Hollow Knight" on the left sidebar. 2. Click the three points then click "Manage". 3. Go to the "Files" tab and select "Browse...". 4. Click "Hollow Knight", then "Content", then click the path bar and copy it. -5. Run Scarab+ as an administrator and, when it asks you for the path, paste what you copied in step 4. +5. Run Lumafly as an administrator and, when it asks you for the path, paste what you copied in step 4. #### Alternative Method: 1. Click on your profile then "Settings". 2. Go to the "General" tab and select "CHANGE FOLDER". 3. Look for a folder where you want to install the game (preferably inside a folder on your desktop) and copy the path. -4. Run Scarab+ as an administrator and, when it asks you for the path, paste what you copied in step 3. +4. Run Lumafly as an administrator and, when it asks you for the path, paste what you copied in step 3. Note: The path folder needs to have the "Hollow Knight_Data" folder inside. From 13b68ecb154fb09e3cf41e3c3b81a3a1d1423d92 Mon Sep 17 00:00:00 2001 From: Alchav <59858495+Alchav@users.noreply.github.com> Date: Tue, 17 Oct 2023 01:20:34 -0400 Subject: [PATCH 02/24] =?UTF-8?q?Pok=C3=A9mon=20R/B:=20Door=20Shuffle=20fi?= =?UTF-8?q?xes=20(#2314)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Door shuffle fixes * Add Rt 23's Victory Road exit door to list of unreachable outdoor entrances --- worlds/pokemon_rb/locations.py | 2 +- worlds/pokemon_rb/regions.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/worlds/pokemon_rb/locations.py b/worlds/pokemon_rb/locations.py index ec6375859bb9..4f1b55a00dd7 100644 --- a/worlds/pokemon_rb/locations.py +++ b/worlds/pokemon_rb/locations.py @@ -795,7 +795,7 @@ def __init__(self, flag): LocationData("Pewter Gym", "Defeat Brock", "Defeat Brock", event=True), LocationData("Cerulean Gym", "Defeat Misty", "Defeat Misty", event=True), LocationData("Vermilion Gym", "Defeat Lt. Surge", "Defeat Lt. Surge", event=True), - LocationData("Celadon Gym", "Defeat Erika", "Defeat Erika", event=True), + LocationData("Celadon Gym-C", "Defeat Erika", "Defeat Erika", event=True), LocationData("Fuchsia Gym", "Defeat Koga", "Defeat Koga", event=True), LocationData("Cinnabar Gym", "Defeat Blaine", "Defeat Blaine", event=True), LocationData("Saffron Gym-C", "Defeat Sabrina", "Defeat Sabrina", event=True), diff --git a/worlds/pokemon_rb/regions.py b/worlds/pokemon_rb/regions.py index cc788dd2ba5c..431b23f49a6a 100644 --- a/worlds/pokemon_rb/regions.py +++ b/worlds/pokemon_rb/regions.py @@ -1456,7 +1456,9 @@ def pair(a, b): unreachable_outdoor_entrances = [ "Route 4-C to Mt Moon B1F-NE", "Fuchsia City-Good Rod House Backyard to Fuchsia Good Rod House", - "Cerulean City-Badge House Backyard to Cerulean Badge House" + "Cerulean City-Badge House Backyard to Cerulean Badge House", + # TODO: This doesn't need to be forced if fly location is Pokemon League? + "Route 23-N to Victory Road 2F-E" ] @@ -2220,7 +2222,7 @@ def cerulean_city_problem(): "Cinnabar Gym - Blaine Prize", "Viridian Gym - Giovanni Prize"]: badge_locs.append(multiworld.get_location(loc, player)) multiworld.random.shuffle(badges) - while badges[3].name == "Cascade Badge" and multiworld.badges_needed_for_hm_moves[player] == "on": + while badges[3].name == "Cascade Badge" and multiworld.badges_needed_for_hm_moves[player]: multiworld.random.shuffle(badges) for badge, loc in zip(badges, badge_locs): loc.place_locked_item(badge) @@ -2266,10 +2268,10 @@ def cerulean_city_problem(): ] def adds_reachable_entrances(entrances_copy, item): - state.collect(item, False) + state_copy = state.copy() + state_copy.collect(item, False) ret = len([entrance for entrance in entrances_copy if entrance in reachable_entrances or - entrance.parent_region.can_reach(state)]) > len(reachable_entrances) - state.remove(item) + entrance.parent_region.can_reach(state_copy)]) > len(reachable_entrances) return ret def dead_end(entrances_copy, e): @@ -2304,9 +2306,16 @@ def dead_end(entrances_copy, e): starting_entrances = len(entrances) dc_connected = [] event_locations = self.multiworld.get_filled_locations(player) + rock_tunnel_entrances = [entrance for entrance in entrances if "Rock Tunnel" in entrance.name] + entrances = [entrance for entrance in entrances if entrance not in rock_tunnel_entrances] while entrances: state.update_reachable_regions(player) state.sweep_for_events(locations=event_locations) + + if rock_tunnel_entrances and logic.rock_tunnel(state, player): + entrances += rock_tunnel_entrances + rock_tunnel_entrances = None + reachable_entrances = [entrance for entrance in entrances if entrance in reachable_entrances or entrance.parent_region.can_reach(state)] assert reachable_entrances, \ @@ -2328,12 +2337,8 @@ def dead_end(entrances_copy, e): # entrances list is empty while it's being sorted, must pass a copy to iterate through entrances_copy = entrances.copy() if multiworld.door_shuffle[player] == "decoupled": - if len(reachable_entrances) <= 8 and not logic.rock_tunnel(state, player): - entrances.sort(key=lambda e: 1 if "Rock Tunnel" in e.name else 2 if e.connected_region is not - None else 3 if e not in reachable_entrances else 0) - else: - entrances.sort(key=lambda e: 1 if e.connected_region is not None else 2 if e not in - reachable_entrances else 0) + entrances.sort(key=lambda e: 1 if e.connected_region is not None else 2 if e not in + reachable_entrances else 0) assert entrances[0].connected_region is None,\ "Ran out of valid reachable entrances in Pokemon Red and Blue door shuffle" elif len(reachable_entrances) > (1 if multiworld.door_shuffle[player] == "insanity" else 8) and len( From 11ebc523a9e96838206bde95e2b15abb3192d4e2 Mon Sep 17 00:00:00 2001 From: Trevor L <80716066+TRPG0@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:50:57 -0600 Subject: [PATCH 03/24] Hylics 2: Various fixes and APWorld support (#2324) - Fix generation failing with certain gesture shuffle options - Fixed passing ItemDict to multidata instead of item code - Don't allow CHARGE UP to be placed at Foglast: TV - APWorld support by removing LogicMixin from Rules.py --- setup.py | 1 - worlds/hylics2/Rules.py | 550 +++++++++++++++++++++++-------------- worlds/hylics2/__init__.py | 12 +- 3 files changed, 349 insertions(+), 214 deletions(-) diff --git a/setup.py b/setup.py index 6d4d947dbd1f..cea60dab8320 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,6 @@ "Clique", "DLCQuest", "Final Fantasy", - "Hylics 2", "Kingdom Hearts 2", "Lufia II Ancient Cave", "Meritous", diff --git a/worlds/hylics2/Rules.py b/worlds/hylics2/Rules.py index 12c22e01cd2f..6c55c8745b17 100644 --- a/worlds/hylics2/Rules.py +++ b/worlds/hylics2/Rules.py @@ -1,91 +1,128 @@ from worlds.generic.Rules import add_rule -from ..AutoWorld import LogicMixin +from BaseClasses import CollectionState -class Hylics2Logic(LogicMixin): +def air_dash(state: CollectionState, player: int) -> bool: + return state.has("PNEUMATOPHORE", player) - def _hylics2_can_air_dash(self, player): - return self.has("PNEUMATOPHORE", player) - def _hylics2_has_airship(self, player): - return self.has("DOCK KEY", player) +def airship(state: CollectionState, player: int) -> bool: + return state.has("DOCK KEY", player) - def _hylics2_has_jail_key(self, player): - return self.has("JAIL KEY", player) - def _hylics2_has_paddle(self, player): - return self.has("PADDLE", player) +def jail_key(state: CollectionState, player: int) -> bool: + return state.has("JAIL KEY", player) - def _hylics2_has_worm_room_key(self, player): - return self.has("WORM ROOM KEY", player) - def _hylics2_has_bridge_key(self, player): - return self.has("BRIDGE KEY", player) +def paddle(state: CollectionState, player: int) -> bool: + return state.has("PADDLE", player) - def _hylics2_has_upper_chamber_key(self, player): - return self.has("UPPER CHAMBER KEY", player) - def _hylics2_has_vessel_room_key(self, player): - return self.has("VESSEL ROOM KEY", player) +def worm_room_key(state: CollectionState, player: int) -> bool: + return state.has("WORM ROOM KEY", player) - def _hylics2_has_house_key(self, player): - return self.has("HOUSE KEY", player) - def _hylics2_has_cave_key(self, player): - return self.has("CAVE KEY", player) +def bridge_key(state: CollectionState, player: int) -> bool: + return state.has("BRIDGE KEY", player) - def _hylics2_has_skull_bomb(self, player): - return self.has("SKULL BOMB", player) - def _hylics2_has_tower_key(self, player): - return self.has("TOWER KEY", player) +def upper_chamber_key(state: CollectionState, player: int) -> bool: + return state.has("UPPER CHAMBER KEY", player) - def _hylics2_has_deep_key(self, player): - return self.has("DEEP KEY", player) - def _hylics2_has_upper_house_key(self, player): - return self.has("UPPER HOUSE KEY", player) +def vessel_room_key(state: CollectionState, player: int) -> bool: + return state.has("VESSEL ROOM KEY", player) - def _hylics2_has_clicker(self, player): - return self.has("CLICKER", player) - def _hylics2_has_tokens(self, player): - return self.has("SAGE TOKEN", player, 3) +def house_key(state: CollectionState, player: int) -> bool: + return state.has("HOUSE KEY", player) - def _hylics2_has_charge_up(self, player): - return self.has("CHARGE UP", player) - def _hylics2_has_cup(self, player): - return self.has("PAPER CUP", player, 1) +def cave_key(state: CollectionState, player: int) -> bool: + return state.has("CAVE KEY", player) - def _hylics2_has_1_member(self, player): - return self.has("Pongorma", player) or self.has("Dedusmuln", player) or self.has("Somsnosa", player) - def _hylics2_has_2_members(self, player): - return (self.has("Pongorma", player) and self.has("Dedusmuln", player)) or\ - (self.has("Pongorma", player) and self.has("Somsnosa", player)) or\ - (self.has("Dedusmuln", player) and self.has("Somsnosa", player)) +def skull_bomb(state: CollectionState, player: int) -> bool: + return state.has("SKULL BOMB", player) - def _hylics2_has_3_members(self, player): - return self.has("Pongorma", player) and self.has("Dedusmuln", player) and self.has("Somsnosa", player) - def _hylics2_enter_arcade2(self, player): - return self._hylics2_can_air_dash(player) and self._hylics2_has_airship(player) +def tower_key(state: CollectionState, player: int) -> bool: + return state.has("TOWER KEY", player) - def _hylics2_enter_wormpod(self, player): - return self._hylics2_has_airship(player) and self._hylics2_has_worm_room_key(player) and\ - self._hylics2_has_paddle(player) - def _hylics2_enter_sageship(self, player): - return self._hylics2_has_skull_bomb(player) and self._hylics2_has_airship(player) and\ - self._hylics2_has_paddle(player) +def deep_key(state: CollectionState, player: int) -> bool: + return state.has("DEEP KEY", player) - def _hylics2_enter_foglast(self, player): - return self._hylics2_enter_wormpod(player) - def _hylics2_enter_hylemxylem(self, player): - return self._hylics2_can_air_dash(player) and self._hylics2_enter_foglast(player) and\ - self._hylics2_has_bridge_key(player) +def upper_house_key(state: CollectionState, player: int) -> bool: + return state.has("UPPER HOUSE KEY", player) + + +def clicker(state: CollectionState, player: int) -> bool: + return state.has("CLICKER", player) + + +def all_tokens(state: CollectionState, player: int) -> bool: + return state.has("SAGE TOKEN", player, 3) + + +def charge_up(state: CollectionState, player: int) -> bool: + return state.has("CHARGE UP", player) + + +def paper_cup(state: CollectionState, player: int) -> bool: + return state.has("PAPER CUP", player) + + +def party_1(state: CollectionState, player: int) -> bool: + return state.has_any({"Pongorma", "Dedusmuln", "Somsnosa"}, player) + + +def party_2(state: CollectionState, player: int) -> bool: + return ( + state.has_all({"Pongorma", "Dedusmuln"}, player) + or state.has_all({"Pongorma", "Somsnosa"}, player) + or state.has_all({"Dedusmuln", "Somsnosa"}, player) + ) + + +def party_3(state: CollectionState, player: int) -> bool: + return state.has_all({"Pongorma", "Dedusmuln", "Somsnosa"}, player) + + +def enter_arcade2(state: CollectionState, player: int) -> bool: + return ( + air_dash(state, player) + and airship(state, player) + ) + + +def enter_wormpod(state: CollectionState, player: int) -> bool: + return ( + airship(state, player) + and worm_room_key(state, player) + and paddle(state, player) + ) + + +def enter_sageship(state: CollectionState, player: int) -> bool: + return ( + skull_bomb(state, player) + and airship(state, player) + and paddle(state, player) + ) + + +def enter_foglast(state: CollectionState, player: int) -> bool: + return enter_wormpod(state, player) + + +def enter_hylemxylem(state: CollectionState, player: int) -> bool: + return ( + air_dash(state, player) + and enter_foglast(state, player) + and bridge_key(state, player) + ) def set_rules(hylics2world): @@ -94,342 +131,439 @@ def set_rules(hylics2world): # Afterlife add_rule(world.get_location("Afterlife: TV", player), - lambda state: state._hylics2_has_cave_key(player)) + lambda state: cave_key(state, player)) # New Muldul add_rule(world.get_location("New Muldul: Underground Chest", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("New Muldul: TV", player), - lambda state: state._hylics2_has_house_key(player)) + lambda state: house_key(state, player)) add_rule(world.get_location("New Muldul: Upper House Chest 1", player), - lambda state: state._hylics2_has_upper_house_key(player)) + lambda state: upper_house_key(state, player)) add_rule(world.get_location("New Muldul: Upper House Chest 2", player), - lambda state: state._hylics2_has_upper_house_key(player)) + lambda state: upper_house_key(state, player)) add_rule(world.get_location("New Muldul: Pot above Vault", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) # New Muldul Vault add_rule(world.get_location("New Muldul: Rescued Blerol 1", player), - lambda state: ((state._hylics2_has_jail_key(player) and state._hylics2_has_paddle(player)) and\ - (state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player))) or\ - state._hylics2_enter_hylemxylem(player)) + lambda state: ( + ( + ( + jail_key(state, player) + and paddle(state, player) + ) + and ( + air_dash(state, player) + or airship(state, player) + ) + ) + or enter_hylemxylem(state, player) + )) add_rule(world.get_location("New Muldul: Rescued Blerol 2", player), - lambda state: ((state._hylics2_has_jail_key(player) and state._hylics2_has_paddle(player)) and\ - (state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player))) or\ - state._hylics2_enter_hylemxylem(player)) + lambda state: ( + ( + ( + jail_key(state, player) + and paddle(state, player) + ) + and ( + air_dash(state, player) + or airship(state, player) + ) + ) + or enter_hylemxylem(state, player) + )) add_rule(world.get_location("New Muldul: Vault Left Chest", player), - lambda state: state._hylics2_enter_hylemxylem(player)) + lambda state: enter_hylemxylem(state, player)) add_rule(world.get_location("New Muldul: Vault Right Chest", player), - lambda state: state._hylics2_enter_hylemxylem(player)) + lambda state: enter_hylemxylem(state, player)) add_rule(world.get_location("New Muldul: Vault Bomb", player), - lambda state: state._hylics2_enter_hylemxylem(player)) + lambda state: enter_hylemxylem(state, player)) # Viewax's Edifice add_rule(world.get_location("Viewax's Edifice: Canopic Jar", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Cave Sarcophagus", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Shielded Key", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Shielded Key", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Tower Pot", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Tower Jar", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Tower Chest", player), - lambda state: state._hylics2_has_paddle(player) and state._hylics2_has_tower_key(player)) + lambda state: ( + paddle(state, player) + and tower_key(state, player) + )) add_rule(world.get_location("Viewax's Edifice: Viewax Pot", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Defeat Viewax", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: TV", player), - lambda state: state._hylics2_has_paddle(player) and state._hylics2_has_jail_key(player)) + lambda state: ( + paddle(state, player) + and jail_key(state, player) + )) add_rule(world.get_location("Viewax's Edifice: Sage Fridge", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Viewax's Edifice: Sage Item 1", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Viewax's Edifice: Sage Item 2", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) # Arcade 1 add_rule(world.get_location("Arcade 1: Key", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Coin Dash", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Burrito Alcove 1", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Burrito Alcove 2", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Behind Spikes Banana", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Pyramid Banana", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Moving Platforms Muscle Applique", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Bed Banana", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) # Airship add_rule(world.get_location("Airship: Talk to Somsnosa", player), - lambda state: state._hylics2_has_worm_room_key(player)) + lambda state: worm_room_key(state, player)) # Foglast add_rule(world.get_location("Foglast: Underground Sarcophagus", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: Shielded Key", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: TV", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_clicker(player)) + lambda state: ( + air_dash(state, player) + and clicker(state, player) + )) add_rule(world.get_location("Foglast: Buy Clicker", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: Shielded Chest", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: Cave Fridge", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: Roof Sarcophagus", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Under Lair Sarcophagus 1", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Under Lair Sarcophagus 2", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Under Lair Sarcophagus 3", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Sage Sarcophagus", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Sage Item 1", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Foglast: Sage Item 2", player), - lambda state: state._hylics2_can_air_dash(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + air_dash(state, player) + and bridge_key(state, player) + )) # Drill Castle add_rule(world.get_location("Drill Castle: Island Banana", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Drill Castle: Island Pot", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Drill Castle: Cave Sarcophagus", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Drill Castle: TV", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) # Sage Labyrinth add_rule(world.get_location("Sage Labyrinth: Sage Item 1", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) add_rule(world.get_location("Sage Labyrinth: Sage Item 2", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) add_rule(world.get_location("Sage Labyrinth: Sage Left Arm", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) add_rule(world.get_location("Sage Labyrinth: Sage Right Arm", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) add_rule(world.get_location("Sage Labyrinth: Sage Left Leg", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) add_rule(world.get_location("Sage Labyrinth: Sage Right Leg", player), - lambda state: state._hylics2_has_deep_key(player)) + lambda state: deep_key(state, player)) # Sage Airship add_rule(world.get_location("Sage Airship: TV", player), - lambda state: state._hylics2_has_tokens(player)) + lambda state: all_tokens(state, player)) # Hylemxylem add_rule(world.get_location("Hylemxylem: Upper Chamber Banana", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Across Upper Reservoir Chest", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Lower Reservoir Chest", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Lower Reservoir Burrito 1", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Lower Reservoir Burrito 2", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Lower Reservoir Hole Pot 1", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Lower Reservoir Hole Pot 2", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Lower Reservoir Hole Pot 3", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Lower Reservoir Hole Sarcophagus", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Upper Reservoir Burrito 1", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Upper Reservoir Burrito 2", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Drained Upper Reservoir Burrito 3", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) add_rule(world.get_location("Hylemxylem: Upper Reservoir Hole Key", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) # extra rules if Extra Items in Logic is enabled if world.extra_items_in_logic[player]: for i in world.get_region("Foglast", player).entrances: - add_rule(i, lambda state: state._hylics2_has_charge_up(player)) + add_rule(i, lambda state: charge_up(state, player)) for i in world.get_region("Sage Airship", player).entrances: - add_rule(i, lambda state: state._hylics2_has_charge_up(player) and state._hylics2_has_cup(player) and\ - state._hylics2_has_worm_room_key(player)) + add_rule(i, lambda state: ( + charge_up(state, player) + and paper_cup(state, player) + and worm_room_key(state, player) + )) for i in world.get_region("Hylemxylem", player).entrances: - add_rule(i, lambda state: state._hylics2_has_charge_up(player) and state._hylics2_has_cup(player)) + add_rule(i, lambda state: ( + charge_up(state, player) + and paper_cup(state, player) + )) add_rule(world.get_location("Sage Labyrinth: Motor Hunter Sarcophagus", player), - lambda state: state._hylics2_has_charge_up(player) and state._hylics2_has_cup(player)) + lambda state: ( + charge_up(state, player) + and paper_cup(state, player) + )) # extra rules if Shuffle Party Members is enabled if world.party_shuffle[player]: for i in world.get_region("Arcade Island", player).entrances: - add_rule(i, lambda state: state._hylics2_has_3_members(player)) + add_rule(i, lambda state: party_3(state, player)) for i in world.get_region("Foglast", player).entrances: - add_rule(i, lambda state: state._hylics2_has_3_members(player) or\ - (state._hylics2_has_2_members(player) and state._hylics2_has_jail_key(player))) + add_rule(i, lambda state: ( + party_3(state, player) + or ( + party_2(state, player) + and jail_key(state, player) + ) + )) for i in world.get_region("Sage Airship", player).entrances: - add_rule(i, lambda state: state._hylics2_has_3_members(player)) + add_rule(i, lambda state: party_3(state, player)) for i in world.get_region("Hylemxylem", player).entrances: - add_rule(i, lambda state: state._hylics2_has_3_members(player)) + add_rule(i, lambda state: party_3(state, player)) add_rule(world.get_location("Viewax's Edifice: Defeat Viewax", player), - lambda state: state._hylics2_has_2_members(player)) + lambda state: party_2(state, player)) add_rule(world.get_location("New Muldul: Rescued Blerol 1", player), - lambda state: state._hylics2_has_2_members(player)) + lambda state: party_2(state, player)) add_rule(world.get_location("New Muldul: Rescued Blerol 2", player), - lambda state: state._hylics2_has_2_members(player)) + lambda state: party_2(state, player)) add_rule(world.get_location("New Muldul: Vault Left Chest", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Right Chest", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Bomb", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("Juice Ranch: Battle with Somsnosa", player), - lambda state: state._hylics2_has_2_members(player)) + lambda state: party_2(state, player)) add_rule(world.get_location("Juice Ranch: Somsnosa Joins", player), - lambda state: state._hylics2_has_2_members(player)) + lambda state: party_2(state, player)) add_rule(world.get_location("Airship: Talk to Somsnosa", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("Sage Labyrinth: Motor Hunter Sarcophagus", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) # extra rules if Shuffle Red Medallions is enabled if world.medallion_shuffle[player]: add_rule(world.get_location("New Muldul: Upper House Medallion", player), - lambda state: state._hylics2_has_upper_house_key(player)) + lambda state: upper_house_key(state, player)) add_rule(world.get_location("New Muldul: Vault Rear Left Medallion", player), - lambda state: state._hylics2_enter_foglast(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + enter_foglast(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("New Muldul: Vault Rear Right Medallion", player), - lambda state: state._hylics2_enter_foglast(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + enter_foglast(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("New Muldul: Vault Center Medallion", player), - lambda state: state._hylics2_enter_foglast(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + enter_foglast(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("New Muldul: Vault Front Left Medallion", player), - lambda state: state._hylics2_enter_foglast(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + enter_foglast(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("New Muldul: Vault Front Right Medallion", player), - lambda state: state._hylics2_enter_foglast(player) and state._hylics2_has_bridge_key(player)) + lambda state: ( + enter_foglast(state, player) + and bridge_key(state, player) + )) add_rule(world.get_location("Viewax's Edifice: Fort Wall Medallion", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Jar Medallion", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Viewax's Edifice: Sage Chair Medallion", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Arcade 1: Lonely Medallion", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Arcade 1: Alcove Medallion", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Foglast: Under Lair Medallion", player), - lambda state: state._hylics2_has_bridge_key(player)) + lambda state: bridge_key(state, player)) add_rule(world.get_location("Foglast: Mid-Air Medallion", player), - lambda state: state._hylics2_can_air_dash(player)) + lambda state: air_dash(state, player)) add_rule(world.get_location("Foglast: Top of Tower Medallion", player), - lambda state: state._hylics2_has_paddle(player)) + lambda state: paddle(state, player)) add_rule(world.get_location("Hylemxylem: Lower Reservoir Hole Medallion", player), - lambda state: state._hylics2_has_upper_chamber_key(player)) + lambda state: upper_chamber_key(state, player)) - # extra rules is Shuffle Red Medallions and Party Shuffle are enabled + # extra rules if Shuffle Red Medallions and Party Shuffle are enabled if world.party_shuffle[player] and world.medallion_shuffle[player]: add_rule(world.get_location("New Muldul: Vault Rear Left Medallion", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Rear Right Medallion", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Center Medallion", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Front Left Medallion", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) add_rule(world.get_location("New Muldul: Vault Front Right Medallion", player), - lambda state: state._hylics2_has_3_members(player)) + lambda state: party_3(state, player)) # entrances for i in world.get_region("Airship", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Arcade Island", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player) and state._hylics2_can_air_dash(player)) + add_rule(i, lambda state: ( + airship(state, player) + and air_dash(state, player) + )) for i in world.get_region("Worm Pod", player).entrances: - add_rule(i, lambda state: state._hylics2_enter_wormpod(player)) + add_rule(i, lambda state: enter_wormpod(state, player)) for i in world.get_region("Foglast", player).entrances: - add_rule(i, lambda state: state._hylics2_enter_foglast(player)) + add_rule(i, lambda state: enter_foglast(state, player)) for i in world.get_region("Sage Labyrinth", player).entrances: - add_rule(i, lambda state: state._hylics2_has_skull_bomb(player)) + add_rule(i, lambda state: skull_bomb(state, player)) for i in world.get_region("Sage Airship", player).entrances: - add_rule(i, lambda state: state._hylics2_enter_sageship(player)) + add_rule(i, lambda state: enter_sageship(state, player)) for i in world.get_region("Hylemxylem", player).entrances: - add_rule(i, lambda state: state._hylics2_enter_hylemxylem(player)) + add_rule(i, lambda state: enter_hylemxylem(state, player)) # random start logic (default) if ((not world.random_start[player]) or \ (world.random_start[player] and hylics2world.start_location == "Waynehouse")): # entrances for i in world.get_region("Viewax", player).entrances: - add_rule(i, lambda state: state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player)) + add_rule(i, lambda state: ( + air_dash(state, player) + and airship(state, player) + )) for i in world.get_region("TV Island", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Shield Facility", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Juice Ranch", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) # random start logic (Viewax's Edifice) elif (world.random_start[player] and hylics2world.start_location == "Viewax's Edifice"): for i in world.get_region("Waynehouse", player).entrances: - add_rule(i, lambda state: state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player)) + add_rule(i, lambda state: ( + air_dash(state, player) + or airship(state, player) + )) for i in world.get_region("New Muldul", player).entrances: - add_rule(i, lambda state: state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player)) + add_rule(i, lambda state: ( + air_dash(state, player) + or airship(state, player) + )) for i in world.get_region("New Muldul Vault", player).entrances: - add_rule(i, lambda state: state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player)) + add_rule(i, lambda state: ( + air_dash(state, player) + or airship(state, player) + )) for i in world.get_region("Drill Castle", player).entrances: - add_rule(i, lambda state: state._hylics2_can_air_dash(player) or state._hylics2_has_airship(player)) + add_rule(i, lambda state: ( + air_dash(state, player) + or airship(state, player) + )) for i in world.get_region("TV Island", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Shield Facility", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Juice Ranch", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Sage Labyrinth", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) # random start logic (TV Island) elif (world.random_start[player] and hylics2world.start_location == "TV Island"): for i in world.get_region("Waynehouse", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("New Muldul", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("New Muldul Vault", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Drill Castle", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Viewax", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Shield Facility", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Juice Ranch", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Sage Labyrinth", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) # random start logic (Shield Facility) elif (world.random_start[player] and hylics2world.start_location == "Shield Facility"): for i in world.get_region("Waynehouse", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("New Muldul", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("New Muldul Vault", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Drill Castle", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Viewax", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("TV Island", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) for i in world.get_region("Sage Labyrinth", player).entrances: - add_rule(i, lambda state: state._hylics2_has_airship(player)) + add_rule(i, lambda state: airship(state, player)) \ No newline at end of file diff --git a/worlds/hylics2/__init__.py b/worlds/hylics2/__init__.py index f721fb474923..19d901bf5a05 100644 --- a/worlds/hylics2/__init__.py +++ b/worlds/hylics2/__init__.py @@ -130,11 +130,11 @@ def pre_fill(self): tvs = list(Locations.tv_location_table.items()) # if Extra Items in Logic is enabled place CHARGE UP first and make sure it doesn't get - # placed at Sage Airship: TV + # placed at Sage Airship: TV or Foglast: TV if self.multiworld.extra_items_in_logic[self.player]: tv = self.multiworld.random.choice(tvs) gest = gestures.index((200681, Items.gesture_item_table[200681])) - while tv[1]["name"] == "Sage Airship: TV": + while tv[1]["name"] == "Sage Airship: TV" or tv[1]["name"] == "Foglast: TV": tv = self.multiworld.random.choice(tvs) self.multiworld.get_location(tv[1]["name"], self.player)\ .place_locked_item(self.add_item(gestures[gest][1]["name"], gestures[gest][1]["classification"], @@ -146,7 +146,7 @@ def pre_fill(self): gest = self.multiworld.random.choice(gestures) tv = self.multiworld.random.choice(tvs) self.multiworld.get_location(tv[1]["name"], self.player)\ - .place_locked_item(self.add_item(gest[1]["name"], gest[1]["classification"], gest[1])) + .place_locked_item(self.add_item(gest[1]["name"], gest[1]["classification"], gest[0])) gestures.remove(gest) tvs.remove(tv) @@ -232,8 +232,10 @@ def create_regions(self) -> None: # create location for beating the game and place Victory event there loc = Location(self.player, "Defeat Gibby", None, self.multiworld.get_region("Hylemxylem", self.player)) loc.place_locked_item(self.create_event("Victory")) - set_rule(loc, lambda state: state._hylics2_has_upper_chamber_key(self.player) - and state._hylics2_has_vessel_room_key(self.player)) + set_rule(loc, lambda state: ( + state.has("UPPER CHAMBER KEY", self.player) + and state.has("VESSEL ROOM KEY", self.player) + )) self.multiworld.get_region("Hylemxylem", self.player).locations.append(loc) self.multiworld.completion_condition[self.player] = lambda state: state.has("Victory", self.player) From 5ca1ababfdd94a6e309d97f658065aeb86b7a463 Mon Sep 17 00:00:00 2001 From: agilbert1412 Date: Wed, 18 Oct 2023 15:53:12 -0400 Subject: [PATCH 04/24] DLC Quest: Fix code structure, typos, poor code quality (#2066) "Added a bunch of tests to make sure I don't break anything during refactoring Huge cleanup in the Regions file, extract methods, remove code duplicate, fix typos, fix variable naming conventions, etc. Small cleanup in other places, minor stuff just what was needed for Regions" --- worlds/dlcquest/Regions.py | 477 +++++++------------- worlds/dlcquest/test/TestItemShuffle.py | 130 ++++++ worlds/dlcquest/test/TestOptionsLong.py | 87 ++++ worlds/dlcquest/test/__init__.py | 53 +++ worlds/dlcquest/test/checks/__init__.py | 0 worlds/dlcquest/test/checks/world_checks.py | 42 ++ worlds/dlcquest/test/option_names.py | 5 + 7 files changed, 486 insertions(+), 308 deletions(-) create mode 100644 worlds/dlcquest/test/TestItemShuffle.py create mode 100644 worlds/dlcquest/test/TestOptionsLong.py create mode 100644 worlds/dlcquest/test/__init__.py create mode 100644 worlds/dlcquest/test/checks/__init__.py create mode 100644 worlds/dlcquest/test/checks/world_checks.py create mode 100644 worlds/dlcquest/test/option_names.py diff --git a/worlds/dlcquest/Regions.py b/worlds/dlcquest/Regions.py index dfb5f6c021be..402ac722a0ad 100644 --- a/worlds/dlcquest/Regions.py +++ b/worlds/dlcquest/Regions.py @@ -1,4 +1,5 @@ import math +from typing import List from BaseClasses import Entrance, MultiWorld, Region from . import Options @@ -9,318 +10,178 @@ "Double Jump Behind the Tree", "The Forest", "Final Room"] -def add_coin_freemium(region: Region, Coin: int, player: int): - number_coin = f"{Coin} coins freemium" - location_coin = f"{region.name} coins freemium" - location = DLCQuestLocation(player, location_coin, None, region) - region.locations.append(location) - location.place_locked_item(create_event(player, number_coin)) +def add_coin_lfod(region: Region, coin: int, player: int): + add_coin(region, coin, player, " coins freemium") + +def add_coin_dlcquest(region: Region, coin: int, player: int): + add_coin(region, coin, player, " coins") -def add_coin_dlcquest(region: Region, Coin: int, player: int): - number_coin = f"{Coin} coins" - location_coin = f"{region.name} coins" + +def add_coin(region: Region, coin: int, player: int, suffix: str): + number_coin = f"{coin}{suffix}" + location_coin = f"{region.name}{suffix}" location = DLCQuestLocation(player, location_coin, None, region) region.locations.append(location) location.place_locked_item(create_event(player, number_coin)) -def create_regions(world: MultiWorld, player: int, World_Options: Options.DLCQuestOptions): - Regmenu = Region("Menu", player, world) - if (World_Options.campaign == Options.Campaign.option_basic or World_Options.campaign - == Options.Campaign.option_both): - Regmenu.exits += [Entrance(player, "DLC Quest Basic", Regmenu)] - if (World_Options.campaign == Options.Campaign.option_live_freemium_or_die or World_Options.campaign - == Options.Campaign.option_both): - Regmenu.exits += [Entrance(player, "Live Freemium or Die", Regmenu)] - world.regions.append(Regmenu) - - if (World_Options.campaign == Options.Campaign.option_basic or World_Options.campaign - == Options.Campaign.option_both): - - Regmoveright = Region("Move Right", player, world, "Start of the basic game") - Locmoveright_name = ["Movement Pack", "Animation Pack", "Audio Pack", "Pause Menu Pack"] - Regmoveright.exits = [Entrance(player, "Moving", Regmoveright)] - Regmoveright.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regmoveright) for - loc_name in Locmoveright_name] - add_coin_dlcquest(Regmoveright, 4, player) - if World_Options.coinsanity == Options.CoinSanity.option_coin: - coin_bundle_needed = math.floor(825 / World_Options.coinbundlequantity) - for i in range(coin_bundle_needed): - item_coin = f"DLC Quest: {World_Options.coinbundlequantity * (i + 1)} Coin" - Regmoveright.locations += [ - DLCQuestLocation(player, item_coin, location_table[item_coin], Regmoveright)] - if 825 % World_Options.coinbundlequantity != 0: - Regmoveright.locations += [ - DLCQuestLocation(player, "DLC Quest: 825 Coin", location_table["DLC Quest: 825 Coin"], - Regmoveright)] - world.regions.append(Regmoveright) - - Regmovpack = Region("Movement Pack", player, world) - Locmovpack_name = ["Time is Money Pack", "Psychological Warfare Pack", "Armor for your Horse Pack", - "Shepherd Sheep"] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Locmovpack_name += ["Sword"] - Regmovpack.exits = [Entrance(player, "Tree", Regmovpack), Entrance(player, "Cloud", Regmovpack)] - Regmovpack.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regmovpack) for loc_name - in Locmovpack_name] - add_coin_dlcquest(Regmovpack, 46, player) - world.regions.append(Regmovpack) - - Regbtree = Region("Behind Tree", player, world) - Locbtree_name = ["Double Jump Pack", "Map Pack", "Between Trees Sheep", "Hole in the Wall Sheep"] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Locbtree_name += ["Gun"] - Regbtree.exits = [Entrance(player, "Behind Tree Double Jump", Regbtree), - Entrance(player, "Forest Entrance", Regbtree)] - Regbtree.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regbtree) for loc_name in - Locbtree_name] - add_coin_dlcquest(Regbtree, 60, player) - world.regions.append(Regbtree) - - Regpsywarfare = Region("Psychological Warfare", player, world) - Locpsywarfare_name = ["West Cave Sheep"] - Regpsywarfare.exits = [Entrance(player, "Cloud Double Jump", Regpsywarfare)] - Regpsywarfare.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regpsywarfare) for - loc_name in Locpsywarfare_name] - add_coin_dlcquest(Regpsywarfare, 100, player) - world.regions.append(Regpsywarfare) - - Regdoubleleft = Region("Double Jump Total Left", player, world) - Locdoubleleft_name = ["Pet Pack", "Top Hat Pack", "North West Alcove Sheep"] - Regdoubleleft.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regdoubleleft) for - loc_name in - Locdoubleleft_name] - Regdoubleleft.exits = [Entrance(player, "Cave Tree", Regdoubleleft), - Entrance(player, "Cave Roof", Regdoubleleft)] - add_coin_dlcquest(Regdoubleleft, 50, player) - world.regions.append(Regdoubleleft) - - Regdoubleleftcave = Region("Double Jump Total Left Cave", player, world) - Locdoubleleftcave_name = ["Top Hat Sheep"] - Regdoubleleftcave.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regdoubleleftcave) - for loc_name in Locdoubleleftcave_name] - add_coin_dlcquest(Regdoubleleftcave, 9, player) - world.regions.append(Regdoubleleftcave) - - Regdoubleleftroof = Region("Double Jump Total Left Roof", player, world) - Locdoubleleftroof_name = ["North West Ceiling Sheep"] - Regdoubleleftroof.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regdoubleleftroof) - for loc_name in Locdoubleleftroof_name] - add_coin_dlcquest(Regdoubleleftroof, 10, player) - world.regions.append(Regdoubleleftroof) - - Regdoubletree = Region("Double Jump Behind Tree", player, world) - Locdoubletree_name = ["Sexy Outfits Pack", "Double Jump Alcove Sheep", "Sexy Outfits Sheep"] - Regdoubletree.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regdoubletree) for - loc_name in - Locdoubletree_name] - Regdoubletree.exits = [Entrance(player, "True Double Jump", Regdoubletree)] - add_coin_dlcquest(Regdoubletree, 89, player) - world.regions.append(Regdoubletree) - - Regtruedoublejump = Region("True Double Jump Behind Tree", player, world) - Loctruedoublejump_name = ["Double Jump Floating Sheep", "Cutscene Sheep"] - Regtruedoublejump.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regtruedoublejump) - for loc_name in Loctruedoublejump_name] - add_coin_dlcquest(Regtruedoublejump, 7, player) - world.regions.append(Regtruedoublejump) - - Regforest = Region("The Forest", player, world) - Locforest_name = ["Gun Pack", "Night Map Pack"] - Regforest.exits = [Entrance(player, "Behind Ogre", Regforest), - Entrance(player, "Forest Double Jump", Regforest)] - Regforest.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regforest) for loc_name in - Locforest_name] - add_coin_dlcquest(Regforest, 171, player) - world.regions.append(Regforest) - - Regforestdoublejump = Region("The Forest whit double Jump", player, world) - Locforestdoublejump_name = ["The Zombie Pack", "Forest Low Sheep"] - Regforestdoublejump.exits = [Entrance(player, "Forest True Double Jump", Regforestdoublejump)] - Regforestdoublejump.locations += [ - DLCQuestLocation(player, loc_name, location_table[loc_name], Regforestdoublejump) for loc_name in - Locforestdoublejump_name] - add_coin_dlcquest(Regforestdoublejump, 76, player) - world.regions.append(Regforestdoublejump) - - Regforesttruedoublejump = Region("The Forest whit double Jump Part 2", player, world) - Locforesttruedoublejump_name = ["Forest High Sheep"] - Regforesttruedoublejump.locations += [ - DLCQuestLocation(player, loc_name, location_table[loc_name], Regforesttruedoublejump) - for loc_name in Locforesttruedoublejump_name] - add_coin_dlcquest(Regforesttruedoublejump, 203, player) - world.regions.append(Regforesttruedoublejump) - - Regfinalroom = Region("The Final Boss Room", player, world) - Locfinalroom_name = ["Finish the Fight Pack"] - Regfinalroom.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regfinalroom) for - loc_name in - Locfinalroom_name] - world.regions.append(Regfinalroom) - - loc_win = DLCQuestLocation(player, "Winning Basic", None, world.get_region("The Final Boss Room", player)) - world.get_region("The Final Boss Room", player).locations.append(loc_win) - loc_win.place_locked_item(create_event(player, "Victory Basic")) - - world.get_entrance("DLC Quest Basic", player).connect(world.get_region("Move Right", player)) - - world.get_entrance("Moving", player).connect(world.get_region("Movement Pack", player)) - - world.get_entrance("Tree", player).connect(world.get_region("Behind Tree", player)) - - world.get_entrance("Cloud", player).connect(world.get_region("Psychological Warfare", player)) - - world.get_entrance("Cloud Double Jump", player).connect(world.get_region("Double Jump Total Left", player)) - - world.get_entrance("Cave Tree", player).connect(world.get_region("Double Jump Total Left Cave", player)) - - world.get_entrance("Cave Roof", player).connect(world.get_region("Double Jump Total Left Roof", player)) - - world.get_entrance("Forest Entrance", player).connect(world.get_region("The Forest", player)) - - world.get_entrance("Behind Tree Double Jump", player).connect( - world.get_region("Double Jump Behind Tree", player)) - - world.get_entrance("Behind Ogre", player).connect(world.get_region("The Final Boss Room", player)) - - world.get_entrance("Forest Double Jump", player).connect( - world.get_region("The Forest whit double Jump", player)) - - world.get_entrance("Forest True Double Jump", player).connect( - world.get_region("The Forest whit double Jump Part 2", player)) - - world.get_entrance("True Double Jump", player).connect(world.get_region("True Double Jump Behind Tree", player)) - - if (World_Options.campaign == Options.Campaign.option_live_freemium_or_die or World_Options.campaign - == Options.Campaign.option_both): - - Regfreemiumstart = Region("Freemium Start", player, world) - Locfreemiumstart_name = ["Particles Pack", "Day One Patch Pack", "Checkpoint Pack", "Incredibly Important Pack", - "Nice Try", "Story is Important", "I Get That Reference!"] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Locfreemiumstart_name += ["Wooden Sword"] - Regfreemiumstart.exits = [Entrance(player, "Vines", Regfreemiumstart)] - Regfreemiumstart.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regfreemiumstart) - for loc_name in - Locfreemiumstart_name] - add_coin_freemium(Regfreemiumstart, 50, player) - if World_Options.coinsanity == Options.CoinSanity.option_coin: - coin_bundle_needed = math.floor(889 / World_Options.coinbundlequantity) - for i in range(coin_bundle_needed): - item_coin_freemium = f"Live Freemium or Die: {World_Options.coinbundlequantity * (i + 1)} Coin" - Regfreemiumstart.locations += [ - DLCQuestLocation(player, item_coin_freemium, location_table[item_coin_freemium], - Regfreemiumstart)] - if 889 % World_Options.coinbundlequantity != 0: - Regfreemiumstart.locations += [ - DLCQuestLocation(player, "Live Freemium or Die: 889 Coin", - location_table["Live Freemium or Die: 889 Coin"], - Regfreemiumstart)] - world.regions.append(Regfreemiumstart) - - Regbehindvine = Region("Behind the Vines", player, world) - Locbehindvine_name = ["Wall Jump Pack", "Health Bar Pack", "Parallax Pack"] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Locbehindvine_name += ["Pickaxe"] - Regbehindvine.exits = [Entrance(player, "Wall Jump Entrance", Regbehindvine)] - Regbehindvine.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regbehindvine) for - loc_name in Locbehindvine_name] - add_coin_freemium(Regbehindvine, 95, player) - world.regions.append(Regbehindvine) - - Regwalljump = Region("Wall Jump", player, world) - Locwalljump_name = ["Harmless Plants Pack", "Death of Comedy Pack", "Canadian Dialog Pack", "DLC NPC Pack"] - Regwalljump.exits = [Entrance(player, "Harmless Plants", Regwalljump), - Entrance(player, "Pickaxe Hard Cave", Regwalljump)] - Regwalljump.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regwalljump) for - loc_name in Locwalljump_name] - add_coin_freemium(Regwalljump, 150, player) - world.regions.append(Regwalljump) - - Regfakeending = Region("Fake Ending", player, world) - Locfakeending_name = ["Cut Content Pack", "Name Change Pack"] - Regfakeending.exits = [Entrance(player, "Name Change Entrance", Regfakeending), - Entrance(player, "Cut Content Entrance", Regfakeending)] - Regfakeending.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regfakeending) for - loc_name in Locfakeending_name] - world.regions.append(Regfakeending) - - Reghardcave = Region("Hard Cave", player, world) - add_coin_freemium(Reghardcave, 20, player) - Reghardcave.exits = [Entrance(player, "Hard Cave Wall Jump", Reghardcave)] - world.regions.append(Reghardcave) - - Reghardcavewalljump = Region("Hard Cave Wall Jump", player, world) - Lochardcavewalljump_name = ["Increased HP Pack"] - Reghardcavewalljump.locations += [ - DLCQuestLocation(player, loc_name, location_table[loc_name], Reghardcavewalljump) for - loc_name in Lochardcavewalljump_name] - add_coin_freemium(Reghardcavewalljump, 130, player) - world.regions.append(Reghardcavewalljump) - - Regcutcontent = Region("Cut Content", player, world) - Loccutcontent_name = [] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Loccutcontent_name += ["Humble Indie Bindle"] - Regcutcontent.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regcutcontent) for - loc_name in Loccutcontent_name] - add_coin_freemium(Regcutcontent, 200, player) - world.regions.append(Regcutcontent) - - Regnamechange = Region("Name Change", player, world) - Locnamechange_name = [] - if World_Options.item_shuffle == Options.ItemShuffle.option_shuffled: - Locnamechange_name += ["Box of Various Supplies"] - Regnamechange.exits = [Entrance(player, "Behind Rocks", Regnamechange)] - Regnamechange.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regnamechange) for - loc_name in Locnamechange_name] - world.regions.append(Regnamechange) - - Regtopright = Region("Top Right", player, world) - Loctopright_name = ["Season Pass", "High Definition Next Gen Pack"] - Regtopright.exits = [Entrance(player, "Blizzard", Regtopright)] - Regtopright.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regtopright) for - loc_name in Loctopright_name] - add_coin_freemium(Regtopright, 90, player) - world.regions.append(Regtopright) - - Regseason = Region("Season", player, world) - Locseason_name = ["Remove Ads Pack", "Not Exactly Noble"] - Regseason.exits = [Entrance(player, "Boss Door", Regseason)] - Regseason.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regseason) for - loc_name in Locseason_name] - add_coin_freemium(Regseason, 154, player) - world.regions.append(Regseason) - - Regfinalboss = Region("Final Boss", player, world) - Locfinalboss_name = ["Big Sword Pack", "Really Big Sword Pack", "Unfathomable Sword Pack"] - Regfinalboss.locations += [DLCQuestLocation(player, loc_name, location_table[loc_name], Regfinalboss) for - loc_name in Locfinalboss_name] - world.regions.append(Regfinalboss) - - loc_wining = DLCQuestLocation(player, "Winning Freemium", None, world.get_region("Final Boss", player)) - world.get_region("Final Boss", player).locations.append(loc_wining) - loc_wining.place_locked_item(create_event(player, "Victory Freemium")) - - world.get_entrance("Live Freemium or Die", player).connect(world.get_region("Freemium Start", player)) - - world.get_entrance("Vines", player).connect(world.get_region("Behind the Vines", player)) - - world.get_entrance("Wall Jump Entrance", player).connect(world.get_region("Wall Jump", player)) - - world.get_entrance("Harmless Plants", player).connect(world.get_region("Fake Ending", player)) - - world.get_entrance("Pickaxe Hard Cave", player).connect(world.get_region("Hard Cave", player)) - - world.get_entrance("Hard Cave Wall Jump", player).connect(world.get_region("Hard Cave Wall Jump", player)) - - world.get_entrance("Name Change Entrance", player).connect(world.get_region("Name Change", player)) - - world.get_entrance("Cut Content Entrance", player).connect(world.get_region("Cut Content", player)) - - world.get_entrance("Behind Rocks", player).connect(world.get_region("Top Right", player)) - - world.get_entrance("Blizzard", player).connect(world.get_region("Season", player)) - - world.get_entrance("Boss Door", player).connect(world.get_region("Final Boss", player)) +def create_regions(multiworld: MultiWorld, player: int, world_options: Options.DLCQuestOptions): + region_menu = Region("Menu", player, multiworld) + has_campaign_basic = world_options.campaign == Options.Campaign.option_basic or world_options.campaign == Options.Campaign.option_both + has_campaign_lfod = world_options.campaign == Options.Campaign.option_live_freemium_or_die or world_options.campaign == Options.Campaign.option_both + has_coinsanity = world_options.coinsanity == Options.CoinSanity.option_coin + coin_bundle_size = world_options.coinbundlequantity.value + has_item_shuffle = world_options.item_shuffle == Options.ItemShuffle.option_shuffled + + multiworld.regions.append(region_menu) + + create_regions_basic_campaign(has_campaign_basic, region_menu, has_item_shuffle, has_coinsanity, coin_bundle_size, player, multiworld) + + create_regions_lfod_campaign(coin_bundle_size, has_campaign_lfod, has_coinsanity, has_item_shuffle, multiworld, player, region_menu) + + +def create_regions_basic_campaign(has_campaign_basic: bool, region_menu: Region, has_item_shuffle: bool, has_coinsanity: bool, + coin_bundle_size: int, player: int, world: MultiWorld): + if not has_campaign_basic: + return + + region_menu.exits += [Entrance(player, "DLC Quest Basic", region_menu)] + locations_move_right = ["Movement Pack", "Animation Pack", "Audio Pack", "Pause Menu Pack"] + region_move_right = create_region_and_locations_basic("Move Right", locations_move_right, ["Moving"], player, world, 4) + create_coinsanity_locations_dlc_quest(has_coinsanity, coin_bundle_size, player, region_move_right) + locations_movement_pack = ["Time is Money Pack", "Psychological Warfare Pack", "Armor for your Horse Pack", "Shepherd Sheep"] + locations_movement_pack += conditional_location(has_item_shuffle, "Sword") + create_region_and_locations_basic("Movement Pack", locations_movement_pack, ["Tree", "Cloud"], player, world, 46) + locations_behind_tree = ["Double Jump Pack", "Map Pack", "Between Trees Sheep", "Hole in the Wall Sheep"] + conditional_location(has_item_shuffle, "Gun") + create_region_and_locations_basic("Behind Tree", locations_behind_tree, ["Behind Tree Double Jump", "Forest Entrance"], player, world, 60) + create_region_and_locations_basic("Psychological Warfare", ["West Cave Sheep"], ["Cloud Double Jump"], player, world, 100) + locations_double_jump_left = ["Pet Pack", "Top Hat Pack", "North West Alcove Sheep"] + create_region_and_locations_basic("Double Jump Total Left", locations_double_jump_left, ["Cave Tree", "Cave Roof"], player, world, 50) + create_region_and_locations_basic("Double Jump Total Left Cave", ["Top Hat Sheep"], [], player, world, 9) + create_region_and_locations_basic("Double Jump Total Left Roof", ["North West Ceiling Sheep"], [], player, world, 10) + locations_double_jump_left_ceiling = ["Sexy Outfits Pack", "Double Jump Alcove Sheep", "Sexy Outfits Sheep"] + create_region_and_locations_basic("Double Jump Behind Tree", locations_double_jump_left_ceiling, ["True Double Jump"], player, world, 89) + create_region_and_locations_basic("True Double Jump Behind Tree", ["Double Jump Floating Sheep", "Cutscene Sheep"], [], player, world, 7) + create_region_and_locations_basic("The Forest", ["Gun Pack", "Night Map Pack"], ["Behind Ogre", "Forest Double Jump"], player, world, 171) + create_region_and_locations_basic("The Forest with double Jump", ["The Zombie Pack", "Forest Low Sheep"], ["Forest True Double Jump"], player, world, 76) + create_region_and_locations_basic("The Forest with double Jump Part 2", ["Forest High Sheep"], [], player, world, 203) + region_final_boss_room = create_region_and_locations_basic("The Final Boss Room", ["Finish the Fight Pack"], [], player, world) + + create_victory_event(region_final_boss_room, "Winning Basic", "Victory Basic", player) + + connect_entrances_basic(player, world) + + +def create_regions_lfod_campaign(coin_bundle_size, has_campaign_lfod, has_coinsanity, has_item_shuffle, multiworld, player, region_menu): + if not has_campaign_lfod: + return + + region_menu.exits += [Entrance(player, "Live Freemium or Die", region_menu)] + locations_lfod_start = ["Particles Pack", "Day One Patch Pack", "Checkpoint Pack", "Incredibly Important Pack", + "Nice Try", "Story is Important", "I Get That Reference!"] + conditional_location(has_item_shuffle, "Wooden Sword") + region_lfod_start = create_region_and_locations_lfod("Freemium Start", locations_lfod_start, ["Vines"], player, multiworld, 50) + create_coinsanity_locations_lfod(has_coinsanity, coin_bundle_size, player, region_lfod_start) + locations_behind_vines = ["Wall Jump Pack", "Health Bar Pack", "Parallax Pack"] + conditional_location(has_item_shuffle, "Pickaxe") + create_region_and_locations_lfod("Behind the Vines", locations_behind_vines, ["Wall Jump Entrance"], player, multiworld, 95) + locations_wall_jump = ["Harmless Plants Pack", "Death of Comedy Pack", "Canadian Dialog Pack", "DLC NPC Pack"] + create_region_and_locations_lfod("Wall Jump", locations_wall_jump, ["Harmless Plants", "Pickaxe Hard Cave"], player, multiworld, 150) + create_region_and_locations_lfod("Fake Ending", ["Cut Content Pack", "Name Change Pack"], ["Name Change Entrance", "Cut Content Entrance"], player, + multiworld) + create_region_and_locations_lfod("Hard Cave", [], ["Hard Cave Wall Jump"], player, multiworld, 20) + create_region_and_locations_lfod("Hard Cave Wall Jump", ["Increased HP Pack"], [], player, multiworld, 130) + create_region_and_locations_lfod("Cut Content", conditional_location(has_item_shuffle, "Humble Indie Bindle"), [], player, multiworld, 200) + create_region_and_locations_lfod("Name Change", conditional_location(has_item_shuffle, "Box of Various Supplies"), ["Behind Rocks"], player, multiworld) + create_region_and_locations_lfod("Top Right", ["Season Pass", "High Definition Next Gen Pack"], ["Blizzard"], player, multiworld, 90) + create_region_and_locations_lfod("Season", ["Remove Ads Pack", "Not Exactly Noble"], ["Boss Door"], player, multiworld, 154) + region_final_boss = create_region_and_locations_lfod("Final Boss", ["Big Sword Pack", "Really Big Sword Pack", "Unfathomable Sword Pack"], [], player, multiworld) + + create_victory_event(region_final_boss, "Winning Freemium", "Victory Freemium", player) + + connect_entrances_lfod(multiworld, player) + + +def conditional_location(condition: bool, location: str) -> List[str]: + return conditional_locations(condition, [location]) + + +def conditional_locations(condition: bool, locations: List[str]) -> List[str]: + return locations if condition else [] + + +def create_region_and_locations_basic(region_name: str, locations: List[str], exits: List[str], player: int, multiworld: MultiWorld, + number_coins: int = 0) -> Region: + return create_region_and_locations(region_name, locations, exits, player, multiworld, number_coins, 0) + + +def create_region_and_locations_lfod(region_name: str, locations: List[str], exits: List[str], player: int, multiworld: MultiWorld, + number_coins: int = 0) -> Region: + return create_region_and_locations(region_name, locations, exits, player, multiworld, 0, number_coins) + + +def create_region_and_locations(region_name: str, locations: List[str], exits: List[str], player: int, multiworld: MultiWorld, + number_coins_basic: int, number_coins_lfod: int) -> Region: + region = Region(region_name, player, multiworld) + region.exits = [Entrance(player, exit_name, region) for exit_name in exits] + region.locations += [DLCQuestLocation(player, name, location_table[name], region) for name in locations] + if number_coins_basic > 0: + add_coin_dlcquest(region, number_coins_basic, player) + if number_coins_lfod > 0: + add_coin_lfod(region, number_coins_lfod, player) + multiworld.regions.append(region) + return region + + +def create_victory_event(region_victory: Region, event_name: str, item_name: str, player: int): + location_victory = DLCQuestLocation(player, event_name, None, region_victory) + region_victory.locations.append(location_victory) + location_victory.place_locked_item(create_event(player, item_name)) + + +def connect_entrances_basic(player, world): + world.get_entrance("DLC Quest Basic", player).connect(world.get_region("Move Right", player)) + world.get_entrance("Moving", player).connect(world.get_region("Movement Pack", player)) + world.get_entrance("Tree", player).connect(world.get_region("Behind Tree", player)) + world.get_entrance("Cloud", player).connect(world.get_region("Psychological Warfare", player)) + world.get_entrance("Cloud Double Jump", player).connect(world.get_region("Double Jump Total Left", player)) + world.get_entrance("Cave Tree", player).connect(world.get_region("Double Jump Total Left Cave", player)) + world.get_entrance("Cave Roof", player).connect(world.get_region("Double Jump Total Left Roof", player)) + world.get_entrance("Forest Entrance", player).connect(world.get_region("The Forest", player)) + world.get_entrance("Behind Tree Double Jump", player).connect(world.get_region("Double Jump Behind Tree", player)) + world.get_entrance("Behind Ogre", player).connect(world.get_region("The Final Boss Room", player)) + world.get_entrance("Forest Double Jump", player).connect(world.get_region("The Forest with double Jump", player)) + world.get_entrance("Forest True Double Jump", player).connect(world.get_region("The Forest with double Jump Part 2", player)) + world.get_entrance("True Double Jump", player).connect(world.get_region("True Double Jump Behind Tree", player)) + + +def connect_entrances_lfod(multiworld, player): + multiworld.get_entrance("Live Freemium or Die", player).connect(multiworld.get_region("Freemium Start", player)) + multiworld.get_entrance("Vines", player).connect(multiworld.get_region("Behind the Vines", player)) + multiworld.get_entrance("Wall Jump Entrance", player).connect(multiworld.get_region("Wall Jump", player)) + multiworld.get_entrance("Harmless Plants", player).connect(multiworld.get_region("Fake Ending", player)) + multiworld.get_entrance("Pickaxe Hard Cave", player).connect(multiworld.get_region("Hard Cave", player)) + multiworld.get_entrance("Hard Cave Wall Jump", player).connect(multiworld.get_region("Hard Cave Wall Jump", player)) + multiworld.get_entrance("Name Change Entrance", player).connect(multiworld.get_region("Name Change", player)) + multiworld.get_entrance("Cut Content Entrance", player).connect(multiworld.get_region("Cut Content", player)) + multiworld.get_entrance("Behind Rocks", player).connect(multiworld.get_region("Top Right", player)) + multiworld.get_entrance("Blizzard", player).connect(multiworld.get_region("Season", player)) + multiworld.get_entrance("Boss Door", player).connect(multiworld.get_region("Final Boss", player)) + + +def create_coinsanity_locations_dlc_quest(has_coinsanity: bool, coin_bundle_size: int, player: int, region_move_right: Region): + create_coinsanity_locations(has_coinsanity, coin_bundle_size, player, region_move_right, 825, "DLC Quest") + + +def create_coinsanity_locations_lfod(has_coinsanity: bool, coin_bundle_size: int, player: int, region_lfod_start: Region): + create_coinsanity_locations(has_coinsanity, coin_bundle_size, player, region_lfod_start, 889, "Live Freemium or Die") + + +def create_coinsanity_locations(has_coinsanity: bool, coin_bundle_size: int, player: int, region: Region, last_coin_number: int, campaign_prefix: str): + if not has_coinsanity: + return + + coin_bundle_needed = math.ceil(last_coin_number / coin_bundle_size) + for i in range(1, coin_bundle_needed + 1): + number_coins = min(last_coin_number, coin_bundle_size * i) + item_coin = f"{campaign_prefix}: {number_coins} Coin" + region.locations += [DLCQuestLocation(player, item_coin, location_table[item_coin], region)] diff --git a/worlds/dlcquest/test/TestItemShuffle.py b/worlds/dlcquest/test/TestItemShuffle.py new file mode 100644 index 000000000000..bfe999246a50 --- /dev/null +++ b/worlds/dlcquest/test/TestItemShuffle.py @@ -0,0 +1,130 @@ +from . import DLCQuestTestBase +from .. import Options + +sword = "Sword" +gun = "Gun" +wooden_sword = "Wooden Sword" +pickaxe = "Pickaxe" +humble_bindle = "Humble Indie Bindle" +box_supplies = "Box of Various Supplies" +items = [sword, gun, wooden_sword, pickaxe, humble_bindle, box_supplies] + +important_pack = "Incredibly Important Pack" + + +class TestItemShuffle(DLCQuestTestBase): + options = {Options.ItemShuffle.internal_name: Options.ItemShuffle.option_shuffled, + Options.Campaign.internal_name: Options.Campaign.option_both} + + def test_items_in_pool(self): + item_names = {item.name for item in self.multiworld.get_items()} + for item in items: + with self.subTest(f"{item}"): + self.assertIn(item, item_names) + + def test_item_locations_in_pool(self): + location_names = {location.name for location in self.multiworld.get_locations()} + for item_location in items: + with self.subTest(f"{item_location}"): + self.assertIn(item_location, location_names) + + def test_sword_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(sword)) + movement_pack = self.multiworld.create_item("Movement Pack", self.player) + self.collect(movement_pack) + self.assertFalse(self.can_reach_location(sword)) + time_pack = self.multiworld.create_item("Time is Money Pack", self.player) + self.collect(time_pack) + self.assertTrue(self.can_reach_location(sword)) + + def test_gun_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(gun)) + movement_pack = self.multiworld.create_item("Movement Pack", self.player) + self.collect(movement_pack) + self.assertFalse(self.can_reach_location(gun)) + sword_item = self.multiworld.create_item(sword, self.player) + self.collect(sword_item) + self.assertFalse(self.can_reach_location(gun)) + gun_pack = self.multiworld.create_item("Gun Pack", self.player) + self.collect(gun_pack) + self.assertTrue(self.can_reach_location(gun)) + + def test_wooden_sword_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(wooden_sword)) + important_pack_item = self.multiworld.create_item(important_pack, self.player) + self.collect(important_pack_item) + self.assertTrue(self.can_reach_location(wooden_sword)) + + def test_bindle_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(humble_bindle)) + wooden_sword_item = self.multiworld.create_item(wooden_sword, self.player) + self.collect(wooden_sword_item) + self.assertFalse(self.can_reach_location(humble_bindle)) + plants_pack = self.multiworld.create_item("Harmless Plants Pack", self.player) + self.collect(plants_pack) + self.assertFalse(self.can_reach_location(humble_bindle)) + wall_jump_pack = self.multiworld.create_item("Wall Jump Pack", self.player) + self.collect(wall_jump_pack) + self.assertFalse(self.can_reach_location(humble_bindle)) + name_change_pack = self.multiworld.create_item("Name Change Pack", self.player) + self.collect(name_change_pack) + self.assertFalse(self.can_reach_location(humble_bindle)) + cut_content_pack = self.multiworld.create_item("Cut Content Pack", self.player) + self.collect(cut_content_pack) + self.assertFalse(self.can_reach_location(humble_bindle)) + box_supplies_item = self.multiworld.create_item(box_supplies, self.player) + self.collect(box_supplies_item) + self.assertTrue(self.can_reach_location(humble_bindle)) + + def test_box_supplies_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(box_supplies)) + wooden_sword_item = self.multiworld.create_item(wooden_sword, self.player) + self.collect(wooden_sword_item) + self.assertFalse(self.can_reach_location(box_supplies)) + plants_pack = self.multiworld.create_item("Harmless Plants Pack", self.player) + self.collect(plants_pack) + self.assertFalse(self.can_reach_location(box_supplies)) + wall_jump_pack = self.multiworld.create_item("Wall Jump Pack", self.player) + self.collect(wall_jump_pack) + self.assertFalse(self.can_reach_location(box_supplies)) + name_change_pack = self.multiworld.create_item("Name Change Pack", self.player) + self.collect(name_change_pack) + self.assertFalse(self.can_reach_location(box_supplies)) + cut_content_pack = self.multiworld.create_item("Cut Content Pack", self.player) + self.collect(cut_content_pack) + self.assertTrue(self.can_reach_location(box_supplies)) + + def test_pickaxe_location_has_correct_rules(self): + self.assertFalse(self.can_reach_location(pickaxe)) + wooden_sword_item = self.multiworld.create_item(wooden_sword, self.player) + self.collect(wooden_sword_item) + self.assertFalse(self.can_reach_location(pickaxe)) + plants_pack = self.multiworld.create_item("Harmless Plants Pack", self.player) + self.collect(plants_pack) + self.assertFalse(self.can_reach_location(pickaxe)) + wall_jump_pack = self.multiworld.create_item("Wall Jump Pack", self.player) + self.collect(wall_jump_pack) + self.assertFalse(self.can_reach_location(pickaxe)) + name_change_pack = self.multiworld.create_item("Name Change Pack", self.player) + self.collect(name_change_pack) + self.assertFalse(self.can_reach_location(pickaxe)) + bindle_item = self.multiworld.create_item("Humble Indie Bindle", self.player) + self.collect(bindle_item) + self.assertTrue(self.can_reach_location(pickaxe)) + + +class TestNoItemShuffle(DLCQuestTestBase): + options = {Options.ItemShuffle.internal_name: Options.ItemShuffle.option_disabled, + Options.Campaign.internal_name: Options.Campaign.option_both} + + def test_items_not_in_pool(self): + item_names = {item.name for item in self.multiworld.get_items()} + for item in items: + with self.subTest(f"{item}"): + self.assertNotIn(item, item_names) + + def test_item_locations_not_in_pool(self): + location_names = {location.name for location in self.multiworld.get_locations()} + for item_location in items: + with self.subTest(f"{item_location}"): + self.assertNotIn(item_location, location_names) \ No newline at end of file diff --git a/worlds/dlcquest/test/TestOptionsLong.py b/worlds/dlcquest/test/TestOptionsLong.py new file mode 100644 index 000000000000..d0a5c0ed7dfb --- /dev/null +++ b/worlds/dlcquest/test/TestOptionsLong.py @@ -0,0 +1,87 @@ +from typing import Dict + +from BaseClasses import MultiWorld +from Options import SpecialRange +from .option_names import options_to_include +from .checks.world_checks import assert_can_win, assert_same_number_items_locations +from . import DLCQuestTestBase, setup_dlc_quest_solo_multiworld +from ... import AutoWorldRegister + + +def basic_checks(tester: DLCQuestTestBase, multiworld: MultiWorld): + assert_can_win(tester, multiworld) + assert_same_number_items_locations(tester, multiworld) + + +def get_option_choices(option) -> Dict[str, int]: + if issubclass(option, SpecialRange): + return option.special_range_names + elif option.options: + return option.options + return {} + + +class TestGenerateDynamicOptions(DLCQuestTestBase): + def test_given_option_pair_when_generate_then_basic_checks(self): + num_options = len(options_to_include) + for option1_index in range(0, num_options): + for option2_index in range(option1_index + 1, num_options): + option1 = options_to_include[option1_index] + option2 = options_to_include[option2_index] + option1_choices = get_option_choices(option1) + option2_choices = get_option_choices(option2) + for key1 in option1_choices: + for key2 in option2_choices: + with self.subTest(f"{option1.internal_name}: {key1}, {option2.internal_name}: {key2}"): + choices = {option1.internal_name: option1_choices[key1], + option2.internal_name: option2_choices[key2]} + multiworld = setup_dlc_quest_solo_multiworld(choices) + basic_checks(self, multiworld) + + def test_given_option_truple_when_generate_then_basic_checks(self): + num_options = len(options_to_include) + for option1_index in range(0, num_options): + for option2_index in range(option1_index + 1, num_options): + for option3_index in range(option2_index + 1, num_options): + option1 = options_to_include[option1_index] + option2 = options_to_include[option2_index] + option3 = options_to_include[option3_index] + option1_choices = get_option_choices(option1) + option2_choices = get_option_choices(option2) + option3_choices = get_option_choices(option3) + for key1 in option1_choices: + for key2 in option2_choices: + for key3 in option3_choices: + with self.subTest(f"{option1.internal_name}: {key1}, {option2.internal_name}: {key2}, {option3.internal_name}: {key3}"): + choices = {option1.internal_name: option1_choices[key1], + option2.internal_name: option2_choices[key2], + option3.internal_name: option3_choices[key3]} + multiworld = setup_dlc_quest_solo_multiworld(choices) + basic_checks(self, multiworld) + + def test_given_option_quartet_when_generate_then_basic_checks(self): + num_options = len(options_to_include) + for option1_index in range(0, num_options): + for option2_index in range(option1_index + 1, num_options): + for option3_index in range(option2_index + 1, num_options): + for option4_index in range(option3_index + 1, num_options): + option1 = options_to_include[option1_index] + option2 = options_to_include[option2_index] + option3 = options_to_include[option3_index] + option4 = options_to_include[option4_index] + option1_choices = get_option_choices(option1) + option2_choices = get_option_choices(option2) + option3_choices = get_option_choices(option3) + option4_choices = get_option_choices(option4) + for key1 in option1_choices: + for key2 in option2_choices: + for key3 in option3_choices: + for key4 in option4_choices: + with self.subTest( + f"{option1.internal_name}: {key1}, {option2.internal_name}: {key2}, {option3.internal_name}: {key3}, {option4.internal_name}: {key4}"): + choices = {option1.internal_name: option1_choices[key1], + option2.internal_name: option2_choices[key2], + option3.internal_name: option3_choices[key3], + option4.internal_name: option4_choices[key4]} + multiworld = setup_dlc_quest_solo_multiworld(choices) + basic_checks(self, multiworld) diff --git a/worlds/dlcquest/test/__init__.py b/worlds/dlcquest/test/__init__.py new file mode 100644 index 000000000000..e998bd8a5e8b --- /dev/null +++ b/worlds/dlcquest/test/__init__.py @@ -0,0 +1,53 @@ +from typing import ClassVar + +from typing import Dict, FrozenSet, Tuple, Any +from argparse import Namespace + +from BaseClasses import MultiWorld +from test.TestBase import WorldTestBase +from .. import DLCqworld +from test.general import gen_steps, setup_solo_multiworld as setup_base_solo_multiworld +from worlds.AutoWorld import call_all + + +class DLCQuestTestBase(WorldTestBase): + game = "DLCQuest" + world: DLCqworld + player: ClassVar[int] = 1 + + def world_setup(self, *args, **kwargs): + super().world_setup(*args, **kwargs) + if self.constructed: + self.world = self.multiworld.worlds[self.player] # noqa + + @property + def run_default_tests(self) -> bool: + # world_setup is overridden, so it'd always run default tests when importing DLCQuestTestBase + is_not_dlc_test = type(self) is not DLCQuestTestBase + should_run_default_tests = is_not_dlc_test and super().run_default_tests + return should_run_default_tests + + +def setup_dlc_quest_solo_multiworld(test_options=None, seed=None, _cache: Dict[FrozenSet[Tuple[str, Any]], MultiWorld] = {}) -> MultiWorld: #noqa + if test_options is None: + test_options = {} + + # Yes I reuse the worlds generated between tests, its speeds the execution by a couple seconds + frozen_options = frozenset(test_options.items()).union({seed}) + if frozen_options in _cache: + return _cache[frozen_options] + + multiworld = setup_base_solo_multiworld(DLCqworld, ()) + multiworld.set_seed(seed) + # print(f"Seed: {multiworld.seed}") # Uncomment to print the seed for every test + args = Namespace() + for name, option in DLCqworld.options_dataclass.type_hints.items(): + value = option(test_options[name]) if name in test_options else option.from_any(option.default) + setattr(args, name, {1: value}) + multiworld.set_options(args) + for step in gen_steps: + call_all(multiworld, step) + + _cache[frozen_options] = multiworld + + return multiworld diff --git a/worlds/dlcquest/test/checks/__init__.py b/worlds/dlcquest/test/checks/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/worlds/dlcquest/test/checks/world_checks.py b/worlds/dlcquest/test/checks/world_checks.py new file mode 100644 index 000000000000..a97093d62036 --- /dev/null +++ b/worlds/dlcquest/test/checks/world_checks.py @@ -0,0 +1,42 @@ +from typing import List + +from BaseClasses import MultiWorld, ItemClassification +from .. import DLCQuestTestBase +from ... import Options + + +def get_all_item_names(multiworld: MultiWorld) -> List[str]: + return [item.name for item in multiworld.itempool] + + +def get_all_location_names(multiworld: MultiWorld) -> List[str]: + return [location.name for location in multiworld.get_locations() if not location.event] + + +def assert_victory_exists(tester: DLCQuestTestBase, multiworld: MultiWorld): + campaign = multiworld.campaign[1] + all_items = [item.name for item in multiworld.get_items()] + if campaign == Options.Campaign.option_basic or campaign == Options.Campaign.option_both: + tester.assertIn("Victory Basic", all_items) + if campaign == Options.Campaign.option_live_freemium_or_die or campaign == Options.Campaign.option_both: + tester.assertIn("Victory Freemium", all_items) + + +def collect_all_then_assert_can_win(tester: DLCQuestTestBase, multiworld: MultiWorld): + for item in multiworld.get_items(): + multiworld.state.collect(item) + campaign = multiworld.campaign[1] + if campaign == Options.Campaign.option_basic or campaign == Options.Campaign.option_both: + tester.assertTrue(multiworld.find_item("Victory Basic", 1).can_reach(multiworld.state)) + if campaign == Options.Campaign.option_live_freemium_or_die or campaign == Options.Campaign.option_both: + tester.assertTrue(multiworld.find_item("Victory Freemium", 1).can_reach(multiworld.state)) + + +def assert_can_win(tester: DLCQuestTestBase, multiworld: MultiWorld): + assert_victory_exists(tester, multiworld) + collect_all_then_assert_can_win(tester, multiworld) + + +def assert_same_number_items_locations(tester: DLCQuestTestBase, multiworld: MultiWorld): + non_event_locations = [location for location in multiworld.get_locations() if not location.event] + tester.assertEqual(len(multiworld.itempool), len(non_event_locations)) \ No newline at end of file diff --git a/worlds/dlcquest/test/option_names.py b/worlds/dlcquest/test/option_names.py new file mode 100644 index 000000000000..4a4b46e906cb --- /dev/null +++ b/worlds/dlcquest/test/option_names.py @@ -0,0 +1,5 @@ +from .. import DLCqworld + +options_to_exclude = ["progression_balancing", "accessibility", "start_inventory", "start_hints", "death_link"] +options_to_include = [option for option_name, option in DLCqworld.options_dataclass.type_hints.items() + if option_name not in options_to_exclude] From 7aab9d44394b005dc1c0ee6e83d25f4bc9326ecb Mon Sep 17 00:00:00 2001 From: Alchav <59858495+Alchav@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:55:03 -0400 Subject: [PATCH 05/24] =?UTF-8?q?Docs:=20Recommend=20Bizhawk=20Version=202?= =?UTF-8?q?.9.1=20for=20Pok=C3=A9mon=20R/B=20(#2320)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worlds/pokemon_rb/docs/setup_en.md | 6 +++--- worlds/pokemon_rb/docs/setup_es.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/worlds/pokemon_rb/docs/setup_en.md b/worlds/pokemon_rb/docs/setup_en.md index 488f3fdc0791..7ba9b3aa09e3 100644 --- a/worlds/pokemon_rb/docs/setup_en.md +++ b/worlds/pokemon_rb/docs/setup_en.md @@ -7,7 +7,7 @@ As we are using BizHawk, this guide is only applicable to Windows and Linux syst ## Required Software - BizHawk: [BizHawk Releases from TASVideos](https://tasvideos.org/BizHawk/ReleaseHistory) - - Version 2.3.1 and later are supported. Version 2.7 is recommended for stability. + - Version 2.3.1 and later are supported. Version 2.9.1 is recommended. - Detailed installation instructions for BizHawk can be found at the above link. - Windows users must run the prereq installer first, which can also be found at the above link. - The built-in Archipelago client, which can be installed [here](https://github.com/ArchipelagoMW/Archipelago/releases) @@ -23,7 +23,7 @@ As we are using BizHawk, this guide is only applicable to Windows and Linux syst Once BizHawk has been installed, open EmuHawk and change the following settings: -- (≤ 2.8) Go to Config > Customize. Switch to the Advanced tab, then switch the Lua Core from "NLua+KopiLua" to +- (If using 2.8 or earlier) Go to Config > Customize. Switch to the Advanced tab, then switch the Lua Core from "NLua+KopiLua" to "Lua+LuaInterface". Then restart EmuHawk. This is required for the Lua script to function correctly. **NOTE: Even if "Lua+LuaInterface" is already selected, toggle between the two options and reselect it. Fresh installs** **of newer versions of EmuHawk have a tendency to show "Lua+LuaInterface" as the default selected option but still load** @@ -57,7 +57,7 @@ For `trainer_name` and `rival_name` the following regular characters are allowed * `‘’“”·… ABCDEFGHIJKLMNOPQRSTUVWXYZ():;[]abcdefghijklmnopqrstuvwxyzé'-?!.♂$×/,♀0123456789` -And the following special characters (these each take up one character): +And the following special characters (these each count as one character): * `<'d>` * `<'l>` * `<'t>` diff --git a/worlds/pokemon_rb/docs/setup_es.md b/worlds/pokemon_rb/docs/setup_es.md index 2a943da72f59..a6a6aa6ce793 100644 --- a/worlds/pokemon_rb/docs/setup_es.md +++ b/worlds/pokemon_rb/docs/setup_es.md @@ -7,7 +7,7 @@ Al usar BizHawk, esta guía solo es aplicable en los sistemas de Windows y Linux ## Software Requerido - BizHawk: [BizHawk Releases en TASVideos](https://tasvideos.org/BizHawk/ReleaseHistory) - - La versión 2.3.1 y posteriores son soportadas. Se recomienda la versión 2.7 para estabilidad. + - La versión 2.3.1 y posteriores son soportadas. Se recomienda la versión 2.9.1. - Instrucciones de instalación detalladas para BizHawk se pueden encontrar en el enlace de arriba. - Los usuarios de Windows deben ejecutar el instalador de prerrequisitos (prereq installer) primero, que también se encuentra en el enlace de arriba. From 45e69f3d268a56badb3868e06e0ad303ef801740 Mon Sep 17 00:00:00 2001 From: Zach Parks Date: Wed, 18 Oct 2023 15:11:25 -0500 Subject: [PATCH 06/24] Docs: Triage role expectations documentation. (#2325) Co-authored-by: Scipio Wright --- docs/triage role expectations.md | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/triage role expectations.md diff --git a/docs/triage role expectations.md b/docs/triage role expectations.md new file mode 100644 index 000000000000..5b4cab227532 --- /dev/null +++ b/docs/triage role expectations.md @@ -0,0 +1,100 @@ +# Triage Role Expectations + +Users with Triage-level access are selected contributors who can and wish to proactively label/triage issues and pull +requests without being granted write access to the Archipelago repository. + +Triage users are not necessarily official members of the Archipelago organization, for the list of core maintainers, +please reference [ArchipelagoMW Members](https://github.com/orgs/ArchipelagoMW/people) page. + +## Access Permissions + +Triage users have the following permissions: + +* Apply/dismiss labels on all issues and pull requests. +* Close, reopen, and assign all issues and pull requests. +* Mark issues and pull requests as duplicate. +* Request pull request reviews from repository members. +* Hide comments in issues or pull requests from public view. + * Hidden comments are not deleted and can be reversed by another triage user or repository member with write access. +* And all other standard permissions granted to regular GitHub users. + +For more details on permissions granted by the Triage role, see +[GitHub's Role Documentation](https://docs.github.com/en/organizations/managing-user-access-to-your-organizations-repositories/managing-repository-roles/repository-roles-for-an-organization). + +## Expectations + +Users with triage-level permissions have no expectation to review code, but, if desired, to review pull requests/issues +and apply the relevant labels and ping/request reviews from any relevant [code owners](./CODEOWNERS) for review. Triage +users are also expected not to close others' issues or pull requests without strong reason to do so (with exception of +`meta: invalid` or `meta: duplicate` scenarios, which are listed below). When in doubt, defer to a core maintainer. + +Triage users are not "moderators" for others' issues or pull requests. However, they may voice their opinions/feedback +on issues or pull requests, just the same as any other GitHub user contributing to Archipelago. + +## Labeling + +As of the time of writing this document, there are 15 distinct labels that can be applied to issues and pull requests. + +### Affects + +These labels notate if certain issues or pull requests affect critical aspects of Archipelago that may require specific +review. More than one of these labels can be used on a issue or pull request, if relevant. + +* `affects: core` is to be applied to issues/PRs that may affect core Archipelago functionality and should be reviewed +with additional scrutiny. + * Core is defined as any files not contained in the `WebHostLib` directory or individual world implementations + directories inside the `worlds` directory, not including `worlds/generic`. +* `affects: webhost` is to be applied to issues/PRs that may affect the core WebHost portion of Archipelago. In +general, this is anything being modified inside the `WebHostLib` directory or `WebHost.py` file. +* `affects: release/blocker` is to be applied for any issues/PRs that may either negatively impact (issues) or propose +to resolve critical issues (pull requests) that affect the current or next official release of Archipelago and should be +given top priority for review. + +### Is + +These labels notate what kinds of changes are being made or proposed in issues or pull requests. More than one of these +labels can be used on a issue or pull request, if relevant, but at least one of these labels should be applied to every +pull request and issue. + +* `is: bug/fix` is to be applied to issues/PRs that report or resolve an issue in core, web, or individual world +implementations. +* `is: documentation` is to be applied to issues/PRs that relate to adding, updating, or removing documentation in +core, web, or individual world implementations without modifying actual code. +* `is: enhancement` is to be applied to issues/PRs that relate to adding, modifying, or removing functionality in +core, web, or individual world implementations. +* `is: refactor/cleanup` is to be applied to issues/PRs that relate to reorganizing existing code to improve +readability or performance without adding, modifying, or removing functionality or fixing known regressions. +* `is: maintenance` is to be applied to issues/PRs that don't modify logic, refactor existing code, change features. +This is typically reserved for pull requests that need to update dependencies or increment version numbers without +resolving existing issues. +* `is: new game` is to be applied to any pull requests that introduce a new game for the first time to the `worlds` +directory. + * Issues should not be opened and classified with `is: new game`, and instead should be directed to the + #future-game-design channel in Archipelago for opening suggestions. If they are opened, they should be labeled + with `meta: invalid` and closed. + * Pull requests for new games should only have this label, as enhancement, documentation, bug/fix, refactor, and + possibly maintenance is implied. + +### Meta + +These labels allow additional quick meta information for contributors or reviewers for issues and pull requests. They +have specific situations where they should be applied. + +* `meta: duplicate` is to be applied to any issues/PRs that are duplicate of another issue/PR that was already opened. + * These should be immediately closed after leaving a comment, directing to the original issue or pull request. +* `meta: invalid` is to be applied to any issues/PRs that do not relate to Archipelago or are inappropriate for +discussion on GitHub. + * These should be immediately closed afterwards. +* `meta: help wanted` is to be applied to any issues/PRs that require additional attention for whatever reason. + * These should include a comment describing what kind of help is requested when the label is added. + * Some common reasons include, but are not limited to: Breaking API changes that require developer input/testing or + pull requests with large line changes that need additional reviewers to be reviewed effectively. + * This label may require some programming experience and familiarity with Archipelago source to determine if + requesting additional attention for help is warranted. +* `meta: good first issue` is to be applied to any issues that may be a good starting ground for new contributors to try +and tackle. + * This label may require some programming experience and familiarity with Archipelago source to determine if an + issue is a "good first issue". +* `meta: wontfix` is to be applied for any issues/PRs that are opened that will not be actioned because it's out of +scope or determined to not be an issue. + * This should be reserved for use by a world's code owner(s) on their relevant world or by core maintainers. From e8a48da315c3e9e5c769e23cdb92b18394bf388c Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Wed, 18 Oct 2023 16:04:12 -0500 Subject: [PATCH 07/24] SM: fix missing option import (#2326) --- worlds/sm/__init__.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/worlds/sm/__init__.py b/worlds/sm/__init__.py index 9d6f28607ec1..f208e600b983 100644 --- a/worlds/sm/__init__.py +++ b/worlds/sm/__init__.py @@ -1,18 +1,17 @@ from __future__ import annotations -import logging +import base64 import copy -import os +import logging import threading -import base64 -import settings import typing from typing import Any, Dict, Iterable, List, Set, TextIO, TypedDict -from BaseClasses import Region, Entrance, Location, MultiWorld, Item, ItemClassification, CollectionState, Tutorial -from Fill import fill_restrictive -from worlds.AutoWorld import World, AutoLogicRegister, WebWorld -from worlds.generic.Rules import set_rule, add_rule, add_item_rule +import settings +from BaseClasses import CollectionState, Entrance, Item, ItemClassification, Location, MultiWorld, Region, Tutorial +from Options import Accessibility +from worlds.AutoWorld import AutoLogicRegister, WebWorld, World +from worlds.generic.Rules import add_rule, set_rule logger = logging.getLogger("Super Metroid") From 1c7c83c69e97a19064a3bf1978be882662e8aee1 Mon Sep 17 00:00:00 2001 From: PsyMarth Date: Wed, 18 Oct 2023 14:53:54 -0700 Subject: [PATCH 08/24] OoT: Update Utils.py (#2310) Removed optional maxsize parameter, setting it to the default of 128. --- worlds/oot/Utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/oot/Utils.py b/worlds/oot/Utils.py index c2444cd1fee9..9faffbdeddfc 100644 --- a/worlds/oot/Utils.py +++ b/worlds/oot/Utils.py @@ -11,7 +11,7 @@ def data_path(*args): return os.path.join(os.path.dirname(__file__), 'data', *args) -@lru_cache(maxsize=13) # Cache Overworld.json and the 12 dungeons +@lru_cache def read_json(file_path): json_string = "" with io.open(file_path, 'r') as file: From 38c9ee146d32e5930f1ac8fa2817616f51f01128 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 18 Oct 2023 15:26:52 -0700 Subject: [PATCH 09/24] WebHost: Refactor weighted-settings.js (#2318) * Refactor weighted-settings.js This moves most of the infrastructure into two classes: * WeightedSettings covers the settings page as a whole. It tracks the user's current settings in local storage as well as the game data from the server so they don't need to be manually passed around from function to function. * GameSettings covers the settings for a single game, and provides a view of the current settings and the game data just for that game. * Fix item count updating --- WebHostLib/static/assets/weighted-settings.js | 1998 +++++++++-------- 1 file changed, 1015 insertions(+), 983 deletions(-) diff --git a/WebHostLib/static/assets/weighted-settings.js b/WebHostLib/static/assets/weighted-settings.js index fb7d3a349b2d..2cd61d2e6e5b 100644 --- a/WebHostLib/static/assets/weighted-settings.js +++ b/WebHostLib/static/assets/weighted-settings.js @@ -1,14 +1,14 @@ window.addEventListener('load', () => { - fetchSettingData().then((results) => { + fetchSettingData().then((data) => { let settingHash = localStorage.getItem('weighted-settings-hash'); if (!settingHash) { // If no hash data has been set before, set it now - settingHash = md5(JSON.stringify(results)); + settingHash = md5(JSON.stringify(data)); localStorage.setItem('weighted-settings-hash', settingHash); localStorage.removeItem('weighted-settings'); } - if (settingHash !== md5(JSON.stringify(results))) { + if (settingHash !== md5(JSON.stringify(data))) { const userMessage = document.getElementById('user-message'); userMessage.innerText = "Your settings are out of date! Click here to update them! Be aware this will reset " + "them all to default."; @@ -17,23 +17,22 @@ window.addEventListener('load', () => { } // Page setup - createDefaultSettings(results); - buildUI(results); - updateVisibleGames(); + const settings = new WeightedSettings(data); + settings.buildUI(); + settings.updateVisibleGames(); adjustHeaderWidth(); // Event listeners - document.getElementById('export-settings').addEventListener('click', () => exportSettings()); - document.getElementById('generate-race').addEventListener('click', () => generateGame(true)); - document.getElementById('generate-game').addEventListener('click', () => generateGame()); + document.getElementById('export-settings').addEventListener('click', () => settings.export()); + document.getElementById('generate-race').addEventListener('click', () => settings.generateGame(true)); + document.getElementById('generate-game').addEventListener('click', () => settings.generateGame()); // Name input field - const weightedSettings = JSON.parse(localStorage.getItem('weighted-settings')); const nameInput = document.getElementById('player-name'); nameInput.setAttribute('data-type', 'data'); nameInput.setAttribute('data-setting', 'name'); - nameInput.addEventListener('keyup', updateBaseSetting); - nameInput.value = weightedSettings.name; + nameInput.addEventListener('keyup', (evt) => settings.updateBaseSetting(evt)); + nameInput.value = settings.current.name; }); }); @@ -50,48 +49,65 @@ const fetchSettingData = () => new Promise((resolve, reject) => { }); }); -const createDefaultSettings = (settingData) => { - if (!localStorage.getItem('weighted-settings')) { - const newSettings = {}; +/// The weighted settings across all games. +class WeightedSettings { + // The data from the server describing the types of settings available for + // each game, as a JSON-safe blob. + data; + + // The settings chosen by the user as they'd appear in the YAML file, stored + // to and retrieved from local storage. + current; + + // A record mapping game names to the associated GameSettings. + games; + + constructor(data) { + this.data = data; + this.current = JSON.parse(localStorage.getItem('weighted-settings')); + this.games = Object.keys(this.data.games).map((game) => new GameSettings(this, game)); + if (this.current) { return; } + + this.current = {}; // Transfer base options directly - for (let baseOption of Object.keys(settingData.baseOptions)){ - newSettings[baseOption] = settingData.baseOptions[baseOption]; + for (let baseOption of Object.keys(this.data.baseOptions)){ + this.current[baseOption] = this.data.baseOptions[baseOption]; } // Set options per game - for (let game of Object.keys(settingData.games)) { + for (let game of Object.keys(this.data.games)) { // Initialize game object - newSettings[game] = {}; + this.current[game] = {}; // Transfer game settings - for (let gameSetting of Object.keys(settingData.games[game].gameSettings)){ - newSettings[game][gameSetting] = {}; + for (let gameSetting of Object.keys(this.data.games[game].gameSettings)){ + this.current[game][gameSetting] = {}; - const setting = settingData.games[game].gameSettings[gameSetting]; + const setting = this.data.games[game].gameSettings[gameSetting]; switch(setting.type){ case 'select': setting.options.forEach((option) => { - newSettings[game][gameSetting][option.value] = + this.current[game][gameSetting][option.value] = (setting.hasOwnProperty('defaultValue') && setting.defaultValue === option.value) ? 25 : 0; }); break; case 'range': case 'special_range': - newSettings[game][gameSetting]['random'] = 0; - newSettings[game][gameSetting]['random-low'] = 0; - newSettings[game][gameSetting]['random-high'] = 0; + this.current[game][gameSetting]['random'] = 0; + this.current[game][gameSetting]['random-low'] = 0; + this.current[game][gameSetting]['random-high'] = 0; if (setting.hasOwnProperty('defaultValue')) { - newSettings[game][gameSetting][setting.defaultValue] = 25; + this.current[game][gameSetting][setting.defaultValue] = 25; } else { - newSettings[game][gameSetting][setting.min] = 25; + this.current[game][gameSetting][setting.min] = 25; } break; case 'items-list': case 'locations-list': case 'custom-list': - newSettings[game][gameSetting] = setting.defaultValue; + this.current[game][gameSetting] = setting.defaultValue; break; default: @@ -99,33 +115,301 @@ const createDefaultSettings = (settingData) => { } } - newSettings[game].start_inventory = {}; - newSettings[game].exclude_locations = []; - newSettings[game].priority_locations = []; - newSettings[game].local_items = []; - newSettings[game].non_local_items = []; - newSettings[game].start_hints = []; - newSettings[game].start_location_hints = []; + this.current[game].start_inventory = {}; + this.current[game].exclude_locations = []; + this.current[game].priority_locations = []; + this.current[game].local_items = []; + this.current[game].non_local_items = []; + this.current[game].start_hints = []; + this.current[game].start_location_hints = []; } - localStorage.setItem('weighted-settings', JSON.stringify(newSettings)); + this.save(); + } + + // Saves the current settings to local storage. + save() { + localStorage.setItem('weighted-settings', JSON.stringify(this.current)); + } + + buildUI() { + // Build the game-choice div + this.#buildGameChoice(); + + const gamesWrapper = document.getElementById('games-wrapper'); + this.games.forEach((game) => { + gamesWrapper.appendChild(game.buildUI()); + }); + } + + #buildGameChoice() { + const gameChoiceDiv = document.getElementById('game-choice'); + const h2 = document.createElement('h2'); + h2.innerText = 'Game Select'; + gameChoiceDiv.appendChild(h2); + + const gameSelectDescription = document.createElement('p'); + gameSelectDescription.classList.add('setting-description'); + gameSelectDescription.innerText = 'Choose which games you might be required to play.'; + gameChoiceDiv.appendChild(gameSelectDescription); + + const hintText = document.createElement('p'); + hintText.classList.add('hint-text'); + hintText.innerText = 'If a game\'s value is greater than zero, you can click it\'s name to jump ' + + 'to that section.' + gameChoiceDiv.appendChild(hintText); + + // Build the game choice table + const table = document.createElement('table'); + const tbody = document.createElement('tbody'); + + Object.keys(this.data.games).forEach((game) => { + const tr = document.createElement('tr'); + const tdLeft = document.createElement('td'); + tdLeft.classList.add('td-left'); + const span = document.createElement('span'); + span.innerText = game; + span.setAttribute('id', `${game}-game-option`) + tdLeft.appendChild(span); + tr.appendChild(tdLeft); + + const tdMiddle = document.createElement('td'); + tdMiddle.classList.add('td-middle'); + const range = document.createElement('input'); + range.setAttribute('type', 'range'); + range.setAttribute('min', 0); + range.setAttribute('max', 50); + range.setAttribute('data-type', 'weight'); + range.setAttribute('data-setting', 'game'); + range.setAttribute('data-option', game); + range.value = this.current.game[game]; + range.addEventListener('change', (evt) => { + this.updateBaseSetting(evt); + this.updateVisibleGames(); // Show or hide games based on the new settings + }); + tdMiddle.appendChild(range); + tr.appendChild(tdMiddle); + + const tdRight = document.createElement('td'); + tdRight.setAttribute('id', `game-${game}`) + tdRight.classList.add('td-right'); + tdRight.innerText = range.value; + tr.appendChild(tdRight); + tbody.appendChild(tr); + }); + + table.appendChild(tbody); + gameChoiceDiv.appendChild(table); + } + + // Verifies that `this.settings` meets all the requirements for world + // generation, normalizes it for serialization, and returns the result. + #validateSettings() { + const settings = structuredClone(this.current); + const userMessage = document.getElementById('user-message'); + let errorMessage = null; + + // User must choose a name for their file + if (!settings.name || settings.name.trim().length === 0 || settings.name.toLowerCase().trim() === 'player') { + userMessage.innerText = 'You forgot to set your player name at the top of the page!'; + userMessage.classList.add('visible'); + userMessage.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + return; + } + + // Clean up the settings output + Object.keys(settings.game).forEach((game) => { + // Remove any disabled games + if (settings.game[game] === 0) { + delete settings.game[game]; + delete settings[game]; + return; + } + + Object.keys(settings[game]).forEach((setting) => { + // Remove any disabled options + Object.keys(settings[game][setting]).forEach((option) => { + if (settings[game][setting][option] === 0) { + delete settings[game][setting][option]; + } + }); + + if ( + Object.keys(settings[game][setting]).length === 0 && + !Array.isArray(settings[game][setting]) && + setting !== 'start_inventory' + ) { + errorMessage = `${game} // ${setting} has no values above zero!`; + } + + // Remove weights from options with only one possibility + if ( + Object.keys(settings[game][setting]).length === 1 && + !Array.isArray(settings[game][setting]) && + setting !== 'start_inventory' + ) { + settings[game][setting] = Object.keys(settings[game][setting])[0]; + } + + // Remove empty arrays + else if ( + ['exclude_locations', 'priority_locations', 'local_items', + 'non_local_items', 'start_hints', 'start_location_hints'].includes(setting) && + settings[game][setting].length === 0 + ) { + delete settings[game][setting]; + } + + // Remove empty start inventory + else if ( + setting === 'start_inventory' && + Object.keys(settings[game]['start_inventory']).length === 0 + ) { + delete settings[game]['start_inventory']; + } + }); + }); + + if (Object.keys(settings.game).length === 0) { + errorMessage = 'You have not chosen a game to play!'; + } + + // Remove weights if there is only one game + else if (Object.keys(settings.game).length === 1) { + settings.game = Object.keys(settings.game)[0]; + } + + // If an error occurred, alert the user and do not export the file + if (errorMessage) { + userMessage.innerText = errorMessage; + userMessage.classList.add('visible'); + userMessage.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + return; + } + + // If no error occurred, hide the user message if it is visible + userMessage.classList.remove('visible'); + return settings; + } + + updateVisibleGames() { + Object.entries(this.current.game).forEach(([game, weight]) => { + const gameDiv = document.getElementById(`${game}-div`); + const gameOption = document.getElementById(`${game}-game-option`); + if (parseInt(weight, 10) > 0) { + gameDiv.classList.remove('invisible'); + gameOption.classList.add('jump-link'); + gameOption.addEventListener('click', () => { + const gameDiv = document.getElementById(`${game}-div`); + if (gameDiv.classList.contains('invisible')) { return; } + gameDiv.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + }); + } else { + gameDiv.classList.add('invisible'); + gameOption.classList.remove('jump-link'); + } + }); + } + + updateBaseSetting(event) { + const setting = event.target.getAttribute('data-setting'); + const option = event.target.getAttribute('data-option'); + const type = event.target.getAttribute('data-type'); + + switch(type){ + case 'weight': + this.current[setting][option] = isNaN(event.target.value) ? event.target.value : parseInt(event.target.value, 10); + document.getElementById(`${setting}-${option}`).innerText = event.target.value; + break; + case 'data': + this.current[setting] = isNaN(event.target.value) ? event.target.value : parseInt(event.target.value, 10); + break; + } + + this.save(); + } + + export() { + const settings = this.#validateSettings(); + if (!settings) { return; } + + const yamlText = jsyaml.safeDump(settings, { noCompatMode: true }).replaceAll(/'(\d+)':/g, (x, y) => `${y}:`); + download(`${document.getElementById('player-name').value}.yaml`, yamlText); + } + + generateGame(raceMode = false) { + const settings = this.#validateSettings(); + if (!settings) { return; } + + axios.post('/api/generate', { + weights: { player: JSON.stringify(settings) }, + presetData: { player: JSON.stringify(settings) }, + playerCount: 1, + spoiler: 3, + race: raceMode ? '1' : '0', + }).then((response) => { + window.location.href = response.data.url; + }).catch((error) => { + const userMessage = document.getElementById('user-message'); + userMessage.innerText = 'Something went wrong and your game could not be generated.'; + if (error.response.data.text) { + userMessage.innerText += ' ' + error.response.data.text; + } + userMessage.classList.add('visible'); + userMessage.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + console.error(error); + }); + } +} + +// Settings for an individual game. +class GameSettings { + // The WeightedSettings that contains this game's settings. Used to save + // settings after editing. + #allSettings; + + // The name of this game. + name; + + // The data from the server describing the types of settings available for + // this game, as a JSON-safe blob. + get data() { + return this.#allSettings.data.games[this.name]; } -}; -const buildUI = (settingData) => { - // Build the game-choice div - buildGameChoice(settingData.games); + // The settings chosen by the user as they'd appear in the YAML file, stored + // to and retrieved from local storage. + get current() { + return this.#allSettings.current[this.name]; + } - const gamesWrapper = document.getElementById('games-wrapper'); - Object.keys(settingData.games).forEach((game) => { + constructor(allSettings, name) { + this.#allSettings = allSettings; + this.name = name; + } + + // Builds and returns the settings UI for this game. + buildUI() { // Create game div, invisible by default const gameDiv = document.createElement('div'); - gameDiv.setAttribute('id', `${game}-div`); + gameDiv.setAttribute('id', `${this.name}-div`); gameDiv.classList.add('game-div'); gameDiv.classList.add('invisible'); const gameHeader = document.createElement('h2'); - gameHeader.innerText = game; + gameHeader.innerText = this.name; gameDiv.appendChild(gameHeader); const collapseButton = document.createElement('a'); @@ -137,24 +421,22 @@ const buildUI = (settingData) => { expandButton.classList.add('invisible'); gameDiv.appendChild(expandButton); - settingData.games[game].gameItems.sort((a, b) => (a > b ? 1 : (a < b ? -1 : 0))); - settingData.games[game].gameLocations.sort((a, b) => (a > b ? 1 : (a < b ? -1 : 0))); + // Sort items and locations alphabetically. + this.data.gameItems.sort(); + this.data.gameLocations.sort(); - const weightedSettingsDiv = buildWeightedSettingsDiv(game, settingData.games[game].gameSettings, - settingData.games[game].gameItems, settingData.games[game].gameLocations); + const weightedSettingsDiv = this.#buildWeightedSettingsDiv(); gameDiv.appendChild(weightedSettingsDiv); - const itemPoolDiv = buildItemsDiv(game, settingData.games[game].gameItems); + const itemPoolDiv = this.#buildItemsDiv(); gameDiv.appendChild(itemPoolDiv); - const hintsDiv = buildHintsDiv(game, settingData.games[game].gameItems, settingData.games[game].gameLocations); + const hintsDiv = this.#buildHintsDiv(); gameDiv.appendChild(hintsDiv); - const locationsDiv = buildLocationsDiv(game, settingData.games[game].gameLocations); + const locationsDiv = this.#buildLocationsDiv(); gameDiv.appendChild(locationsDiv); - gamesWrapper.appendChild(gameDiv); - collapseButton.addEventListener('click', () => { collapseButton.classList.add('invisible'); weightedSettingsDiv.classList.add('invisible'); @@ -172,257 +454,145 @@ const buildUI = (settingData) => { locationsDiv.classList.remove('invisible'); expandButton.classList.add('invisible'); }); - }); -}; -const buildGameChoice = (games) => { - const settings = JSON.parse(localStorage.getItem('weighted-settings')); - const gameChoiceDiv = document.getElementById('game-choice'); - const h2 = document.createElement('h2'); - h2.innerText = 'Game Select'; - gameChoiceDiv.appendChild(h2); - - const gameSelectDescription = document.createElement('p'); - gameSelectDescription.classList.add('setting-description'); - gameSelectDescription.innerText = 'Choose which games you might be required to play.'; - gameChoiceDiv.appendChild(gameSelectDescription); - - const hintText = document.createElement('p'); - hintText.classList.add('hint-text'); - hintText.innerText = 'If a game\'s value is greater than zero, you can click it\'s name to jump ' + - 'to that section.' - gameChoiceDiv.appendChild(hintText); - - // Build the game choice table - const table = document.createElement('table'); - const tbody = document.createElement('tbody'); - - Object.keys(games).forEach((game) => { - const tr = document.createElement('tr'); - const tdLeft = document.createElement('td'); - tdLeft.classList.add('td-left'); - const span = document.createElement('span'); - span.innerText = game; - span.setAttribute('id', `${game}-game-option`) - tdLeft.appendChild(span); - tr.appendChild(tdLeft); - - const tdMiddle = document.createElement('td'); - tdMiddle.classList.add('td-middle'); - const range = document.createElement('input'); - range.setAttribute('type', 'range'); - range.setAttribute('min', 0); - range.setAttribute('max', 50); - range.setAttribute('data-type', 'weight'); - range.setAttribute('data-setting', 'game'); - range.setAttribute('data-option', game); - range.value = settings.game[game]; - range.addEventListener('change', (evt) => { - updateBaseSetting(evt); - updateVisibleGames(); // Show or hide games based on the new settings - }); - tdMiddle.appendChild(range); - tr.appendChild(tdMiddle); - - const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `game-${game}`) - tdRight.classList.add('td-right'); - tdRight.innerText = range.value; - tr.appendChild(tdRight); - tbody.appendChild(tr); - }); + return gameDiv; + } - table.appendChild(tbody); - gameChoiceDiv.appendChild(table); -}; + #buildWeightedSettingsDiv() { + const settingsWrapper = document.createElement('div'); + settingsWrapper.classList.add('settings-wrapper'); -const buildWeightedSettingsDiv = (game, settings, gameItems, gameLocations) => { - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - const settingsWrapper = document.createElement('div'); - settingsWrapper.classList.add('settings-wrapper'); - - Object.keys(settings).forEach((settingName) => { - const setting = settings[settingName]; - const settingWrapper = document.createElement('div'); - settingWrapper.classList.add('setting-wrapper'); - - const settingNameHeader = document.createElement('h4'); - settingNameHeader.innerText = setting.displayName; - settingWrapper.appendChild(settingNameHeader); - - const settingDescription = document.createElement('p'); - settingDescription.classList.add('setting-description'); - settingDescription.innerText = setting.description.replace(/(\n)/g, ' '); - settingWrapper.appendChild(settingDescription); - - switch(setting.type){ - case 'select': - const optionTable = document.createElement('table'); - const tbody = document.createElement('tbody'); - - // Add a weight range for each option - setting.options.forEach((option) => { - const tr = document.createElement('tr'); - const tdLeft = document.createElement('td'); - tdLeft.classList.add('td-left'); - tdLeft.innerText = option.name; - tr.appendChild(tdLeft); - - const tdMiddle = document.createElement('td'); - tdMiddle.classList.add('td-middle'); - const range = document.createElement('input'); - range.setAttribute('type', 'range'); - range.setAttribute('data-game', game); - range.setAttribute('data-setting', settingName); - range.setAttribute('data-option', option.value); - range.setAttribute('data-type', setting.type); - range.setAttribute('min', 0); - range.setAttribute('max', 50); - range.addEventListener('change', updateRangeSetting); - range.value = currentSettings[game][settingName][option.value]; - tdMiddle.appendChild(range); - tr.appendChild(tdMiddle); - - const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `${game}-${settingName}-${option.value}`) - tdRight.classList.add('td-right'); - tdRight.innerText = range.value; - tr.appendChild(tdRight); - - tbody.appendChild(tr); - }); + Object.keys(this.data.gameSettings).forEach((settingName) => { + const setting = this.data.gameSettings[settingName]; + const settingWrapper = document.createElement('div'); + settingWrapper.classList.add('setting-wrapper'); - optionTable.appendChild(tbody); - settingWrapper.appendChild(optionTable); - break; + const settingNameHeader = document.createElement('h4'); + settingNameHeader.innerText = setting.displayName; + settingWrapper.appendChild(settingNameHeader); - case 'range': - case 'special_range': - const rangeTable = document.createElement('table'); - const rangeTbody = document.createElement('tbody'); + const settingDescription = document.createElement('p'); + settingDescription.classList.add('setting-description'); + settingDescription.innerText = setting.description.replace(/(\n)/g, ' '); + settingWrapper.appendChild(settingDescription); - if (((setting.max - setting.min) + 1) < 11) { - for (let i=setting.min; i <= setting.max; ++i) { + switch(setting.type){ + case 'select': + const optionTable = document.createElement('table'); + const tbody = document.createElement('tbody'); + + // Add a weight range for each option + setting.options.forEach((option) => { const tr = document.createElement('tr'); const tdLeft = document.createElement('td'); tdLeft.classList.add('td-left'); - tdLeft.innerText = i; + tdLeft.innerText = option.name; tr.appendChild(tdLeft); const tdMiddle = document.createElement('td'); tdMiddle.classList.add('td-middle'); const range = document.createElement('input'); range.setAttribute('type', 'range'); - range.setAttribute('id', `${game}-${settingName}-${i}-range`); - range.setAttribute('data-game', game); + range.setAttribute('data-game', this.name); range.setAttribute('data-setting', settingName); - range.setAttribute('data-option', i); + range.setAttribute('data-option', option.value); + range.setAttribute('data-type', setting.type); range.setAttribute('min', 0); range.setAttribute('max', 50); - range.addEventListener('change', updateRangeSetting); - range.value = currentSettings[game][settingName][i] || 0; + range.addEventListener('change', (evt) => this.#updateRangeSetting(evt)); + range.value = this.current[settingName][option.value]; tdMiddle.appendChild(range); tr.appendChild(tdMiddle); const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `${game}-${settingName}-${i}`) + tdRight.setAttribute('id', `${this.name}-${settingName}-${option.value}`); tdRight.classList.add('td-right'); tdRight.innerText = range.value; tr.appendChild(tdRight); - rangeTbody.appendChild(tr); - } - } else { - const hintText = document.createElement('p'); - hintText.classList.add('hint-text'); - hintText.innerHTML = 'This is a range option. You may enter a valid numerical value in the text box ' + - `below, then press the "Add" button to add a weight for it.
Minimum value: ${setting.min}
` + - `Maximum value: ${setting.max}`; - - if (setting.hasOwnProperty('value_names')) { - hintText.innerHTML += '

Certain values have special meaning:'; - Object.keys(setting.value_names).forEach((specialName) => { - hintText.innerHTML += `
${specialName}: ${setting.value_names[specialName]}`; - }); - } - - settingWrapper.appendChild(hintText); - - const addOptionDiv = document.createElement('div'); - addOptionDiv.classList.add('add-option-div'); - const optionInput = document.createElement('input'); - optionInput.setAttribute('id', `${game}-${settingName}-option`); - optionInput.setAttribute('placeholder', `${setting.min} - ${setting.max}`); - addOptionDiv.appendChild(optionInput); - const addOptionButton = document.createElement('button'); - addOptionButton.innerText = 'Add'; - addOptionDiv.appendChild(addOptionButton); - settingWrapper.appendChild(addOptionDiv); - optionInput.addEventListener('keydown', (evt) => { - if (evt.key === 'Enter') { addOptionButton.dispatchEvent(new Event('click')); } + tbody.appendChild(tr); }); - addOptionButton.addEventListener('click', () => { - const optionInput = document.getElementById(`${game}-${settingName}-option`); - let option = optionInput.value; - if (!option || !option.trim()) { return; } - option = parseInt(option, 10); - if ((option < setting.min) || (option > setting.max)) { return; } - optionInput.value = ''; - if (document.getElementById(`${game}-${settingName}-${option}-range`)) { return; } + optionTable.appendChild(tbody); + settingWrapper.appendChild(optionTable); + break; - const tr = document.createElement('tr'); - const tdLeft = document.createElement('td'); - tdLeft.classList.add('td-left'); - tdLeft.innerText = option; - tr.appendChild(tdLeft); + case 'range': + case 'special_range': + const rangeTable = document.createElement('table'); + const rangeTbody = document.createElement('tbody'); - const tdMiddle = document.createElement('td'); - tdMiddle.classList.add('td-middle'); - const range = document.createElement('input'); - range.setAttribute('type', 'range'); - range.setAttribute('id', `${game}-${settingName}-${option}-range`); - range.setAttribute('data-game', game); - range.setAttribute('data-setting', settingName); - range.setAttribute('data-option', option); - range.setAttribute('min', 0); - range.setAttribute('max', 50); - range.addEventListener('change', updateRangeSetting); - range.value = currentSettings[game][settingName][parseInt(option, 10)]; - tdMiddle.appendChild(range); - tr.appendChild(tdMiddle); + if (((setting.max - setting.min) + 1) < 11) { + for (let i=setting.min; i <= setting.max; ++i) { + const tr = document.createElement('tr'); + const tdLeft = document.createElement('td'); + tdLeft.classList.add('td-left'); + tdLeft.innerText = i; + tr.appendChild(tdLeft); - const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `${game}-${settingName}-${option}`) - tdRight.classList.add('td-right'); - tdRight.innerText = range.value; - tr.appendChild(tdRight); + const tdMiddle = document.createElement('td'); + tdMiddle.classList.add('td-middle'); + const range = document.createElement('input'); + range.setAttribute('type', 'range'); + range.setAttribute('id', `${this.name}-${settingName}-${i}-range`); + range.setAttribute('data-game', this.name); + range.setAttribute('data-setting', settingName); + range.setAttribute('data-option', i); + range.setAttribute('min', 0); + range.setAttribute('max', 50); + range.addEventListener('change', (evt) => this.#updateRangeSetting(evt)); + range.value = this.current[settingName][i] || 0; + tdMiddle.appendChild(range); + tr.appendChild(tdMiddle); - const tdDelete = document.createElement('td'); - tdDelete.classList.add('td-delete'); - const deleteButton = document.createElement('span'); - deleteButton.classList.add('range-option-delete'); - deleteButton.innerText = '❌'; - deleteButton.addEventListener('click', () => { - range.value = 0; - range.dispatchEvent(new Event('change')); - rangeTbody.removeChild(tr); - }); - tdDelete.appendChild(deleteButton); - tr.appendChild(tdDelete); + const tdRight = document.createElement('td'); + tdRight.setAttribute('id', `${this.name}-${settingName}-${i}`) + tdRight.classList.add('td-right'); + tdRight.innerText = range.value; + tr.appendChild(tdRight); - rangeTbody.appendChild(tr); + rangeTbody.appendChild(tr); + } + } else { + const hintText = document.createElement('p'); + hintText.classList.add('hint-text'); + hintText.innerHTML = 'This is a range option. You may enter a valid numerical value in the text box ' + + `below, then press the "Add" button to add a weight for it.
Minimum value: ${setting.min}
` + + `Maximum value: ${setting.max}`; + + if (setting.hasOwnProperty('value_names')) { + hintText.innerHTML += '

Certain values have special meaning:'; + Object.keys(setting.value_names).forEach((specialName) => { + hintText.innerHTML += `
${specialName}: ${setting.value_names[specialName]}`; + }); + } - // Save new option to settings - range.dispatchEvent(new Event('change')); - }); + settingWrapper.appendChild(hintText); + + const addOptionDiv = document.createElement('div'); + addOptionDiv.classList.add('add-option-div'); + const optionInput = document.createElement('input'); + optionInput.setAttribute('id', `${this.name}-${settingName}-option`); + optionInput.setAttribute('placeholder', `${setting.min} - ${setting.max}`); + addOptionDiv.appendChild(optionInput); + const addOptionButton = document.createElement('button'); + addOptionButton.innerText = 'Add'; + addOptionDiv.appendChild(addOptionButton); + settingWrapper.appendChild(addOptionDiv); + optionInput.addEventListener('keydown', (evt) => { + if (evt.key === 'Enter') { addOptionButton.dispatchEvent(new Event('click')); } + }); - Object.keys(currentSettings[game][settingName]).forEach((option) => { - // These options are statically generated below, and should always appear even if they are deleted - // from localStorage - if (['random-low', 'random', 'random-high'].includes(option)) { return; } + addOptionButton.addEventListener('click', () => { + const optionInput = document.getElementById(`${this.name}-${settingName}-option`); + let option = optionInput.value; + if (!option || !option.trim()) { return; } + option = parseInt(option, 10); + if ((option < setting.min) || (option > setting.max)) { return; } + optionInput.value = ''; + if (document.getElementById(`${this.name}-${settingName}-${option}-range`)) { return; } - const tr = document.createElement('tr'); + const tr = document.createElement('tr'); const tdLeft = document.createElement('td'); tdLeft.classList.add('td-left'); tdLeft.innerText = option; @@ -432,19 +602,19 @@ const buildWeightedSettingsDiv = (game, settings, gameItems, gameLocations) => { tdMiddle.classList.add('td-middle'); const range = document.createElement('input'); range.setAttribute('type', 'range'); - range.setAttribute('id', `${game}-${settingName}-${option}-range`); - range.setAttribute('data-game', game); + range.setAttribute('id', `${this.name}-${settingName}-${option}-range`); + range.setAttribute('data-game', this.name); range.setAttribute('data-setting', settingName); range.setAttribute('data-option', option); range.setAttribute('min', 0); range.setAttribute('max', 50); - range.addEventListener('change', updateRangeSetting); - range.value = currentSettings[game][settingName][parseInt(option, 10)]; + range.addEventListener('change', (evt) => this.#updateRangeSetting(evt)); + range.value = this.current[settingName][parseInt(option, 10)]; tdMiddle.appendChild(range); tr.appendChild(tdMiddle); const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `${game}-${settingName}-${option}`) + tdRight.setAttribute('id', `${this.name}-${settingName}-${option}`) tdRight.classList.add('td-right'); tdRight.innerText = range.value; tr.appendChild(tdRight); @@ -456,762 +626,651 @@ const buildWeightedSettingsDiv = (game, settings, gameItems, gameLocations) => { deleteButton.innerText = '❌'; deleteButton.addEventListener('click', () => { range.value = 0; - const changeEvent = new Event('change'); - changeEvent.action = 'rangeDelete'; - range.dispatchEvent(changeEvent); + range.dispatchEvent(new Event('change')); rangeTbody.removeChild(tr); }); tdDelete.appendChild(deleteButton); tr.appendChild(tdDelete); rangeTbody.appendChild(tr); - }); - } - - ['random', 'random-low', 'random-high'].forEach((option) => { - const tr = document.createElement('tr'); - const tdLeft = document.createElement('td'); - tdLeft.classList.add('td-left'); - switch(option){ - case 'random': - tdLeft.innerText = 'Random'; - break; - case 'random-low': - tdLeft.innerText = "Random (Low)"; - break; - case 'random-high': - tdLeft.innerText = "Random (High)"; - break; - } - tr.appendChild(tdLeft); - - const tdMiddle = document.createElement('td'); - tdMiddle.classList.add('td-middle'); - const range = document.createElement('input'); - range.setAttribute('type', 'range'); - range.setAttribute('id', `${game}-${settingName}-${option}-range`); - range.setAttribute('data-game', game); - range.setAttribute('data-setting', settingName); - range.setAttribute('data-option', option); - range.setAttribute('min', 0); - range.setAttribute('max', 50); - range.addEventListener('change', updateRangeSetting); - range.value = currentSettings[game][settingName][option]; - tdMiddle.appendChild(range); - tr.appendChild(tdMiddle); - - const tdRight = document.createElement('td'); - tdRight.setAttribute('id', `${game}-${settingName}-${option}`) - tdRight.classList.add('td-right'); - tdRight.innerText = range.value; - tr.appendChild(tdRight); - rangeTbody.appendChild(tr); - }); - rangeTable.appendChild(rangeTbody); - settingWrapper.appendChild(rangeTable); - break; + // Save new option to settings + range.dispatchEvent(new Event('change')); + }); - case 'items-list': - const itemsList = document.createElement('div'); - itemsList.classList.add('simple-list'); - - Object.values(gameItems).forEach((item) => { - const itemRow = document.createElement('div'); - itemRow.classList.add('list-row'); - - const itemLabel = document.createElement('label'); - itemLabel.setAttribute('for', `${game}-${settingName}-${item}`) - - const itemCheckbox = document.createElement('input'); - itemCheckbox.setAttribute('id', `${game}-${settingName}-${item}`); - itemCheckbox.setAttribute('type', 'checkbox'); - itemCheckbox.setAttribute('data-game', game); - itemCheckbox.setAttribute('data-setting', settingName); - itemCheckbox.setAttribute('data-option', item.toString()); - itemCheckbox.addEventListener('change', updateListSetting); - if (currentSettings[game][settingName].includes(item)) { - itemCheckbox.setAttribute('checked', '1'); + Object.keys(this.current[settingName]).forEach((option) => { + // These options are statically generated below, and should always appear even if they are deleted + // from localStorage + if (['random-low', 'random', 'random-high'].includes(option)) { return; } + + const tr = document.createElement('tr'); + const tdLeft = document.createElement('td'); + tdLeft.classList.add('td-left'); + tdLeft.innerText = option; + tr.appendChild(tdLeft); + + const tdMiddle = document.createElement('td'); + tdMiddle.classList.add('td-middle'); + const range = document.createElement('input'); + range.setAttribute('type', 'range'); + range.setAttribute('id', `${this.name}-${settingName}-${option}-range`); + range.setAttribute('data-game', this.name); + range.setAttribute('data-setting', settingName); + range.setAttribute('data-option', option); + range.setAttribute('min', 0); + range.setAttribute('max', 50); + range.addEventListener('change', (evt) => this.#updateRangeSetting(evt)); + range.value = this.current[settingName][parseInt(option, 10)]; + tdMiddle.appendChild(range); + tr.appendChild(tdMiddle); + + const tdRight = document.createElement('td'); + tdRight.setAttribute('id', `${this.name}-${settingName}-${option}`) + tdRight.classList.add('td-right'); + tdRight.innerText = range.value; + tr.appendChild(tdRight); + + const tdDelete = document.createElement('td'); + tdDelete.classList.add('td-delete'); + const deleteButton = document.createElement('span'); + deleteButton.classList.add('range-option-delete'); + deleteButton.innerText = '❌'; + deleteButton.addEventListener('click', () => { + range.value = 0; + const changeEvent = new Event('change'); + changeEvent.action = 'rangeDelete'; + range.dispatchEvent(changeEvent); + rangeTbody.removeChild(tr); + }); + tdDelete.appendChild(deleteButton); + tr.appendChild(tdDelete); + + rangeTbody.appendChild(tr); + }); } - const itemName = document.createElement('span'); - itemName.innerText = item.toString(); + ['random', 'random-low', 'random-high'].forEach((option) => { + const tr = document.createElement('tr'); + const tdLeft = document.createElement('td'); + tdLeft.classList.add('td-left'); + switch(option){ + case 'random': + tdLeft.innerText = 'Random'; + break; + case 'random-low': + tdLeft.innerText = "Random (Low)"; + break; + case 'random-high': + tdLeft.innerText = "Random (High)"; + break; + } + tr.appendChild(tdLeft); - itemLabel.appendChild(itemCheckbox); - itemLabel.appendChild(itemName); + const tdMiddle = document.createElement('td'); + tdMiddle.classList.add('td-middle'); + const range = document.createElement('input'); + range.setAttribute('type', 'range'); + range.setAttribute('id', `${this.name}-${settingName}-${option}-range`); + range.setAttribute('data-game', this.name); + range.setAttribute('data-setting', settingName); + range.setAttribute('data-option', option); + range.setAttribute('min', 0); + range.setAttribute('max', 50); + range.addEventListener('change', (evt) => this.#updateRangeSetting(evt)); + range.value = this.current[settingName][option]; + tdMiddle.appendChild(range); + tr.appendChild(tdMiddle); - itemRow.appendChild(itemLabel); - itemsList.appendChild((itemRow)); - }); + const tdRight = document.createElement('td'); + tdRight.setAttribute('id', `${this.name}-${settingName}-${option}`) + tdRight.classList.add('td-right'); + tdRight.innerText = range.value; + tr.appendChild(tdRight); + rangeTbody.appendChild(tr); + }); - settingWrapper.appendChild(itemsList); - break; + rangeTable.appendChild(rangeTbody); + settingWrapper.appendChild(rangeTable); + break; + + case 'items-list': + const itemsList = document.createElement('div'); + itemsList.classList.add('simple-list'); + + Object.values(this.data.gameItems).forEach((item) => { + const itemRow = document.createElement('div'); + itemRow.classList.add('list-row'); + + const itemLabel = document.createElement('label'); + itemLabel.setAttribute('for', `${this.name}-${settingName}-${item}`) + + const itemCheckbox = document.createElement('input'); + itemCheckbox.setAttribute('id', `${this.name}-${settingName}-${item}`); + itemCheckbox.setAttribute('type', 'checkbox'); + itemCheckbox.setAttribute('data-game', this.name); + itemCheckbox.setAttribute('data-setting', settingName); + itemCheckbox.setAttribute('data-option', item.toString()); + itemCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + if (this.current[settingName].includes(item)) { + itemCheckbox.setAttribute('checked', '1'); + } - case 'locations-list': - const locationsList = document.createElement('div'); - locationsList.classList.add('simple-list'); - - Object.values(gameLocations).forEach((location) => { - const locationRow = document.createElement('div'); - locationRow.classList.add('list-row'); - - const locationLabel = document.createElement('label'); - locationLabel.setAttribute('for', `${game}-${settingName}-${location}`) - - const locationCheckbox = document.createElement('input'); - locationCheckbox.setAttribute('id', `${game}-${settingName}-${location}`); - locationCheckbox.setAttribute('type', 'checkbox'); - locationCheckbox.setAttribute('data-game', game); - locationCheckbox.setAttribute('data-setting', settingName); - locationCheckbox.setAttribute('data-option', location.toString()); - locationCheckbox.addEventListener('change', updateListSetting); - if (currentSettings[game][settingName].includes(location)) { - locationCheckbox.setAttribute('checked', '1'); - } + const itemName = document.createElement('span'); + itemName.innerText = item.toString(); - const locationName = document.createElement('span'); - locationName.innerText = location.toString(); + itemLabel.appendChild(itemCheckbox); + itemLabel.appendChild(itemName); - locationLabel.appendChild(locationCheckbox); - locationLabel.appendChild(locationName); + itemRow.appendChild(itemLabel); + itemsList.appendChild((itemRow)); + }); - locationRow.appendChild(locationLabel); - locationsList.appendChild((locationRow)); - }); + settingWrapper.appendChild(itemsList); + break; + + case 'locations-list': + const locationsList = document.createElement('div'); + locationsList.classList.add('simple-list'); + + Object.values(this.data.gameLocations).forEach((location) => { + const locationRow = document.createElement('div'); + locationRow.classList.add('list-row'); + + const locationLabel = document.createElement('label'); + locationLabel.setAttribute('for', `${this.name}-${settingName}-${location}`) + + const locationCheckbox = document.createElement('input'); + locationCheckbox.setAttribute('id', `${this.name}-${settingName}-${location}`); + locationCheckbox.setAttribute('type', 'checkbox'); + locationCheckbox.setAttribute('data-game', this.name); + locationCheckbox.setAttribute('data-setting', settingName); + locationCheckbox.setAttribute('data-option', location.toString()); + locationCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + if (this.current[settingName].includes(location)) { + locationCheckbox.setAttribute('checked', '1'); + } - settingWrapper.appendChild(locationsList); - break; + const locationName = document.createElement('span'); + locationName.innerText = location.toString(); - case 'custom-list': - const customList = document.createElement('div'); - customList.classList.add('simple-list'); - - Object.values(settings[settingName].options).forEach((listItem) => { - const customListRow = document.createElement('div'); - customListRow.classList.add('list-row'); - - const customItemLabel = document.createElement('label'); - customItemLabel.setAttribute('for', `${game}-${settingName}-${listItem}`) - - const customItemCheckbox = document.createElement('input'); - customItemCheckbox.setAttribute('id', `${game}-${settingName}-${listItem}`); - customItemCheckbox.setAttribute('type', 'checkbox'); - customItemCheckbox.setAttribute('data-game', game); - customItemCheckbox.setAttribute('data-setting', settingName); - customItemCheckbox.setAttribute('data-option', listItem.toString()); - customItemCheckbox.addEventListener('change', updateListSetting); - if (currentSettings[game][settingName].includes(listItem)) { - customItemCheckbox.setAttribute('checked', '1'); - } + locationLabel.appendChild(locationCheckbox); + locationLabel.appendChild(locationName); - const customItemName = document.createElement('span'); - customItemName.innerText = listItem.toString(); + locationRow.appendChild(locationLabel); + locationsList.appendChild((locationRow)); + }); - customItemLabel.appendChild(customItemCheckbox); - customItemLabel.appendChild(customItemName); + settingWrapper.appendChild(locationsList); + break; + + case 'custom-list': + const customList = document.createElement('div'); + customList.classList.add('simple-list'); + + Object.values(this.data.gameSettings[settingName].options).forEach((listItem) => { + const customListRow = document.createElement('div'); + customListRow.classList.add('list-row'); + + const customItemLabel = document.createElement('label'); + customItemLabel.setAttribute('for', `${this.name}-${settingName}-${listItem}`) + + const customItemCheckbox = document.createElement('input'); + customItemCheckbox.setAttribute('id', `${this.name}-${settingName}-${listItem}`); + customItemCheckbox.setAttribute('type', 'checkbox'); + customItemCheckbox.setAttribute('data-game', this.name); + customItemCheckbox.setAttribute('data-setting', settingName); + customItemCheckbox.setAttribute('data-option', listItem.toString()); + customItemCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + if (this.current[settingName].includes(listItem)) { + customItemCheckbox.setAttribute('checked', '1'); + } - customListRow.appendChild(customItemLabel); - customList.appendChild((customListRow)); - }); + const customItemName = document.createElement('span'); + customItemName.innerText = listItem.toString(); - settingWrapper.appendChild(customList); - break; + customItemLabel.appendChild(customItemCheckbox); + customItemLabel.appendChild(customItemName); - default: - console.error(`Unknown setting type for ${game} setting ${settingName}: ${setting.type}`); - return; - } + customListRow.appendChild(customItemLabel); + customList.appendChild((customListRow)); + }); - settingsWrapper.appendChild(settingWrapper); - }); + settingWrapper.appendChild(customList); + break; - return settingsWrapper; -}; + default: + console.error(`Unknown setting type for ${this.name} setting ${settingName}: ${setting.type}`); + return; + } -const buildItemsDiv = (game, items) => { - // Sort alphabetical, in pace - items.sort(); - - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - const itemsDiv = document.createElement('div'); - itemsDiv.classList.add('items-div'); - - const itemsDivHeader = document.createElement('h3'); - itemsDivHeader.innerText = 'Item Pool'; - itemsDiv.appendChild(itemsDivHeader); - - const itemsDescription = document.createElement('p'); - itemsDescription.classList.add('setting-description'); - itemsDescription.innerText = 'Choose if you would like to start with items, or control if they are placed in ' + - 'your seed or someone else\'s.'; - itemsDiv.appendChild(itemsDescription); - - const itemsHint = document.createElement('p'); - itemsHint.classList.add('hint-text'); - itemsHint.innerText = 'Drag and drop items from one box to another.'; - itemsDiv.appendChild(itemsHint); - - const itemsWrapper = document.createElement('div'); - itemsWrapper.classList.add('items-wrapper'); - - // Create container divs for each category - const availableItemsWrapper = document.createElement('div'); - availableItemsWrapper.classList.add('item-set-wrapper'); - availableItemsWrapper.innerText = 'Available Items'; - const availableItems = document.createElement('div'); - availableItems.classList.add('item-container'); - availableItems.setAttribute('id', `${game}-available_items`); - availableItems.addEventListener('dragover', itemDragoverHandler); - availableItems.addEventListener('drop', itemDropHandler); - - const startInventoryWrapper = document.createElement('div'); - startInventoryWrapper.classList.add('item-set-wrapper'); - startInventoryWrapper.innerText = 'Start Inventory'; - const startInventory = document.createElement('div'); - startInventory.classList.add('item-container'); - startInventory.setAttribute('id', `${game}-start_inventory`); - startInventory.setAttribute('data-setting', 'start_inventory'); - startInventory.addEventListener('dragover', itemDragoverHandler); - startInventory.addEventListener('drop', itemDropHandler); - - const localItemsWrapper = document.createElement('div'); - localItemsWrapper.classList.add('item-set-wrapper'); - localItemsWrapper.innerText = 'Local Items'; - const localItems = document.createElement('div'); - localItems.classList.add('item-container'); - localItems.setAttribute('id', `${game}-local_items`); - localItems.setAttribute('data-setting', 'local_items') - localItems.addEventListener('dragover', itemDragoverHandler); - localItems.addEventListener('drop', itemDropHandler); - - const nonLocalItemsWrapper = document.createElement('div'); - nonLocalItemsWrapper.classList.add('item-set-wrapper'); - nonLocalItemsWrapper.innerText = 'Non-Local Items'; - const nonLocalItems = document.createElement('div'); - nonLocalItems.classList.add('item-container'); - nonLocalItems.setAttribute('id', `${game}-non_local_items`); - nonLocalItems.setAttribute('data-setting', 'non_local_items'); - nonLocalItems.addEventListener('dragover', itemDragoverHandler); - nonLocalItems.addEventListener('drop', itemDropHandler); - - // Populate the divs - items.forEach((item) => { - if (Object.keys(currentSettings[game].start_inventory).includes(item)){ - const itemDiv = buildItemQtyDiv(game, item); - itemDiv.setAttribute('data-setting', 'start_inventory'); - startInventory.appendChild(itemDiv); - } else if (currentSettings[game].local_items.includes(item)) { - const itemDiv = buildItemDiv(game, item); - itemDiv.setAttribute('data-setting', 'local_items'); - localItems.appendChild(itemDiv); - } else if (currentSettings[game].non_local_items.includes(item)) { - const itemDiv = buildItemDiv(game, item); - itemDiv.setAttribute('data-setting', 'non_local_items'); - nonLocalItems.appendChild(itemDiv); - } else { - const itemDiv = buildItemDiv(game, item); - availableItems.appendChild(itemDiv); - } - }); + settingsWrapper.appendChild(settingWrapper); + }); - availableItemsWrapper.appendChild(availableItems); - startInventoryWrapper.appendChild(startInventory); - localItemsWrapper.appendChild(localItems); - nonLocalItemsWrapper.appendChild(nonLocalItems); - itemsWrapper.appendChild(availableItemsWrapper); - itemsWrapper.appendChild(startInventoryWrapper); - itemsWrapper.appendChild(localItemsWrapper); - itemsWrapper.appendChild(nonLocalItemsWrapper); - itemsDiv.appendChild(itemsWrapper); - return itemsDiv; -}; + return settingsWrapper; + } -const buildItemDiv = (game, item) => { - const itemDiv = document.createElement('div'); - itemDiv.classList.add('item-div'); - itemDiv.setAttribute('id', `${game}-${item}`); - itemDiv.setAttribute('data-game', game); - itemDiv.setAttribute('data-item', item); - itemDiv.setAttribute('draggable', 'true'); - itemDiv.innerText = item; - itemDiv.addEventListener('dragstart', (evt) => { - evt.dataTransfer.setData('text/plain', itemDiv.getAttribute('id')); - }); - return itemDiv; -}; + #buildItemsDiv() { + const itemsDiv = document.createElement('div'); + itemsDiv.classList.add('items-div'); + + const itemsDivHeader = document.createElement('h3'); + itemsDivHeader.innerText = 'Item Pool'; + itemsDiv.appendChild(itemsDivHeader); + + const itemsDescription = document.createElement('p'); + itemsDescription.classList.add('setting-description'); + itemsDescription.innerText = 'Choose if you would like to start with items, or control if they are placed in ' + + 'your seed or someone else\'s.'; + itemsDiv.appendChild(itemsDescription); + + const itemsHint = document.createElement('p'); + itemsHint.classList.add('hint-text'); + itemsHint.innerText = 'Drag and drop items from one box to another.'; + itemsDiv.appendChild(itemsHint); + + const itemsWrapper = document.createElement('div'); + itemsWrapper.classList.add('items-wrapper'); + + const itemDragoverHandler = (evt) => evt.preventDefault(); + const itemDropHandler = (evt) => this.#itemDropHandler(evt); + + // Create container divs for each category + const availableItemsWrapper = document.createElement('div'); + availableItemsWrapper.classList.add('item-set-wrapper'); + availableItemsWrapper.innerText = 'Available Items'; + const availableItems = document.createElement('div'); + availableItems.classList.add('item-container'); + availableItems.setAttribute('id', `${this.name}-available_items`); + availableItems.addEventListener('dragover', itemDragoverHandler); + availableItems.addEventListener('drop', itemDropHandler); + + const startInventoryWrapper = document.createElement('div'); + startInventoryWrapper.classList.add('item-set-wrapper'); + startInventoryWrapper.innerText = 'Start Inventory'; + const startInventory = document.createElement('div'); + startInventory.classList.add('item-container'); + startInventory.setAttribute('id', `${this.name}-start_inventory`); + startInventory.setAttribute('data-setting', 'start_inventory'); + startInventory.addEventListener('dragover', itemDragoverHandler); + startInventory.addEventListener('drop', itemDropHandler); + + const localItemsWrapper = document.createElement('div'); + localItemsWrapper.classList.add('item-set-wrapper'); + localItemsWrapper.innerText = 'Local Items'; + const localItems = document.createElement('div'); + localItems.classList.add('item-container'); + localItems.setAttribute('id', `${this.name}-local_items`); + localItems.setAttribute('data-setting', 'local_items') + localItems.addEventListener('dragover', itemDragoverHandler); + localItems.addEventListener('drop', itemDropHandler); + + const nonLocalItemsWrapper = document.createElement('div'); + nonLocalItemsWrapper.classList.add('item-set-wrapper'); + nonLocalItemsWrapper.innerText = 'Non-Local Items'; + const nonLocalItems = document.createElement('div'); + nonLocalItems.classList.add('item-container'); + nonLocalItems.setAttribute('id', `${this.name}-non_local_items`); + nonLocalItems.setAttribute('data-setting', 'non_local_items'); + nonLocalItems.addEventListener('dragover', itemDragoverHandler); + nonLocalItems.addEventListener('drop', itemDropHandler); + + // Populate the divs + this.data.gameItems.forEach((item) => { + if (Object.keys(this.current.start_inventory).includes(item)){ + const itemDiv = this.#buildItemQtyDiv(item); + itemDiv.setAttribute('data-setting', 'start_inventory'); + startInventory.appendChild(itemDiv); + } else if (this.current.local_items.includes(item)) { + const itemDiv = this.#buildItemDiv(item); + itemDiv.setAttribute('data-setting', 'local_items'); + localItems.appendChild(itemDiv); + } else if (this.current.non_local_items.includes(item)) { + const itemDiv = this.#buildItemDiv(item); + itemDiv.setAttribute('data-setting', 'non_local_items'); + nonLocalItems.appendChild(itemDiv); + } else { + const itemDiv = this.#buildItemDiv(item); + availableItems.appendChild(itemDiv); + } + }); -const buildItemQtyDiv = (game, item) => { - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - const itemQtyDiv = document.createElement('div'); - itemQtyDiv.classList.add('item-qty-div'); - itemQtyDiv.setAttribute('id', `${game}-${item}`); - itemQtyDiv.setAttribute('data-game', game); - itemQtyDiv.setAttribute('data-item', item); - itemQtyDiv.setAttribute('draggable', 'true'); - itemQtyDiv.innerText = item; - - const inputWrapper = document.createElement('div'); - inputWrapper.classList.add('item-qty-input-wrapper') - - const itemQty = document.createElement('input'); - itemQty.setAttribute('value', currentSettings[game].start_inventory.hasOwnProperty(item) ? - currentSettings[game].start_inventory[item] : '1'); - itemQty.setAttribute('data-game', game); - itemQty.setAttribute('data-setting', 'start_inventory'); - itemQty.setAttribute('data-option', item); - itemQty.setAttribute('maxlength', '3'); - itemQty.addEventListener('keyup', (evt) => { - evt.target.value = isNaN(parseInt(evt.target.value)) ? 0 : parseInt(evt.target.value); - updateItemSetting(evt); - }); - inputWrapper.appendChild(itemQty); - itemQtyDiv.appendChild(inputWrapper); + availableItemsWrapper.appendChild(availableItems); + startInventoryWrapper.appendChild(startInventory); + localItemsWrapper.appendChild(localItems); + nonLocalItemsWrapper.appendChild(nonLocalItems); + itemsWrapper.appendChild(availableItemsWrapper); + itemsWrapper.appendChild(startInventoryWrapper); + itemsWrapper.appendChild(localItemsWrapper); + itemsWrapper.appendChild(nonLocalItemsWrapper); + itemsDiv.appendChild(itemsWrapper); + return itemsDiv; + } - itemQtyDiv.addEventListener('dragstart', (evt) => { - evt.dataTransfer.setData('text/plain', itemQtyDiv.getAttribute('id')); - }); - return itemQtyDiv; -}; + #buildItemDiv(item) { + const itemDiv = document.createElement('div'); + itemDiv.classList.add('item-div'); + itemDiv.setAttribute('id', `${this.name}-${item}`); + itemDiv.setAttribute('data-game', this.name); + itemDiv.setAttribute('data-item', item); + itemDiv.setAttribute('draggable', 'true'); + itemDiv.innerText = item; + itemDiv.addEventListener('dragstart', (evt) => { + evt.dataTransfer.setData('text/plain', itemDiv.getAttribute('id')); + }); + return itemDiv; + } -const itemDragoverHandler = (evt) => { - evt.preventDefault(); -}; + #buildItemQtyDiv(item) { + const itemQtyDiv = document.createElement('div'); + itemQtyDiv.classList.add('item-qty-div'); + itemQtyDiv.setAttribute('id', `${this.name}-${item}`); + itemQtyDiv.setAttribute('data-game', this.name); + itemQtyDiv.setAttribute('data-item', item); + itemQtyDiv.setAttribute('draggable', 'true'); + itemQtyDiv.innerText = item; + + const inputWrapper = document.createElement('div'); + inputWrapper.classList.add('item-qty-input-wrapper') + + const itemQty = document.createElement('input'); + itemQty.setAttribute('value', this.current.start_inventory.hasOwnProperty(item) ? + this.current.start_inventory[item] : '1'); + itemQty.setAttribute('data-game', this.name); + itemQty.setAttribute('data-setting', 'start_inventory'); + itemQty.setAttribute('data-option', item); + itemQty.setAttribute('maxlength', '3'); + itemQty.addEventListener('keyup', (evt) => { + evt.target.value = isNaN(parseInt(evt.target.value)) ? 0 : parseInt(evt.target.value); + this.#updateItemSetting(evt); + }); + inputWrapper.appendChild(itemQty); + itemQtyDiv.appendChild(inputWrapper); -const itemDropHandler = (evt) => { - evt.preventDefault(); - const sourceId = evt.dataTransfer.getData('text/plain'); - const sourceDiv = document.getElementById(sourceId); + itemQtyDiv.addEventListener('dragstart', (evt) => { + evt.dataTransfer.setData('text/plain', itemQtyDiv.getAttribute('id')); + }); + return itemQtyDiv; + } - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - const game = sourceDiv.getAttribute('data-game'); - const item = sourceDiv.getAttribute('data-item'); + #itemDropHandler(evt) { + evt.preventDefault(); + const sourceId = evt.dataTransfer.getData('text/plain'); + const sourceDiv = document.getElementById(sourceId); - const oldSetting = sourceDiv.hasAttribute('data-setting') ? sourceDiv.getAttribute('data-setting') : null; - const newSetting = evt.target.hasAttribute('data-setting') ? evt.target.getAttribute('data-setting') : null; + const item = sourceDiv.getAttribute('data-item'); - const itemDiv = newSetting === 'start_inventory' ? buildItemQtyDiv(game, item) : buildItemDiv(game, item); + const oldSetting = sourceDiv.hasAttribute('data-setting') ? sourceDiv.getAttribute('data-setting') : null; + const newSetting = evt.target.hasAttribute('data-setting') ? evt.target.getAttribute('data-setting') : null; - if (oldSetting) { - if (oldSetting === 'start_inventory') { - if (currentSettings[game][oldSetting].hasOwnProperty(item)) { - delete currentSettings[game][oldSetting][item]; - } - } else { - if (currentSettings[game][oldSetting].includes(item)) { - currentSettings[game][oldSetting].splice(currentSettings[game][oldSetting].indexOf(item), 1); + const itemDiv = newSetting === 'start_inventory' ? this.#buildItemQtyDiv(item) : this.#buildItemDiv(item); + + if (oldSetting) { + if (oldSetting === 'start_inventory') { + if (this.current[oldSetting].hasOwnProperty(item)) { + delete this.current[oldSetting][item]; + } + } else { + if (this.current[oldSetting].includes(item)) { + this.current[oldSetting].splice(this.current[oldSetting].indexOf(item), 1); + } } } - } - if (newSetting) { - itemDiv.setAttribute('data-setting', newSetting); - document.getElementById(`${game}-${newSetting}`).appendChild(itemDiv); - if (newSetting === 'start_inventory') { - currentSettings[game][newSetting][item] = 1; - } else { - if (!currentSettings[game][newSetting].includes(item)){ - currentSettings[game][newSetting].push(item); + if (newSetting) { + itemDiv.setAttribute('data-setting', newSetting); + document.getElementById(`${this.name}-${newSetting}`).appendChild(itemDiv); + if (newSetting === 'start_inventory') { + this.current[newSetting][item] = 1; + } else { + if (!this.current[newSetting].includes(item)){ + this.current[newSetting].push(item); + } } + } else { + // No setting was assigned, this item has been removed from the settings + document.getElementById(`${this.name}-available_items`).appendChild(itemDiv); } - } else { - // No setting was assigned, this item has been removed from the settings - document.getElementById(`${game}-available_items`).appendChild(itemDiv); - } - // Remove the source drag object - sourceDiv.parentElement.removeChild(sourceDiv); + // Remove the source drag object + sourceDiv.parentElement.removeChild(sourceDiv); - // Save the updated settings - localStorage.setItem('weighted-settings', JSON.stringify(currentSettings)); -}; + // Save the updated settings + this.save(); + } -const buildHintsDiv = (game, items, locations) => { - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - - // Sort alphabetical, in place - items.sort(); - locations.sort(); - - const hintsDiv = document.createElement('div'); - hintsDiv.classList.add('hints-div'); - const hintsHeader = document.createElement('h3'); - hintsHeader.innerText = 'Item & Location Hints'; - hintsDiv.appendChild(hintsHeader); - const hintsDescription = document.createElement('p'); - hintsDescription.classList.add('setting-description'); - hintsDescription.innerText = 'Choose any items or locations to begin the game with the knowledge of where those ' + - ' items are, or what those locations contain.'; - hintsDiv.appendChild(hintsDescription); - - const itemHintsContainer = document.createElement('div'); - itemHintsContainer.classList.add('hints-container'); - - // Item Hints - const itemHintsWrapper = document.createElement('div'); - itemHintsWrapper.classList.add('hints-wrapper'); - itemHintsWrapper.innerText = 'Starting Item Hints'; - - const itemHintsDiv = document.createElement('div'); - itemHintsDiv.classList.add('simple-list'); - items.forEach((item) => { - const itemRow = document.createElement('div'); - itemRow.classList.add('list-row'); - - const itemLabel = document.createElement('label'); - itemLabel.setAttribute('for', `${game}-start_hints-${item}`); - - const itemCheckbox = document.createElement('input'); - itemCheckbox.setAttribute('type', 'checkbox'); - itemCheckbox.setAttribute('id', `${game}-start_hints-${item}`); - itemCheckbox.setAttribute('data-game', game); - itemCheckbox.setAttribute('data-setting', 'start_hints'); - itemCheckbox.setAttribute('data-option', item); - if (currentSettings[game].start_hints.includes(item)) { - itemCheckbox.setAttribute('checked', 'true'); - } - itemCheckbox.addEventListener('change', updateListSetting); - itemLabel.appendChild(itemCheckbox); + #buildHintsDiv() { + const hintsDiv = document.createElement('div'); + hintsDiv.classList.add('hints-div'); + const hintsHeader = document.createElement('h3'); + hintsHeader.innerText = 'Item & Location Hints'; + hintsDiv.appendChild(hintsHeader); + const hintsDescription = document.createElement('p'); + hintsDescription.classList.add('setting-description'); + hintsDescription.innerText = 'Choose any items or locations to begin the game with the knowledge of where those ' + + ' items are, or what those locations contain.'; + hintsDiv.appendChild(hintsDescription); + + const itemHintsContainer = document.createElement('div'); + itemHintsContainer.classList.add('hints-container'); + + // Item Hints + const itemHintsWrapper = document.createElement('div'); + itemHintsWrapper.classList.add('hints-wrapper'); + itemHintsWrapper.innerText = 'Starting Item Hints'; + + const itemHintsDiv = document.createElement('div'); + itemHintsDiv.classList.add('simple-list'); + this.data.gameItems.forEach((item) => { + const itemRow = document.createElement('div'); + itemRow.classList.add('list-row'); + + const itemLabel = document.createElement('label'); + itemLabel.setAttribute('for', `${this.name}-start_hints-${item}`); + + const itemCheckbox = document.createElement('input'); + itemCheckbox.setAttribute('type', 'checkbox'); + itemCheckbox.setAttribute('id', `${this.name}-start_hints-${item}`); + itemCheckbox.setAttribute('data-game', this.name); + itemCheckbox.setAttribute('data-setting', 'start_hints'); + itemCheckbox.setAttribute('data-option', item); + if (this.current.start_hints.includes(item)) { + itemCheckbox.setAttribute('checked', 'true'); + } + itemCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + itemLabel.appendChild(itemCheckbox); - const itemName = document.createElement('span'); - itemName.innerText = item; - itemLabel.appendChild(itemName); + const itemName = document.createElement('span'); + itemName.innerText = item; + itemLabel.appendChild(itemName); - itemRow.appendChild(itemLabel); - itemHintsDiv.appendChild(itemRow); - }); + itemRow.appendChild(itemLabel); + itemHintsDiv.appendChild(itemRow); + }); - itemHintsWrapper.appendChild(itemHintsDiv); - itemHintsContainer.appendChild(itemHintsWrapper); - - // Starting Location Hints - const locationHintsWrapper = document.createElement('div'); - locationHintsWrapper.classList.add('hints-wrapper'); - locationHintsWrapper.innerText = 'Starting Location Hints'; - - const locationHintsDiv = document.createElement('div'); - locationHintsDiv.classList.add('simple-list'); - locations.forEach((location) => { - const locationRow = document.createElement('div'); - locationRow.classList.add('list-row'); - - const locationLabel = document.createElement('label'); - locationLabel.setAttribute('for', `${game}-start_location_hints-${location}`); - - const locationCheckbox = document.createElement('input'); - locationCheckbox.setAttribute('type', 'checkbox'); - locationCheckbox.setAttribute('id', `${game}-start_location_hints-${location}`); - locationCheckbox.setAttribute('data-game', game); - locationCheckbox.setAttribute('data-setting', 'start_location_hints'); - locationCheckbox.setAttribute('data-option', location); - if (currentSettings[game].start_location_hints.includes(location)) { - locationCheckbox.setAttribute('checked', '1'); - } - locationCheckbox.addEventListener('change', updateListSetting); - locationLabel.appendChild(locationCheckbox); + itemHintsWrapper.appendChild(itemHintsDiv); + itemHintsContainer.appendChild(itemHintsWrapper); + + // Starting Location Hints + const locationHintsWrapper = document.createElement('div'); + locationHintsWrapper.classList.add('hints-wrapper'); + locationHintsWrapper.innerText = 'Starting Location Hints'; + + const locationHintsDiv = document.createElement('div'); + locationHintsDiv.classList.add('simple-list'); + this.data.gameLocations.forEach((location) => { + const locationRow = document.createElement('div'); + locationRow.classList.add('list-row'); + + const locationLabel = document.createElement('label'); + locationLabel.setAttribute('for', `${this.name}-start_location_hints-${location}`); + + const locationCheckbox = document.createElement('input'); + locationCheckbox.setAttribute('type', 'checkbox'); + locationCheckbox.setAttribute('id', `${this.name}-start_location_hints-${location}`); + locationCheckbox.setAttribute('data-game', this.name); + locationCheckbox.setAttribute('data-setting', 'start_location_hints'); + locationCheckbox.setAttribute('data-option', location); + if (this.current.start_location_hints.includes(location)) { + locationCheckbox.setAttribute('checked', '1'); + } + locationCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + locationLabel.appendChild(locationCheckbox); - const locationName = document.createElement('span'); - locationName.innerText = location; - locationLabel.appendChild(locationName); + const locationName = document.createElement('span'); + locationName.innerText = location; + locationLabel.appendChild(locationName); - locationRow.appendChild(locationLabel); - locationHintsDiv.appendChild(locationRow); - }); + locationRow.appendChild(locationLabel); + locationHintsDiv.appendChild(locationRow); + }); - locationHintsWrapper.appendChild(locationHintsDiv); - itemHintsContainer.appendChild(locationHintsWrapper); + locationHintsWrapper.appendChild(locationHintsDiv); + itemHintsContainer.appendChild(locationHintsWrapper); - hintsDiv.appendChild(itemHintsContainer); - return hintsDiv; -}; + hintsDiv.appendChild(itemHintsContainer); + return hintsDiv; + } -const buildLocationsDiv = (game, locations) => { - const currentSettings = JSON.parse(localStorage.getItem('weighted-settings')); - locations.sort(); // Sort alphabetical, in-place - - const locationsDiv = document.createElement('div'); - locationsDiv.classList.add('locations-div'); - const locationsHeader = document.createElement('h3'); - locationsHeader.innerText = 'Priority & Exclusion Locations'; - locationsDiv.appendChild(locationsHeader); - const locationsDescription = document.createElement('p'); - locationsDescription.classList.add('setting-description'); - locationsDescription.innerText = 'Priority locations guarantee a progression item will be placed there while ' + - 'excluded locations will not contain progression or useful items.'; - locationsDiv.appendChild(locationsDescription); - - const locationsContainer = document.createElement('div'); - locationsContainer.classList.add('locations-container'); - - // Priority Locations - const priorityLocationsWrapper = document.createElement('div'); - priorityLocationsWrapper.classList.add('locations-wrapper'); - priorityLocationsWrapper.innerText = 'Priority Locations'; - - const priorityLocationsDiv = document.createElement('div'); - priorityLocationsDiv.classList.add('simple-list'); - locations.forEach((location) => { - const locationRow = document.createElement('div'); - locationRow.classList.add('list-row'); - - const locationLabel = document.createElement('label'); - locationLabel.setAttribute('for', `${game}-priority_locations-${location}`); - - const locationCheckbox = document.createElement('input'); - locationCheckbox.setAttribute('type', 'checkbox'); - locationCheckbox.setAttribute('id', `${game}-priority_locations-${location}`); - locationCheckbox.setAttribute('data-game', game); - locationCheckbox.setAttribute('data-setting', 'priority_locations'); - locationCheckbox.setAttribute('data-option', location); - if (currentSettings[game].priority_locations.includes(location)) { - locationCheckbox.setAttribute('checked', '1'); - } - locationCheckbox.addEventListener('change', updateListSetting); - locationLabel.appendChild(locationCheckbox); + #buildLocationsDiv() { + const locationsDiv = document.createElement('div'); + locationsDiv.classList.add('locations-div'); + const locationsHeader = document.createElement('h3'); + locationsHeader.innerText = 'Priority & Exclusion Locations'; + locationsDiv.appendChild(locationsHeader); + const locationsDescription = document.createElement('p'); + locationsDescription.classList.add('setting-description'); + locationsDescription.innerText = 'Priority locations guarantee a progression item will be placed there while ' + + 'excluded locations will not contain progression or useful items.'; + locationsDiv.appendChild(locationsDescription); + + const locationsContainer = document.createElement('div'); + locationsContainer.classList.add('locations-container'); + + // Priority Locations + const priorityLocationsWrapper = document.createElement('div'); + priorityLocationsWrapper.classList.add('locations-wrapper'); + priorityLocationsWrapper.innerText = 'Priority Locations'; + + const priorityLocationsDiv = document.createElement('div'); + priorityLocationsDiv.classList.add('simple-list'); + this.data.gameLocations.forEach((location) => { + const locationRow = document.createElement('div'); + locationRow.classList.add('list-row'); + + const locationLabel = document.createElement('label'); + locationLabel.setAttribute('for', `${this.name}-priority_locations-${location}`); + + const locationCheckbox = document.createElement('input'); + locationCheckbox.setAttribute('type', 'checkbox'); + locationCheckbox.setAttribute('id', `${this.name}-priority_locations-${location}`); + locationCheckbox.setAttribute('data-game', this.name); + locationCheckbox.setAttribute('data-setting', 'priority_locations'); + locationCheckbox.setAttribute('data-option', location); + if (this.current.priority_locations.includes(location)) { + locationCheckbox.setAttribute('checked', '1'); + } + locationCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + locationLabel.appendChild(locationCheckbox); - const locationName = document.createElement('span'); - locationName.innerText = location; - locationLabel.appendChild(locationName); + const locationName = document.createElement('span'); + locationName.innerText = location; + locationLabel.appendChild(locationName); - locationRow.appendChild(locationLabel); - priorityLocationsDiv.appendChild(locationRow); - }); + locationRow.appendChild(locationLabel); + priorityLocationsDiv.appendChild(locationRow); + }); - priorityLocationsWrapper.appendChild(priorityLocationsDiv); - locationsContainer.appendChild(priorityLocationsWrapper); - - // Exclude Locations - const excludeLocationsWrapper = document.createElement('div'); - excludeLocationsWrapper.classList.add('locations-wrapper'); - excludeLocationsWrapper.innerText = 'Exclude Locations'; - - const excludeLocationsDiv = document.createElement('div'); - excludeLocationsDiv.classList.add('simple-list'); - locations.forEach((location) => { - const locationRow = document.createElement('div'); - locationRow.classList.add('list-row'); - - const locationLabel = document.createElement('label'); - locationLabel.setAttribute('for', `${game}-exclude_locations-${location}`); - - const locationCheckbox = document.createElement('input'); - locationCheckbox.setAttribute('type', 'checkbox'); - locationCheckbox.setAttribute('id', `${game}-exclude_locations-${location}`); - locationCheckbox.setAttribute('data-game', game); - locationCheckbox.setAttribute('data-setting', 'exclude_locations'); - locationCheckbox.setAttribute('data-option', location); - if (currentSettings[game].exclude_locations.includes(location)) { - locationCheckbox.setAttribute('checked', '1'); - } - locationCheckbox.addEventListener('change', updateListSetting); - locationLabel.appendChild(locationCheckbox); + priorityLocationsWrapper.appendChild(priorityLocationsDiv); + locationsContainer.appendChild(priorityLocationsWrapper); + + // Exclude Locations + const excludeLocationsWrapper = document.createElement('div'); + excludeLocationsWrapper.classList.add('locations-wrapper'); + excludeLocationsWrapper.innerText = 'Exclude Locations'; + + const excludeLocationsDiv = document.createElement('div'); + excludeLocationsDiv.classList.add('simple-list'); + this.data.gameLocations.forEach((location) => { + const locationRow = document.createElement('div'); + locationRow.classList.add('list-row'); + + const locationLabel = document.createElement('label'); + locationLabel.setAttribute('for', `${this.name}-exclude_locations-${location}`); + + const locationCheckbox = document.createElement('input'); + locationCheckbox.setAttribute('type', 'checkbox'); + locationCheckbox.setAttribute('id', `${this.name}-exclude_locations-${location}`); + locationCheckbox.setAttribute('data-game', this.name); + locationCheckbox.setAttribute('data-setting', 'exclude_locations'); + locationCheckbox.setAttribute('data-option', location); + if (this.current.exclude_locations.includes(location)) { + locationCheckbox.setAttribute('checked', '1'); + } + locationCheckbox.addEventListener('change', (evt) => this.#updateListSetting(evt)); + locationLabel.appendChild(locationCheckbox); - const locationName = document.createElement('span'); - locationName.innerText = location; - locationLabel.appendChild(locationName); + const locationName = document.createElement('span'); + locationName.innerText = location; + locationLabel.appendChild(locationName); - locationRow.appendChild(locationLabel); - excludeLocationsDiv.appendChild(locationRow); - }); + locationRow.appendChild(locationLabel); + excludeLocationsDiv.appendChild(locationRow); + }); - excludeLocationsWrapper.appendChild(excludeLocationsDiv); - locationsContainer.appendChild(excludeLocationsWrapper); + excludeLocationsWrapper.appendChild(excludeLocationsDiv); + locationsContainer.appendChild(excludeLocationsWrapper); - locationsDiv.appendChild(locationsContainer); - return locationsDiv; -}; + locationsDiv.appendChild(locationsContainer); + return locationsDiv; + } -const updateVisibleGames = () => { - const settings = JSON.parse(localStorage.getItem('weighted-settings')); - Object.keys(settings.game).forEach((game) => { - const gameDiv = document.getElementById(`${game}-div`); - const gameOption = document.getElementById(`${game}-game-option`); - if (parseInt(settings.game[game], 10) > 0) { - gameDiv.classList.remove('invisible'); - gameOption.classList.add('jump-link'); - gameOption.addEventListener('click', () => { - const gameDiv = document.getElementById(`${game}-div`); - if (gameDiv.classList.contains('invisible')) { return; } - gameDiv.scrollIntoView({ - behavior: 'smooth', - block: 'start', - }); - }); + #updateRangeSetting(evt) { + const setting = evt.target.getAttribute('data-setting'); + const option = evt.target.getAttribute('data-option'); + document.getElementById(`${this.name}-${setting}-${option}`).innerText = evt.target.value; + if (evt.action && evt.action === 'rangeDelete') { + delete this.current[setting][option]; } else { - gameDiv.classList.add('invisible'); - gameOption.classList.remove('jump-link'); - + this.current[setting][option] = parseInt(evt.target.value, 10); } - }); -}; - -const updateBaseSetting = (event) => { - const settings = JSON.parse(localStorage.getItem('weighted-settings')); - const setting = event.target.getAttribute('data-setting'); - const option = event.target.getAttribute('data-option'); - const type = event.target.getAttribute('data-type'); - - switch(type){ - case 'weight': - settings[setting][option] = isNaN(event.target.value) ? event.target.value : parseInt(event.target.value, 10); - document.getElementById(`${setting}-${option}`).innerText = event.target.value; - break; - case 'data': - settings[setting] = isNaN(event.target.value) ? event.target.value : parseInt(event.target.value, 10); - break; + this.save(); } - localStorage.setItem('weighted-settings', JSON.stringify(settings)); -}; - -const updateRangeSetting = (evt) => { - const options = JSON.parse(localStorage.getItem('weighted-settings')); - const game = evt.target.getAttribute('data-game'); - const setting = evt.target.getAttribute('data-setting'); - const option = evt.target.getAttribute('data-option'); - document.getElementById(`${game}-${setting}-${option}`).innerText = evt.target.value; - if (evt.action && evt.action === 'rangeDelete') { - delete options[game][setting][option]; - } else { - options[game][setting][option] = parseInt(evt.target.value, 10); - } - localStorage.setItem('weighted-settings', JSON.stringify(options)); -}; - -const updateListSetting = (evt) => { - const options = JSON.parse(localStorage.getItem('weighted-settings')); - const game = evt.target.getAttribute('data-game'); - const setting = evt.target.getAttribute('data-setting'); - const option = evt.target.getAttribute('data-option'); - - if (evt.target.checked) { - // If the option is to be enabled and it is already enabled, do nothing - if (options[game][setting].includes(option)) { return; } + #updateListSetting(evt) { + const setting = evt.target.getAttribute('data-setting'); + const option = evt.target.getAttribute('data-option'); - options[game][setting].push(option); - } else { - // If the option is to be disabled and it is already disabled, do nothing - if (!options[game][setting].includes(option)) { return; } + if (evt.target.checked) { + // If the option is to be enabled and it is already enabled, do nothing + if (this.current[setting].includes(option)) { return; } - options[game][setting].splice(options[game][setting].indexOf(option), 1); - } - localStorage.setItem('weighted-settings', JSON.stringify(options)); -}; - -const updateItemSetting = (evt) => { - const options = JSON.parse(localStorage.getItem('weighted-settings')); - const game = evt.target.getAttribute('data-game'); - const setting = evt.target.getAttribute('data-setting'); - const option = evt.target.getAttribute('data-option'); - if (setting === 'start_inventory') { - options[game][setting][option] = evt.target.value.trim() ? parseInt(evt.target.value) : 0; - } else { - options[game][setting][option] = isNaN(evt.target.value) ? - evt.target.value : parseInt(evt.target.value, 10); - } - localStorage.setItem('weighted-settings', JSON.stringify(options)); -}; - -const validateSettings = () => { - const settings = JSON.parse(localStorage.getItem('weighted-settings')); - const userMessage = document.getElementById('user-message'); - let errorMessage = null; - - // User must choose a name for their file - if (!settings.name || settings.name.trim().length === 0 || settings.name.toLowerCase().trim() === 'player') { - userMessage.innerText = 'You forgot to set your player name at the top of the page!'; - userMessage.classList.add('visible'); - userMessage.scrollIntoView({ - behavior: 'smooth', - block: 'start', - }); - return; - } + this.current[setting].push(option); + } else { + // If the option is to be disabled and it is already disabled, do nothing + if (!this.current[setting].includes(option)) { return; } - // Clean up the settings output - Object.keys(settings.game).forEach((game) => { - // Remove any disabled games - if (settings.game[game] === 0) { - delete settings.game[game]; - delete settings[game]; - return; + this.current[setting].splice(this.current[setting].indexOf(option), 1); } - - Object.keys(settings[game]).forEach((setting) => { - // Remove any disabled options - Object.keys(settings[game][setting]).forEach((option) => { - if (settings[game][setting][option] === 0) { - delete settings[game][setting][option]; - } - }); - - if ( - Object.keys(settings[game][setting]).length === 0 && - !Array.isArray(settings[game][setting]) && - setting !== 'start_inventory' - ) { - errorMessage = `${game} // ${setting} has no values above zero!`; - } - - // Remove weights from options with only one possibility - if ( - Object.keys(settings[game][setting]).length === 1 && - !Array.isArray(settings[game][setting]) && - setting !== 'start_inventory' - ) { - settings[game][setting] = Object.keys(settings[game][setting])[0]; - } - - // Remove empty arrays - else if ( - ['exclude_locations', 'priority_locations', 'local_items', - 'non_local_items', 'start_hints', 'start_location_hints'].includes(setting) && - settings[game][setting].length === 0 - ) { - delete settings[game][setting]; - } - - // Remove empty start inventory - else if ( - setting === 'start_inventory' && - Object.keys(settings[game]['start_inventory']).length === 0 - ) { - delete settings[game]['start_inventory']; - } - }); - }); - - if (Object.keys(settings.game).length === 0) { - errorMessage = 'You have not chosen a game to play!'; + this.save(); } - // Remove weights if there is only one game - else if (Object.keys(settings.game).length === 1) { - settings.game = Object.keys(settings.game)[0]; + #updateItemSetting(evt) { + const setting = evt.target.getAttribute('data-setting'); + const option = evt.target.getAttribute('data-option'); + if (setting === 'start_inventory') { + this.current[setting][option] = evt.target.value.trim() ? parseInt(evt.target.value) : 0; + } else { + this.current[setting][option] = isNaN(evt.target.value) ? + evt.target.value : parseInt(evt.target.value, 10); + } + this.save(); } - // If an error occurred, alert the user and do not export the file - if (errorMessage) { - userMessage.innerText = errorMessage; - userMessage.classList.add('visible'); - userMessage.scrollIntoView({ - behavior: 'smooth', - block: 'start', - }); - return; + // Saves the current settings to local storage. + save() { + this.#allSettings.save(); } - - // If no error occurred, hide the user message if it is visible - userMessage.classList.remove('visible'); - return settings; -}; - -const exportSettings = () => { - const settings = validateSettings(); - if (!settings) { return; } - - const yamlText = jsyaml.safeDump(settings, { noCompatMode: true }).replaceAll(/'(\d+)':/g, (x, y) => `${y}:`); - download(`${document.getElementById('player-name').value}.yaml`, yamlText); -}; +} /** Create an anchor and trigger a download of a text file. */ const download = (filename, text) => { @@ -1223,30 +1282,3 @@ const download = (filename, text) => { downloadLink.click(); document.body.removeChild(downloadLink); }; - -const generateGame = (raceMode = false) => { - const settings = validateSettings(); - if (!settings) { return; } - - axios.post('/api/generate', { - weights: { player: JSON.stringify(settings) }, - presetData: { player: JSON.stringify(settings) }, - playerCount: 1, - spoiler: 3, - race: raceMode ? '1' : '0', - }).then((response) => { - window.location.href = response.data.url; - }).catch((error) => { - const userMessage = document.getElementById('user-message'); - userMessage.innerText = 'Something went wrong and your game could not be generated.'; - if (error.response.data.text) { - userMessage.innerText += ' ' + error.response.data.text; - } - userMessage.classList.add('visible'); - userMessage.scrollIntoView({ - behavior: 'smooth', - block: 'start', - }); - console.error(error); - }); -}; From b707619aad6bf557559ad0a619cf716c51676747 Mon Sep 17 00:00:00 2001 From: Bryce Wilson Date: Wed, 18 Oct 2023 22:07:15 -0700 Subject: [PATCH 10/24] BizHawkClient: Add autostart setting (#2322) --- settings.py | 20 ++++++++++++++++++++ worlds/_bizhawk/context.py | 21 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/settings.py b/settings.py index a7dcbbf8ddbf..acae86095cda 100644 --- a/settings.py +++ b/settings.py @@ -694,6 +694,25 @@ class SnesRomStart(str): snes_rom_start: Union[SnesRomStart, bool] = True +class BizHawkClientOptions(Group): + class EmuHawkPath(UserFilePath): + """ + The location of the EmuHawk you want to auto launch patched ROMs with + """ + is_exe = True + description = "EmuHawk Executable" + + class RomStart(str): + """ + Set this to true to autostart a patched ROM in BizHawk with the connector script, + to false to never open the patched rom automatically, + or to a path to an external program to open the ROM file with that instead. + """ + + emuhawk_path: EmuHawkPath = EmuHawkPath(None) + rom_start: Union[RomStart, bool] = True + + # Top-level group with lazy loading of worlds class Settings(Group): @@ -701,6 +720,7 @@ class Settings(Group): server_options: ServerOptions = ServerOptions() generator: GeneratorOptions = GeneratorOptions() sni_options: SNIOptions = SNIOptions() + bizhawkclient_options: BizHawkClientOptions = BizHawkClientOptions() _filename: Optional[str] = None diff --git a/worlds/_bizhawk/context.py b/worlds/_bizhawk/context.py index 6e53b370af1c..465334274e8e 100644 --- a/worlds/_bizhawk/context.py +++ b/worlds/_bizhawk/context.py @@ -5,6 +5,7 @@ import asyncio +import subprocess import traceback from typing import Any, Dict, Optional @@ -146,8 +147,24 @@ async def _game_watcher(ctx: BizHawkClientContext): async def _run_game(rom: str): - import webbrowser - webbrowser.open(rom) + import os + auto_start = Utils.get_settings().bizhawkclient_options.rom_start + + if auto_start is True: + emuhawk_path = Utils.get_settings().bizhawkclient_options.emuhawk_path + subprocess.Popen([emuhawk_path, "--lua=data/lua/connector_bizhawk_generic.lua", os.path.realpath(rom)], + cwd=Utils.local_path("."), + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + elif isinstance(auto_start, str): + import shlex + + subprocess.Popen([*shlex.split(auto_start), os.path.realpath(rom)], + cwd=Utils.local_path("."), + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) async def _patch_and_run_game(patch_file: str): From fb6b66463da5235603abe01aa3110098376ce17d Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Thu, 19 Oct 2023 18:36:18 -0500 Subject: [PATCH 11/24] OC2: fix mistakes when moving to new options api (#2332) --- worlds/overcooked2/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worlds/overcooked2/__init__.py b/worlds/overcooked2/__init__.py index 2bf523b347c8..0451f32bdd49 100644 --- a/worlds/overcooked2/__init__.py +++ b/worlds/overcooked2/__init__.py @@ -172,7 +172,7 @@ def get_priority_locations(self) -> List[int]: # random priority locations have no desirable effect on solo seeds return list() - balancing_mode = self.get_options()["LocationBalancing"] + balancing_mode = self.options.location_balancing if balancing_mode == LocationBalancingMode.disabled: # Location balancing is disabled, progression density is purely determined by filler @@ -528,7 +528,7 @@ def kevin_level_to_keyholder_level_id(level_id: int) -> Optional[int]: # Game Modifications "LevelPurchaseRequirements": level_purchase_requirements, "Custom66TimerScale": max(0.4, 0.25 + (1.0 - star_threshold_scale)*0.6), - "ShortHordeLevels": self.options.short_horde_levels, + "ShortHordeLevels": self.options.short_horde_levels.result, "CustomLevelOrder": custom_level_order, # Items (Starting Inventory) @@ -584,6 +584,7 @@ def kevin_level_to_keyholder_level_id(level_id: int) -> Optional[int]: "TwoStars": star_threshold_scale * 0.75, "OneStar": star_threshold_scale * 0.35, } + base_data["AlwaysServeOldestOrder"] = self.options.always_serve_oldest_order.result return base_data From 385803eb5ce3b9df4ca5d9307e0d2046be7b3854 Mon Sep 17 00:00:00 2001 From: Justus Lind Date: Fri, 20 Oct 2023 10:13:17 +1000 Subject: [PATCH 12/24] Muse Dash: Add support for specifying specific DLCs (#2329) --- worlds/musedash/Items.py | 2 +- worlds/musedash/MuseDashCollection.py | 38 ++++++-- worlds/musedash/MuseDashData.txt | 94 ++++++++++++-------- worlds/musedash/Options.py | 52 ++++++----- worlds/musedash/__init__.py | 59 ++++++------ worlds/musedash/test/TestCollection.py | 17 +++- worlds/musedash/test/TestDifficultyRanges.py | 3 +- 7 files changed, 166 insertions(+), 99 deletions(-) diff --git a/worlds/musedash/Items.py b/worlds/musedash/Items.py index be229228bd40..63fd3aa51b94 100644 --- a/worlds/musedash/Items.py +++ b/worlds/musedash/Items.py @@ -6,7 +6,7 @@ class SongData(NamedTuple): """Special data container to contain the metadata of each song to make filtering work.""" code: Optional[int] - song_is_free: bool + album: str streamer_mode: bool easy: Optional[int] hard: Optional[int] diff --git a/worlds/musedash/MuseDashCollection.py b/worlds/musedash/MuseDashCollection.py index 7812e28b7a8c..1807dce2f937 100644 --- a/worlds/musedash/MuseDashCollection.py +++ b/worlds/musedash/MuseDashCollection.py @@ -1,5 +1,5 @@ from .Items import SongData, AlbumData -from typing import Dict, List, Optional +from typing import Dict, List, Set, Optional from collections import ChainMap @@ -15,13 +15,21 @@ class MuseDashCollections: MUSIC_SHEET_NAME: str = "Music Sheet" MUSIC_SHEET_CODE: int = STARTING_CODE - FREE_ALBUMS = [ + FREE_ALBUMS: List[str] = [ "Default Music", "Budget Is Burning: Nano Core", "Budget Is Burning Vol.1", ] - DIFF_OVERRIDES = [ + MUSE_PLUS_DLC: str = "Muse Plus" + DLC: List[str] = [ + # MUSE_PLUS_DLC, # To be included when OptionSets are rendered as part of basic settings. + # "maimai DX Limited-time Suite", # Part of Muse Plus. Goes away 31st Jan 2026. + "Miku in Museland", # Paid DLC not included in Muse Plus + "MSR Anthology", # Part of Muse Plus. Goes away 20th Jan 2024. + ] + + DIFF_OVERRIDES: List[str] = [ "MuseDash ka nanika hi", "Rush-Hour", "Find this Month's Featured Playlist", @@ -48,8 +56,8 @@ class MuseDashCollections: "Error SFX Trap": STARTING_CODE + 9, } - item_names_to_id = ChainMap({}, sfx_trap_items, vfx_trap_items) - location_names_to_id = ChainMap(song_locations, album_locations) + item_names_to_id: ChainMap = ChainMap({}, sfx_trap_items, vfx_trap_items) + location_names_to_id: ChainMap = ChainMap(song_locations, album_locations) def __init__(self) -> None: self.item_names_to_id[self.MUSIC_SHEET_NAME] = self.MUSIC_SHEET_CODE @@ -70,7 +78,6 @@ def __init__(self) -> None: # Data is in the format 'Song|UID|Album|StreamerMode|EasyDiff|HardDiff|MasterDiff|SecretDiff' song_name = sections[0] # [1] is used in the client copy to make sure item id's match. - song_is_free = album in self.FREE_ALBUMS steamer_mode = sections[3] == "True" if song_name in self.DIFF_OVERRIDES: @@ -84,7 +91,7 @@ def __init__(self) -> None: diff_of_hard = self.parse_song_difficulty(sections[5]) diff_of_master = self.parse_song_difficulty(sections[6]) - self.song_items[song_name] = SongData(item_id_index, song_is_free, steamer_mode, + self.song_items[song_name] = SongData(item_id_index, album, steamer_mode, diff_of_easy, diff_of_hard, diff_of_master) item_id_index += 1 @@ -102,13 +109,13 @@ def __init__(self) -> None: self.song_locations[f"{name}-1"] = location_id_index + 1 location_id_index += 2 - def get_songs_with_settings(self, dlc_songs: bool, streamer_mode_active: bool, + def get_songs_with_settings(self, dlc_songs: Set[str], streamer_mode_active: bool, diff_lower: int, diff_higher: int) -> List[str]: """Gets a list of all songs that match the filter settings. Difficulty thresholds are inclusive.""" filtered_list = [] for songKey, songData in self.song_items.items(): - if not dlc_songs and not songData.song_is_free: + if not self.song_matches_dlc_filter(songData, dlc_songs): continue if streamer_mode_active and not songData.streamer_mode: @@ -128,6 +135,19 @@ def get_songs_with_settings(self, dlc_songs: bool, streamer_mode_active: bool, return filtered_list + def song_matches_dlc_filter(self, song: SongData, dlc_songs: Set[str]) -> bool: + if song.album in self.FREE_ALBUMS: + return True + + if song.album in dlc_songs: + return True + + # Muse Plus provides access to any DLC not included as a seperate pack + if song.album not in self.DLC and self.MUSE_PLUS_DLC in dlc_songs: + return True + + return False + def parse_song_difficulty(self, difficulty: str) -> Optional[int]: """Attempts to parse the song difficulty.""" if len(difficulty) <= 0 or difficulty == "?" or difficulty == "¿": diff --git a/worlds/musedash/MuseDashData.txt b/worlds/musedash/MuseDashData.txt index 8d6c3f375314..bd07fef7af51 100644 --- a/worlds/musedash/MuseDashData.txt +++ b/worlds/musedash/MuseDashData.txt @@ -51,42 +51,42 @@ Mujinku-Vacuum|0-28|Default Music|False|5|7|11| MilK|0-36|Default Music|False|5|7|9| umpopoff|0-41|Default Music|False|0|?|0| Mopemope|0-45|Default Music|False|4|7|9|11 -The Happycore Idol|43-0|Just as Planned Plus|True|2|5|7| -Amatsumikaboshi|43-1|Just as Planned Plus|True|4|6|8|10 -ARIGA THESIS|43-2|Just as Planned Plus|True|3|6|10| -Night of Nights|43-3|Just as Planned Plus|False|4|7|10| -#Psychedelic_Meguro_River|43-4|Just as Planned Plus|False|3|6|8| -can you feel it|43-5|Just as Planned Plus|False|4|6|8|9 -Midnight O'clock|43-6|Just as Planned Plus|True|3|6|8| -Rin|43-7|Just as Planned Plus|True|5|7|10| -Smile-mileS|43-8|Just as Planned Plus|False|6|8|10| -Believing and Being|43-9|Just as Planned Plus|True|4|6|9| -Catalyst|43-10|Just as Planned Plus|False|5|7|9| -don't!stop!eroero!|43-11|Just as Planned Plus|True|5|7|9| -pa pi pu pi pu pi pa|43-12|Just as Planned Plus|False|6|8|10| -Sand Maze|43-13|Just as Planned Plus|True|6|8|10|11 -Diffraction|43-14|Just as Planned Plus|True|5|8|10| -AKUMU|43-15|Just as Planned Plus|False|4|6|8| -Queen Aluett|43-16|Just as Planned Plus|True|7|9|11| -DROPS|43-17|Just as Planned Plus|False|2|5|8| -Frightfully-insane Flan-chan's frightful song|43-18|Just as Planned Plus|False|5|7|10| -snooze|43-19|Just as Planned Plus|False|5|7|10| -Kuishinbo Hacker feat.Kuishinbo Akachan|43-20|Just as Planned Plus|True|5|7|9| -Inu no outa|43-21|Just as Planned Plus|True|3|5|7| -Prism Fountain|43-22|Just as Planned Plus|True|7|9|11| -Gospel|43-23|Just as Planned Plus|False|4|6|9| +The Happycore Idol|43-0|MD Plus Project|True|2|5|7| +Amatsumikaboshi|43-1|MD Plus Project|True|4|6|8|10 +ARIGA THESIS|43-2|MD Plus Project|True|3|6|10| +Night of Nights|43-3|MD Plus Project|False|4|7|10| +#Psychedelic_Meguro_River|43-4|MD Plus Project|False|3|6|8| +can you feel it|43-5|MD Plus Project|False|4|6|8|9 +Midnight O'clock|43-6|MD Plus Project|True|3|6|8| +Rin|43-7|MD Plus Project|True|5|7|10| +Smile-mileS|43-8|MD Plus Project|False|6|8|10| +Believing and Being|43-9|MD Plus Project|True|4|6|9| +Catalyst|43-10|MD Plus Project|False|5|7|9| +don't!stop!eroero!|43-11|MD Plus Project|True|5|7|9| +pa pi pu pi pu pi pa|43-12|MD Plus Project|False|6|8|10| +Sand Maze|43-13|MD Plus Project|True|6|8|10|11 +Diffraction|43-14|MD Plus Project|True|5|8|10| +AKUMU|43-15|MD Plus Project|False|4|6|8| +Queen Aluett|43-16|MD Plus Project|True|7|9|11| +DROPS|43-17|MD Plus Project|False|2|5|8| +Frightfully-insane Flan-chan's frightful song|43-18|MD Plus Project|False|5|7|10| +snooze|43-19|MD Plus Project|False|5|7|10| +Kuishinbo Hacker feat.Kuishinbo Akachan|43-20|MD Plus Project|True|5|7|9| +Inu no outa|43-21|MD Plus Project|True|3|5|7| +Prism Fountain|43-22|MD Plus Project|True|7|9|11| +Gospel|43-23|MD Plus Project|False|4|6|9| East Ai Li Lovely|62-0|Happy Otaku Pack Vol.17|False|2|4|7| Mori Umi no Fune|62-1|Happy Otaku Pack Vol.17|True|5|7|9| Ooi|62-2|Happy Otaku Pack Vol.17|True|5|7|10| Numatta!!|62-3|Happy Otaku Pack Vol.17|True|5|7|9| -SATELLITE|62-4|Happy Otaku Pack Vol.17|False|5|7|9| +SATELLITE|62-4|Happy Otaku Pack Vol.17|False|5|7|9|10 Fantasia Sonata Colorful feat. V!C|62-5|Happy Otaku Pack Vol.17|True|6|8|11| MuseDash ka nanika hi|61-0|Ola Dash|True|?|?|¿| Aleph-0|61-1|Ola Dash|True|7|9|11| Buttoba Supernova|61-2|Ola Dash|False|5|7|10|11 Rush-Hour|61-3|Ola Dash|False|IG|Jh|a2|Eh 3rd Avenue|61-4|Ola Dash|False|3|5|〇| -WORLDINVADER|61-5|Ola Dash|True|5|8|10| +WORLDINVADER|61-5|Ola Dash|True|5|8|10|11 N3V3R G3T OV3R|60-0|maimai DX Limited-time Suite|True|4|7|10| Oshama Scramble!|60-1|maimai DX Limited-time Suite|True|5|7|10| Valsqotch|60-2|maimai DX Limited-time Suite|True|5|9|11| @@ -450,13 +450,13 @@ Love Patrol|63-2|MUSE RADIO FM104|True|3|5|7| Mahorova|63-3|MUSE RADIO FM104|True|3|5|8| Yoru no machi|63-4|MUSE RADIO FM104|True|1|4|7| INTERNET YAMERO|63-5|MUSE RADIO FM104|True|6|8|10| -Abracadabra|43-24|Just as Planned Plus|False|6|8|10| -Squalldecimator feat. EZ-Ven|43-25|Just as Planned Plus|True|5|7|9| -Amateras Rhythm|43-26|Just as Planned Plus|True|6|8|11| -Record one's Dream|43-27|Just as Planned Plus|False|4|7|10| -Lunatic|43-28|Just as Planned Plus|True|5|8|10| -Jiumeng|43-29|Just as Planned Plus|True|3|6|8| -The Day We Become Family|43-30|Just as Planned Plus|True|3|5|8| +Abracadabra|43-24|MD Plus Project|False|6|8|10| +Squalldecimator feat. EZ-Ven|43-25|MD Plus Project|True|5|7|9| +Amateras Rhythm|43-26|MD Plus Project|True|6|8|11| +Record one's Dream|43-27|MD Plus Project|False|4|7|10| +Lunatic|43-28|MD Plus Project|True|5|8|10| +Jiumeng|43-29|MD Plus Project|True|3|6|8| +The Day We Become Family|43-30|MD Plus Project|True|3|5|8| Sutori ma FIRE!?!?|64-0|COSMIC RADIO PEROLIST|True|3|5|8| Tanuki Step|64-1|COSMIC RADIO PEROLIST|True|5|7|10|11 Space Stationery|64-2|COSMIC RADIO PEROLIST|True|5|7|10| @@ -465,7 +465,27 @@ Kawai Splendid Space Thief|64-4|COSMIC RADIO PEROLIST|False|6|8|10|11 Night City Runway|64-5|COSMIC RADIO PEROLIST|True|4|6|8| Chaos Shotgun feat. ChumuNote|64-6|COSMIC RADIO PEROLIST|True|6|8|10| mew mew magical summer|64-7|COSMIC RADIO PEROLIST|False|5|8|10|11 -BrainDance|65-0|Neon Abyss|True|3|6|9| -My Focus!|65-1|Neon Abyss|True|5|7|10| -ABABABA BURST|65-2|Neon Abyss|True|5|7|9| -ULTRA HIGHER|65-3|Neon Abyss|True|4|7|10| \ No newline at end of file +BrainDance|65-0|NeonAbyss|True|3|6|9| +My Focus!|65-1|NeonAbyss|True|5|7|10| +ABABABA BURST|65-2|NeonAbyss|True|5|7|9| +ULTRA HIGHER|65-3|NeonAbyss|True|4|7|10| +Silver Bullet|43-31|MD Plus Project|True|5|7|10| +Random|43-32|MD Plus Project|True|4|7|9| +OTOGE-BOSS-KYOKU-CHAN|43-33|MD Plus Project|False|6|8|10|11 +Crow Rabbit|43-34|MD Plus Project|True|7|9|11| +SyZyGy|43-35|MD Plus Project|True|6|8|10|11 +Mermaid Radio|43-36|MD Plus Project|True|3|5|7| +Helixir|43-37|MD Plus Project|False|6|8|10| +Highway Cruisin'|43-38|MD Plus Project|False|3|5|8| +JACK PT BOSS|43-39|MD Plus Project|False|6|8|10| +Time Capsule|43-40|MD Plus Project|False|7|9|11| +39 Music!|66-0|Miku in Museland|False|3|5|8| +Hand in Hand|66-1|Miku in Museland|False|1|3|6| +Cynical Night Plan|66-2|Miku in Museland|False|4|6|8| +God-ish|66-3|Miku in Museland|False|4|7|10| +Darling Dance|66-4|Miku in Museland|False|4|7|9| +Hatsune Creation Myth|66-5|Miku in Museland|False|6|8|10| +The Vampire|66-6|Miku in Museland|False|4|6|9| +Future Eve|66-7|Miku in Museland|False|4|8|11| +Unknown Mother Goose|66-8|Miku in Museland|False|4|8|10| +Shun-ran|66-9|Miku in Museland|False|4|7|9| \ No newline at end of file diff --git a/worlds/musedash/Options.py b/worlds/musedash/Options.py index b2f15ecc8e6c..3fe28187fae6 100644 --- a/worlds/musedash/Options.py +++ b/worlds/musedash/Options.py @@ -1,10 +1,19 @@ from typing import Dict -from Options import Toggle, Option, Range, Choice, DeathLink, ItemSet +from Options import Toggle, Option, Range, Choice, DeathLink, ItemSet, OptionSet, PerGameCommonOptions +from dataclasses import dataclass +from .MuseDashCollection import MuseDashCollections class AllowJustAsPlannedDLCSongs(Toggle): - """Whether [Just as Planned]/[Muse Plus] DLC Songs, and all the DLCs along with it, will be included in the randomizer.""" - display_name = "Allow [Just as Planned]/[Muse Plus] DLC Songs" + """Whether [Muse Plus] DLC Songs, and all the albums included in it, can be chosen as randomised songs. + Note: The [Just As Planned] DLC contains all [Muse Plus] songs.""" + display_name = "Allow [Muse Plus] DLC Songs" + +class DLCMusicPacks(OptionSet): + """Which non-[Muse Plus] DLC packs can be chosen as randomised songs.""" + display_name = "DLC Packs" + default = {} + valid_keys = [dlc for dlc in MuseDashCollections.DLC] class StreamerModeEnabled(Toggle): @@ -159,21 +168,22 @@ class ExcludeSongs(ItemSet): display_name = "Exclude Songs" -musedash_options: Dict[str, type(Option)] = { - "allow_just_as_planned_dlc_songs": AllowJustAsPlannedDLCSongs, - "streamer_mode_enabled": StreamerModeEnabled, - "starting_song_count": StartingSongs, - "additional_song_count": AdditionalSongs, - "additional_item_percentage": AdditionalItemPercentage, - "song_difficulty_mode": DifficultyMode, - "song_difficulty_min": DifficultyModeOverrideMin, - "song_difficulty_max": DifficultyModeOverrideMax, - "grade_needed": GradeNeeded, - "music_sheet_count_percentage": MusicSheetCountPercentage, - "music_sheet_win_count_percentage": MusicSheetWinCountPercentage, - "available_trap_types": TrapTypes, - "trap_count_percentage": TrapCountPercentage, - "death_link": DeathLink, - "include_songs": IncludeSongs, - "exclude_songs": ExcludeSongs -} +@dataclass +class MuseDashOptions(PerGameCommonOptions): + allow_just_as_planned_dlc_songs: AllowJustAsPlannedDLCSongs + dlc_packs: DLCMusicPacks + streamer_mode_enabled: StreamerModeEnabled + starting_song_count: StartingSongs + additional_song_count: AdditionalSongs + additional_item_percentage: AdditionalItemPercentage + song_difficulty_mode: DifficultyMode + song_difficulty_min: DifficultyModeOverrideMin + song_difficulty_max: DifficultyModeOverrideMax + grade_needed: GradeNeeded + music_sheet_count_percentage: MusicSheetCountPercentage + music_sheet_win_count_percentage: MusicSheetWinCountPercentage + available_trap_types: TrapTypes + trap_count_percentage: TrapCountPercentage + death_link: DeathLink + include_songs: IncludeSongs + exclude_songs: ExcludeSongs diff --git a/worlds/musedash/__init__.py b/worlds/musedash/__init__.py index 754d2352e03e..63ce123c93d3 100644 --- a/worlds/musedash/__init__.py +++ b/worlds/musedash/__init__.py @@ -1,10 +1,10 @@ from worlds.AutoWorld import World, WebWorld -from worlds.generic.Rules import set_rule from BaseClasses import Region, Item, ItemClassification, Entrance, Tutorial -from typing import List +from typing import List, ClassVar, Type from math import floor +from Options import PerGameCommonOptions -from .Options import musedash_options +from .Options import MuseDashOptions from .Items import MuseDashSongItem, MuseDashFixedItem from .Locations import MuseDashLocation from .MuseDashCollection import MuseDashCollections @@ -47,9 +47,9 @@ class MuseDashWorld(World): # World Options game = "Muse Dash" - option_definitions = musedash_options + options_dataclass: ClassVar[Type[PerGameCommonOptions]] = MuseDashOptions topology_present = False - data_version = 9 + data_version = 10 web = MuseDashWebWorld() # Necessary Data @@ -66,14 +66,17 @@ class MuseDashWorld(World): location_count: int def generate_early(self): - dlc_songs = self.multiworld.allow_just_as_planned_dlc_songs[self.player] - streamer_mode = self.multiworld.streamer_mode_enabled[self.player] + dlc_songs = {key for key in self.options.dlc_packs.value} + if (self.options.allow_just_as_planned_dlc_songs.value): + dlc_songs.add(self.md_collection.MUSE_PLUS_DLC) + + streamer_mode = self.options.streamer_mode_enabled (lower_diff_threshold, higher_diff_threshold) = self.get_difficulty_range() # The minimum amount of songs to make an ok rando would be Starting Songs + 10 interim songs + Goal song. # - Interim songs being equal to max starting song count. # Note: The worst settings still allow 25 songs (Streamer Mode + No DLC). - starter_song_count = self.multiworld.starting_song_count[self.player].value + starter_song_count = self.options.starting_song_count.value while True: # In most cases this should only need to run once @@ -104,9 +107,9 @@ def generate_early(self): def handle_plando(self, available_song_keys: List[str]) -> List[str]: song_items = self.md_collection.song_items - start_items = self.multiworld.start_inventory[self.player].value.keys() - include_songs = self.multiworld.include_songs[self.player].value - exclude_songs = self.multiworld.exclude_songs[self.player].value + start_items = self.options.start_inventory.value.keys() + include_songs = self.options.include_songs.value + exclude_songs = self.options.exclude_songs.value self.starting_songs = [s for s in start_items if s in song_items] self.included_songs = [s for s in include_songs if s in song_items and s not in self.starting_songs] @@ -115,8 +118,8 @@ def handle_plando(self, available_song_keys: List[str]) -> List[str]: and s not in include_songs and s not in exclude_songs] def create_song_pool(self, available_song_keys: List[str]): - starting_song_count = self.multiworld.starting_song_count[self.player].value - additional_song_count = self.multiworld.additional_song_count[self.player].value + starting_song_count = self.options.starting_song_count.value + additional_song_count = self.options.additional_song_count.value self.random.shuffle(available_song_keys) @@ -150,7 +153,7 @@ def create_song_pool(self, available_song_keys: List[str]): # Then attempt to fufill any remaining songs for interim songs if len(self.included_songs) < additional_song_count: - for _ in range(len(self.included_songs), self.multiworld.additional_song_count[self.player]): + for _ in range(len(self.included_songs), self.options.additional_song_count): if len(available_song_keys) <= 0: break self.included_songs.append(available_song_keys.pop()) @@ -258,40 +261,40 @@ def set_rules(self) -> None: state.has(self.md_collection.MUSIC_SHEET_NAME, self.player, self.get_music_sheet_win_count()) def get_available_traps(self) -> List[str]: - dlc_songs = self.multiworld.allow_just_as_planned_dlc_songs[self.player] + sfx_traps_available = self.options.allow_just_as_planned_dlc_songs.value trap_list = [] - if self.multiworld.available_trap_types[self.player].value & 1 != 0: + if self.options.available_trap_types.value & 1 != 0: trap_list += self.md_collection.vfx_trap_items.keys() # SFX options are only available under Just as Planned DLC. - if dlc_songs and self.multiworld.available_trap_types[self.player].value & 2 != 0: + if sfx_traps_available and self.options.available_trap_types.value & 2 != 0: trap_list += self.md_collection.sfx_trap_items.keys() return trap_list def get_additional_item_percentage(self) -> int: - trap_count = self.multiworld.trap_count_percentage[self.player].value - song_count = self.multiworld.music_sheet_count_percentage[self.player].value - return max(trap_count + song_count, self.multiworld.additional_item_percentage[self.player].value) + trap_count = self.options.trap_count_percentage.value + song_count = self.options.music_sheet_count_percentage.value + return max(trap_count + song_count, self.options.additional_item_percentage.value) def get_trap_count(self) -> int: - multiplier = self.multiworld.trap_count_percentage[self.player].value / 100.0 + multiplier = self.options.trap_count_percentage.value / 100.0 trap_count = (len(self.starting_songs) * 2) + len(self.included_songs) return max(0, floor(trap_count * multiplier)) def get_music_sheet_count(self) -> int: - multiplier = self.multiworld.music_sheet_count_percentage[self.player].value / 100.0 + multiplier = self.options.music_sheet_count_percentage.value / 100.0 song_count = (len(self.starting_songs) * 2) + len(self.included_songs) return max(1, floor(song_count * multiplier)) def get_music_sheet_win_count(self) -> int: - multiplier = self.multiworld.music_sheet_win_count_percentage[self.player].value / 100.0 + multiplier = self.options.music_sheet_win_count_percentage.value / 100.0 sheet_count = self.get_music_sheet_count() return max(1, floor(sheet_count * multiplier)) def get_difficulty_range(self) -> List[int]: - difficulty_mode = self.multiworld.song_difficulty_mode[self.player] + difficulty_mode = self.options.song_difficulty_mode # Valid difficulties are between 1 and 11. But make it 0 to 12 for safety difficulty_bounds = [0, 12] @@ -309,8 +312,8 @@ def get_difficulty_range(self) -> List[int]: elif difficulty_mode == 5: difficulty_bounds[0] = 10 elif difficulty_mode == 6: - minimum_difficulty = self.multiworld.song_difficulty_min[self.player].value - maximum_difficulty = self.multiworld.song_difficulty_max[self.player].value + minimum_difficulty = self.options.song_difficulty_min.value + maximum_difficulty = self.options.song_difficulty_max.value difficulty_bounds[0] = min(minimum_difficulty, maximum_difficulty) difficulty_bounds[1] = max(minimum_difficulty, maximum_difficulty) @@ -320,7 +323,7 @@ def get_difficulty_range(self) -> List[int]: def fill_slot_data(self): return { "victoryLocation": self.victory_song_name, - "deathLink": self.multiworld.death_link[self.player].value, + "deathLink": self.options.death_link.value, "musicSheetWinCount": self.get_music_sheet_win_count(), - "gradeNeeded": self.multiworld.grade_needed[self.player].value + "gradeNeeded": self.options.grade_needed.value } diff --git a/worlds/musedash/test/TestCollection.py b/worlds/musedash/test/TestCollection.py index 23348af104b5..f9422388ae1e 100644 --- a/worlds/musedash/test/TestCollection.py +++ b/worlds/musedash/test/TestCollection.py @@ -36,14 +36,27 @@ def test_ids_dont_change(self) -> None: def test_free_dlc_included_in_base_songs(self) -> None: collection = MuseDashCollections() - songs = collection.get_songs_with_settings(False, False, 0, 11) + songs = collection.get_songs_with_settings(set(), False, 0, 12) self.assertIn("Glimmer", songs, "Budget Is Burning Vol.1 is not being included in base songs") self.assertIn("Out of Sense", songs, "Budget Is Burning: Nano Core is not being included in base songs") + def test_dlcs(self) -> None: + collection = MuseDashCollections() + free_song_count = len(collection.get_songs_with_settings(set(), False, 0, 12)) + known_mp_song = "The Happycore Idol" + + for dlc in collection.DLC: + songs_with_dlc = collection.get_songs_with_settings({dlc}, False, 0, 12) + self.assertGreater(len(songs_with_dlc), free_song_count, f"DLC {dlc} did not include extra songs.") + if dlc == collection.MUSE_PLUS_DLC: + self.assertIn(known_mp_song, songs_with_dlc, f"Muse Plus missing muse plus song.") + else: + self.assertNotIn(known_mp_song, songs_with_dlc, f"DLC {dlc} includes Muse Plus songs.") + def test_remove_songs_are_not_generated(self) -> None: collection = MuseDashCollections() - songs = collection.get_songs_with_settings(True, False, 0, 11) + songs = collection.get_songs_with_settings({x for x in collection.DLC}, False, 0, 12) for song_name in self.REMOVED_SONGS: self.assertNotIn(song_name, songs, f"Song '{song_name}' wasn't removed correctly.") diff --git a/worlds/musedash/test/TestDifficultyRanges.py b/worlds/musedash/test/TestDifficultyRanges.py index 58817d0fc3ef..01420347af15 100644 --- a/worlds/musedash/test/TestDifficultyRanges.py +++ b/worlds/musedash/test/TestDifficultyRanges.py @@ -4,6 +4,7 @@ class DifficultyRanges(MuseDashTestBase): def test_all_difficulty_ranges(self) -> None: muse_dash_world = self.multiworld.worlds[1] + dlc_set = {x for x in muse_dash_world.md_collection.DLC} difficulty_choice = self.multiworld.song_difficulty_mode[1] difficulty_min = self.multiworld.song_difficulty_min[1] difficulty_max = self.multiworld.song_difficulty_max[1] @@ -12,7 +13,7 @@ def test_range(inputRange, lower, upper): self.assertEqual(inputRange[0], lower) self.assertEqual(inputRange[1], upper) - songs = muse_dash_world.md_collection.get_songs_with_settings(True, False, inputRange[0], inputRange[1]) + songs = muse_dash_world.md_collection.get_songs_with_settings(dlc_set, False, inputRange[0], inputRange[1]) for songKey in songs: song = muse_dash_world.md_collection.song_items[songKey] if (song.easy is not None and inputRange[0] <= song.easy <= inputRange[1]): From b82f48fe4b408ccfd66c9eb3f1eaefda19fb665b Mon Sep 17 00:00:00 2001 From: espeon65536 <81029175+espeon65536@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:23:32 -0600 Subject: [PATCH 13/24] Core: guard against plandoing items onto event locations (#2284) --- Fill.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Fill.py b/Fill.py index 600d18ef2a55..94528a307f64 100644 --- a/Fill.py +++ b/Fill.py @@ -897,19 +897,22 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: for item_name in items: item = world.worlds[player].create_item(item_name) for location in reversed(candidates): - if not location.item: - if location.item_rule(item): - if location.can_fill(world.state, item, False): - successful_pairs.append((item, location)) - candidates.remove(location) - count = count + 1 - break + if (location.address is None) == (item.code is None): # either both None or both not None + if not location.item: + if location.item_rule(item): + if location.can_fill(world.state, item, False): + successful_pairs.append((item, location)) + candidates.remove(location) + count = count + 1 + break + else: + err.append(f"Can't place item at {location} due to fill condition not met.") else: - err.append(f"Can't place item at {location} due to fill condition not met.") + err.append(f"{item_name} not allowed at {location}.") else: - err.append(f"{item_name} not allowed at {location}.") + err.append(f"Cannot place {item_name} into already filled location {location}.") else: - err.append(f"Cannot place {item_name} into already filled location {location}.") + err.append(f"Mismatch between {item_name} and {location}, only one is an event.") if count == maxcount: break if count < placement['count']['min']: From 56796b7ee8b0177c1387657152865c7909037886 Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Fri, 20 Oct 2023 02:58:41 +0200 Subject: [PATCH 14/24] WebHost: minor css changes to make Supported Games page usable without js (#2266) * WebHost: minor css changes to make Supported Games page usable without js * Update JS to use querySelectorAll, remove most id attributes from elements, use relative element selectors * Hide content when clearing search bar * Remove `console.log`, remove TODO --------- Co-authored-by: Chris Wilson --- WebHostLib/static/assets/supportedGames.js | 87 ++++++++------------- WebHostLib/static/styles/supportedGames.css | 12 ++- WebHostLib/templates/supportedGames.html | 28 ++++++- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/WebHostLib/static/assets/supportedGames.js b/WebHostLib/static/assets/supportedGames.js index 1acf0e0cc5ac..56eb15b5e580 100644 --- a/WebHostLib/static/assets/supportedGames.js +++ b/WebHostLib/static/assets/supportedGames.js @@ -1,51 +1,32 @@ window.addEventListener('load', () => { - const gameHeaders = document.getElementsByClassName('collapse-toggle'); - Array.from(gameHeaders).forEach((header) => { - const gameName = header.getAttribute('data-game'); - header.addEventListener('click', () => { - const gameArrow = document.getElementById(`${gameName}-arrow`); - const gameInfo = document.getElementById(gameName); - if (gameInfo.classList.contains('collapsed')) { - gameArrow.innerText = '▼'; - gameInfo.classList.remove('collapsed'); - } else { - gameArrow.innerText = '▶'; - gameInfo.classList.add('collapsed'); - } - }); - }); + // Add toggle listener to all elements with .collapse-toggle + const toggleButtons = document.querySelectorAll('.collapse-toggle'); + toggleButtons.forEach((e) => e.addEventListener('click', toggleCollapse)); // Handle game filter input const gameSearch = document.getElementById('game-search'); gameSearch.value = ''; - gameSearch.addEventListener('input', (evt) => { if (!evt.target.value.trim()) { // If input is empty, display all collapsed games - return Array.from(gameHeaders).forEach((header) => { + return toggleButtons.forEach((header) => { header.style.display = null; - const gameName = header.getAttribute('data-game'); - document.getElementById(`${gameName}-arrow`).innerText = '▶'; - document.getElementById(gameName).classList.add('collapsed'); + header.firstElementChild.innerText = '▶'; + header.nextElementSibling.classList.add('collapsed'); }); } // Loop over all the games - Array.from(gameHeaders).forEach((header) => { - const gameName = header.getAttribute('data-game'); - const gameArrow = document.getElementById(`${gameName}-arrow`); - const gameInfo = document.getElementById(gameName); - + toggleButtons.forEach((header) => { // If the game name includes the search string, display the game. If not, hide it - if (gameName.toLowerCase().includes(evt.target.value.toLowerCase())) { + if (header.getAttribute('data-game').toLowerCase().includes(evt.target.value.toLowerCase())) { header.style.display = null; - gameArrow.innerText = '▼'; - gameInfo.classList.remove('collapsed'); + header.firstElementChild.innerText = '▼'; + header.nextElementSibling.classList.remove('collapsed'); } else { - console.log(header); header.style.display = 'none'; - gameArrow.innerText = '▶'; - gameInfo.classList.add('collapsed'); + header.firstElementChild.innerText = '▶'; + header.nextElementSibling.classList.add('collapsed'); } }); }); @@ -54,30 +35,30 @@ window.addEventListener('load', () => { document.getElementById('collapse-all').addEventListener('click', collapseAll); }); -const expandAll = () => { - const gameHeaders = document.getElementsByClassName('collapse-toggle'); - // Loop over all the games - Array.from(gameHeaders).forEach((header) => { - const gameName = header.getAttribute('data-game'); - const gameArrow = document.getElementById(`${gameName}-arrow`); - const gameInfo = document.getElementById(gameName); +const toggleCollapse = (evt) => { + const gameArrow = evt.target.firstElementChild; + const gameInfo = evt.target.nextElementSibling; + if (gameInfo.classList.contains('collapsed')) { + gameArrow.innerText = '▼'; + gameInfo.classList.remove('collapsed'); + } else { + gameArrow.innerText = '▶'; + gameInfo.classList.add('collapsed'); + } +}; - if (header.style.display === 'none') { return; } - gameArrow.innerText = '▼'; - gameInfo.classList.remove('collapsed'); - }); +const expandAll = () => { + document.querySelectorAll('.collapse-toggle').forEach((header) => { + if (header.style.display === 'none') { return; } + header.firstElementChild.innerText = '▼'; + header.nextElementSibling.classList.remove('collapsed'); + }); }; const collapseAll = () => { - const gameHeaders = document.getElementsByClassName('collapse-toggle'); - // Loop over all the games - Array.from(gameHeaders).forEach((header) => { - const gameName = header.getAttribute('data-game'); - const gameArrow = document.getElementById(`${gameName}-arrow`); - const gameInfo = document.getElementById(gameName); - - if (header.style.display === 'none') { return; } - gameArrow.innerText = '▶'; - gameInfo.classList.add('collapsed'); - }); + document.querySelectorAll('.collapse-toggle').forEach((header) => { + if (header.style.display === 'none') { return; } + header.firstElementChild.innerText = '▶'; + header.nextElementSibling.classList.add('collapsed'); + }); }; diff --git a/WebHostLib/static/styles/supportedGames.css b/WebHostLib/static/styles/supportedGames.css index 1e9a98c17a0e..7396daa95404 100644 --- a/WebHostLib/static/styles/supportedGames.css +++ b/WebHostLib/static/styles/supportedGames.css @@ -18,10 +18,16 @@ margin-bottom: 2px; } +#games .collapse-toggle{ + cursor: pointer; +} + #games h2 .collapse-arrow{ font-size: 20px; + display: inline-block; /* make vertical-align work */ + padding-bottom: 9px; vertical-align: middle; - cursor: pointer; + padding-right: 8px; } #games p.collapsed{ @@ -42,12 +48,12 @@ margin-bottom: 7px; } -#games #page-controls{ +#games .page-controls{ display: flex; flex-direction: row; margin-top: 0.25rem; } -#games #page-controls button{ +#games .page-controls button{ margin-left: 0.5rem; } diff --git a/WebHostLib/templates/supportedGames.html b/WebHostLib/templates/supportedGames.html index 63b70216d705..f1514d83535d 100644 --- a/WebHostLib/templates/supportedGames.html +++ b/WebHostLib/templates/supportedGames.html @@ -5,15 +5,35 @@ + {% endblock %} {% block body %} {% include 'header/oceanHeader.html' %}

Currently Supported Games

-
+

-
+
@@ -22,9 +42,9 @@

Currently Supported Games

{% for game_name in worlds | title_sorted %} {% set world = worlds[game_name] %}

-  {{ game_name }} + {{ game_name }}

-

Verification Results

{% endfor %} + {% if combined_yaml %} +

Combined File Download

+

Download

+ {% endif %}
{% endblock %} diff --git a/worlds/alttp/docs/multiworld_de.md b/worlds/alttp/docs/multiworld_de.md index 38009fb58ed3..8ccd1a87a6b7 100644 --- a/worlds/alttp/docs/multiworld_de.md +++ b/worlds/alttp/docs/multiworld_de.md @@ -67,7 +67,7 @@ Wenn du eine Option nicht gewählt haben möchtest, setze ihren Wert einfach auf ### Überprüfung deiner YAML-Datei -Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/mysterycheck) Seite +Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/check) Seite tun. ## ein Einzelspielerspiel erstellen diff --git a/worlds/alttp/docs/multiworld_es.md b/worlds/alttp/docs/multiworld_es.md index 8576318bb997..37aeda2a63e5 100644 --- a/worlds/alttp/docs/multiworld_es.md +++ b/worlds/alttp/docs/multiworld_es.md @@ -82,7 +82,7 @@ debe tener al menos un valor mayor que cero, si no la generación fallará. ### Verificando tu archivo YAML Si quieres validar que tu fichero YAML para asegurarte que funciona correctamente, puedes hacerlo en la pagina -[YAML Validator](/mysterycheck). +[YAML Validator](/check). ## Generar una partida para un jugador diff --git a/worlds/alttp/docs/multiworld_fr.md b/worlds/alttp/docs/multiworld_fr.md index 329ca6537573..078a270f08b9 100644 --- a/worlds/alttp/docs/multiworld_fr.md +++ b/worlds/alttp/docs/multiworld_fr.md @@ -83,7 +83,7 @@ chaque paramètre il faut au moins une option qui soit paramétrée sur un nombr ### Vérifier son fichier YAML Si vous voulez valider votre fichier YAML pour être sûr qu'il fonctionne, vous pouvez le vérifier sur la page du -[Validateur de YAML](/mysterycheck). +[Validateur de YAML](/check). ## Générer une partie pour un joueur diff --git a/worlds/dkc3/docs/setup_en.md b/worlds/dkc3/docs/setup_en.md index bb1075630016..9c4197286eb9 100644 --- a/worlds/dkc3/docs/setup_en.md +++ b/worlds/dkc3/docs/setup_en.md @@ -50,7 +50,7 @@ them. Player settings page: [Donkey Kong Country 3 Player Settings Page](/games/ ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/factorio/docs/setup_en.md b/worlds/factorio/docs/setup_en.md index 09ad431a21cc..b6d45459253a 100644 --- a/worlds/factorio/docs/setup_en.md +++ b/worlds/factorio/docs/setup_en.md @@ -31,7 +31,7 @@ them. Factorio player settings page: [Factorio Settings Page](/games/Factorio/pl ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -Validator page: [Yaml Validation Page](/mysterycheck) +Validator page: [Yaml Validation Page](/check) ## Connecting to Someone Else's Factorio Game diff --git a/worlds/generic/docs/setup_en.md b/worlds/generic/docs/setup_en.md index 132b88e28553..93ae217e0d33 100644 --- a/worlds/generic/docs/setup_en.md +++ b/worlds/generic/docs/setup_en.md @@ -40,7 +40,7 @@ game you will be playing as well as the settings you would like for that game. YAML is a format very similar to JSON however it is made to be more human-readable. If you are ever unsure of the validity of your YAML file you may check the file by uploading it to the check page on the Archipelago website: -[YAML Validation Page](/mysterycheck) +[YAML Validation Page](/check) ### Creating a YAML diff --git a/worlds/ladx/docs/setup_en.md b/worlds/ladx/docs/setup_en.md index 538d70d45e4a..e21c5bddc489 100644 --- a/worlds/ladx/docs/setup_en.md +++ b/worlds/ladx/docs/setup_en.md @@ -40,7 +40,7 @@ your personal settings and export a config file from them. ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the -[YAML Validator](/mysterycheck) page. +[YAML Validator](/check) page. ## Generating a Single-Player Game diff --git a/worlds/lufia2ac/docs/setup_en.md b/worlds/lufia2ac/docs/setup_en.md index 4236c26e8a70..3762f32fb4a8 100644 --- a/worlds/lufia2ac/docs/setup_en.md +++ b/worlds/lufia2ac/docs/setup_en.md @@ -44,7 +44,7 @@ your personal settings and export a config file from them. ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the -[YAML Validator](/mysterycheck) page. +[YAML Validator](/check) page. ## Generating a Single-Player Game diff --git a/worlds/sm/docs/multiworld_en.md b/worlds/sm/docs/multiworld_en.md index ce91e7a7e403..129150774341 100644 --- a/worlds/sm/docs/multiworld_en.md +++ b/worlds/sm/docs/multiworld_en.md @@ -49,7 +49,7 @@ them. Player settings page: [Super Metroid Player Settings Page](/games/Super%20 ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/smw/docs/setup_en.md b/worlds/smw/docs/setup_en.md index 9ca8bdf58a16..3967f544a056 100644 --- a/worlds/smw/docs/setup_en.md +++ b/worlds/smw/docs/setup_en.md @@ -50,7 +50,7 @@ them. Player settings page: [Super Mario World Player Settings Page](/games/Supe ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Joining a MultiWorld Game diff --git a/worlds/smz3/docs/multiworld_en.md b/worlds/smz3/docs/multiworld_en.md index da6e29ab6923..53842a3c6fa4 100644 --- a/worlds/smz3/docs/multiworld_en.md +++ b/worlds/smz3/docs/multiworld_en.md @@ -47,7 +47,7 @@ them. Player settings page: [SMZ3 Player Settings Page](/games/SMZ3/player-setti ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/soe/docs/multiworld_en.md b/worlds/soe/docs/multiworld_en.md index d995cea56ae9..58b9aabf6a9a 100644 --- a/worlds/soe/docs/multiworld_en.md +++ b/worlds/soe/docs/multiworld_en.md @@ -29,7 +29,7 @@ them. Player settings page: [Secret of Evermore Player Settings PAge](/games/Sec ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator -page: [YAML Validation page](/mysterycheck) +page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/tloz/docs/multiworld_en.md b/worlds/tloz/docs/multiworld_en.md index 581e8cf7b24e..ae53d953b14b 100644 --- a/worlds/tloz/docs/multiworld_en.md +++ b/worlds/tloz/docs/multiworld_en.md @@ -44,7 +44,7 @@ them. Player settings page: [The Legend of Zelda Player Settings Page](/games/Th ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/zillion/docs/setup_en.md b/worlds/zillion/docs/setup_en.md index 16000dbe3b7a..22dee5ee55e6 100644 --- a/worlds/zillion/docs/setup_en.md +++ b/worlds/zillion/docs/setup_en.md @@ -51,7 +51,7 @@ them. ### Verifying your config file -If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/mysterycheck). +If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/check). ## Generating a Single-Player Game From 9f126ad0d070c0eb42bdf416a11775aa7d01307f Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 22 Oct 2023 06:48:06 +0200 Subject: [PATCH 20/24] The Witness: Fix random events not having the correct probabilities (#2340) --- worlds/witness/__init__.py | 2 +- worlds/witness/hints.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/worlds/witness/__init__.py b/worlds/witness/__init__.py index faaafd598b51..28eaba6404b6 100644 --- a/worlds/witness/__init__.py +++ b/worlds/witness/__init__.py @@ -66,7 +66,7 @@ def __init__(self, multiworld: "MultiWorld", player: int): def _get_slot_data(self): return { - 'seed': self.multiworld.per_slot_randoms[self.player].randint(0, 1000000), + 'seed': self.random.randrange(0, 1000000), 'victory_location': int(self.player_logic.VICTORY_LOCATION, 16), 'panelhex_to_id': self.locat.CHECK_PANELHEX_TO_ID, 'item_id_to_door_hexes': StaticWitnessItems.get_item_to_door_mappings(), diff --git a/worlds/witness/hints.py b/worlds/witness/hints.py index 5d8bd5d3702c..4fd0edc4296e 100644 --- a/worlds/witness/hints.py +++ b/worlds/witness/hints.py @@ -306,7 +306,7 @@ def make_hints(multiworld: MultiWorld, player: int, hint_amount: int): else: hints.append((f"{loc} contains {item[0]}.", item[2])) - next_random_hint_is_item = multiworld.per_slot_randoms[player].randint(0, 2) + next_random_hint_is_item = multiworld.per_slot_randoms[player].randrange(0, 2) # Moving this to the new system is in the bigger refactoring PR while len(hints) < hint_amount: if next_random_hint_is_item: From 6e6fa13e441ca9a915cfd17f50ddf6b140ab3c7d Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Sun, 22 Oct 2023 05:12:26 -0500 Subject: [PATCH 21/24] Tests: add multiworld seed to fill subtest (#2346) --- test/TestBase.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/TestBase.py b/test/TestBase.py index e6fbafd95aa0..ca7a19815cb1 100644 --- a/test/TestBase.py +++ b/test/TestBase.py @@ -172,7 +172,7 @@ def collect(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None: items = (items,) for item in items: self.multiworld.state.collect(item) - + def remove_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: """Remove all of the items in the item pool with the given names from state""" items = self.get_items_by_name(item_names) @@ -278,7 +278,6 @@ def testEmptyStateCanReachSomething(self): def testFill(self): """Generates a multiworld and validates placements with the defined options""" - # don't run this test if accessibility is set manually if not (self.run_default_tests and self.constructed): return from Fill import distribute_items_restrictive @@ -301,8 +300,8 @@ def fulfills_accessibility(): state.collect(location.item, True, location) return self.multiworld.has_beaten_game(state, 1) - - with self.subTest("Game", game=self.game): + + with self.subTest("Game", game=self.game, seed=self.multiworld.seed): distribute_items_restrictive(self.multiworld) call_all(self.multiworld, "post_fill") self.assertTrue(fulfills_accessibility(), "Collected all locations, but can't beat the game.") From 30da81c39043befff8c829fe816e10030ecf3bf0 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Sun, 22 Oct 2023 06:00:27 -0500 Subject: [PATCH 22/24] Tests: modern PEP8-ify core test modules and methods (#2298) * rename modules * rename methods * add docstrings to the general tests * add base import stub * test_base -> bases * print deprecation warning * redo 2346 --- docs/world api.md | 3 +- test/TestBase.py | 313 +----------------- test/bases.py | 309 +++++++++++++++++ test/general/__init__.py | 7 + test/general/{TestFill.py => test_fill.py} | 48 ++- .../{TestHelpers.py => test_helpers.py} | 13 +- .../{TestHostYAML.py => test_host_yaml.py} | 2 + test/general/{TestIDs.py => test_ids.py} | 20 +- ...TestImplemented.py => test_implemented.py} | 6 +- test/general/{TestItems.py => test_items.py} | 10 +- .../{TestLocations.py => test_locations.py} | 8 +- test/general/{TestNames.py => test_names.py} | 4 +- .../{TestOptions.py => test_options.py} | 3 +- ...stReachability.py => test_reachability.py} | 6 +- ...ocationStore.py => test_location_store.py} | 0 .../data/{OnePlayer => one_player}/test.yaml | 0 .../{TestGenerate.py => test_generate.py} | 2 +- ...estMultiServer.py => test_multi_server.py} | 0 .../{TestSIPrefix.py => test_si_prefix.py} | 0 ...estAPIGenerate.py => test_api_generate.py} | 4 +- test/webhost/{TestDocs.py => test_docs.py} | 4 +- ...eGeneration.py => test_file_generation.py} | 4 +- 22 files changed, 410 insertions(+), 356 deletions(-) create mode 100644 test/bases.py rename test/general/{TestFill.py => test_fill.py} (92%) rename test/general/{TestHelpers.py => test_helpers.py} (90%) rename test/general/{TestHostYAML.py => test_host_yaml.py} (87%) rename test/general/{TestIDs.py => test_ids.py} (82%) rename test/general/{TestImplemented.py => test_implemented.py} (93%) rename test/general/{TestItems.py => test_items.py} (88%) rename test/general/{TestLocations.py => test_locations.py} (96%) rename test/general/{TestNames.py => test_names.py} (92%) rename test/general/{TestOptions.py => test_options.py} (78%) rename test/general/{TestReachability.py => test_reachability.py} (91%) rename test/netutils/{TestLocationStore.py => test_location_store.py} (100%) rename test/programs/data/{OnePlayer => one_player}/test.yaml (100%) rename test/programs/{TestGenerate.py => test_generate.py} (98%) rename test/programs/{TestMultiServer.py => test_multi_server.py} (100%) rename test/utils/{TestSIPrefix.py => test_si_prefix.py} (100%) rename test/webhost/{TestAPIGenerate.py => test_api_generate.py} (93%) rename test/webhost/{TestDocs.py => test_docs.py} (96%) rename test/webhost/{TestFileGeneration.py => test_file_generation.py} (96%) diff --git a/docs/world api.md b/docs/world api.md index 6fb5b3ac9c6d..b128e2b146b4 100644 --- a/docs/world api.md +++ b/docs/world api.md @@ -759,8 +759,9 @@ multiworld for each test written using it. Within subsequent modules, classes sh TestBase, and can then define options to test in the class body, and run tests in each test method. Example `__init__.py` + ```python -from test.TestBase import WorldTestBase +from test.test_base import WorldTestBase class MyGameTestBase(WorldTestBase): diff --git a/test/TestBase.py b/test/TestBase.py index ca7a19815cb1..bfd92346d301 100644 --- a/test/TestBase.py +++ b/test/TestBase.py @@ -1,310 +1,3 @@ -import typing -import unittest -from argparse import Namespace - -from test.general import gen_steps -from worlds import AutoWorld -from worlds.AutoWorld import call_all - -from BaseClasses import Location, MultiWorld, CollectionState, ItemClassification, Item -from worlds.alttp.Items import ItemFactory - - -class TestBase(unittest.TestCase): - multiworld: MultiWorld - _state_cache = {} - - def get_state(self, items): - if (self.multiworld, tuple(items)) in self._state_cache: - return self._state_cache[self.multiworld, tuple(items)] - state = CollectionState(self.multiworld) - for item in items: - item.classification = ItemClassification.progression - state.collect(item, event=True) - state.sweep_for_events() - state.update_reachable_regions(1) - self._state_cache[self.multiworld, tuple(items)] = state - return state - - def get_path(self, state, region): - def flist_to_iter(node): - while node: - value, node = node - yield value - - from itertools import zip_longest - reversed_path_as_flist = state.path.get(region, (region, None)) - string_path_flat = reversed(list(map(str, flist_to_iter(reversed_path_as_flist)))) - # Now we combine the flat string list into (region, exit) pairs - pathsiter = iter(string_path_flat) - pathpairs = zip_longest(pathsiter, pathsiter) - return list(pathpairs) - - def run_location_tests(self, access_pool): - for i, (location, access, *item_pool) in enumerate(access_pool): - items = item_pool[0] - all_except = item_pool[1] if len(item_pool) > 1 else None - state = self._get_items(item_pool, all_except) - path = self.get_path(state, self.multiworld.get_location(location, 1).parent_region) - with self.subTest(msg="Reach Location", location=location, access=access, items=items, - all_except=all_except, path=path, entry=i): - - self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), access, - f"failed {self.multiworld.get_location(location, 1)} with: {item_pool}") - - # check for partial solution - if not all_except and access: # we are not supposed to be able to reach location with partial inventory - for missing_item in item_pool[0]: - with self.subTest(msg="Location reachable without required item", location=location, - items=item_pool[0], missing_item=missing_item, entry=i): - state = self._get_items_partial(item_pool, missing_item) - - self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), False, - f"failed {self.multiworld.get_location(location, 1)}: succeeded with " - f"{missing_item} removed from: {item_pool}") - - def run_entrance_tests(self, access_pool): - for i, (entrance, access, *item_pool) in enumerate(access_pool): - items = item_pool[0] - all_except = item_pool[1] if len(item_pool) > 1 else None - state = self._get_items(item_pool, all_except) - path = self.get_path(state, self.multiworld.get_entrance(entrance, 1).parent_region) - with self.subTest(msg="Reach Entrance", entrance=entrance, access=access, items=items, - all_except=all_except, path=path, entry=i): - - self.assertEqual(self.multiworld.get_entrance(entrance, 1).can_reach(state), access) - - # check for partial solution - if not all_except and access: # we are not supposed to be able to reach location with partial inventory - for missing_item in item_pool[0]: - with self.subTest(msg="Entrance reachable without required item", entrance=entrance, - items=item_pool[0], missing_item=missing_item, entry=i): - state = self._get_items_partial(item_pool, missing_item) - self.assertEqual(self.multiworld.get_entrance(entrance, 1).can_reach(state), False, - f"failed {self.multiworld.get_entrance(entrance, 1)} with: {item_pool}") - - def _get_items(self, item_pool, all_except): - if all_except and len(all_except) > 0: - items = self.multiworld.itempool[:] - items = [item for item in items if - item.name not in all_except and not ("Bottle" in item.name and "AnyBottle" in all_except)] - items.extend(ItemFactory(item_pool[0], 1)) - else: - items = ItemFactory(item_pool[0], 1) - return self.get_state(items) - - def _get_items_partial(self, item_pool, missing_item): - new_items = item_pool[0].copy() - new_items.remove(missing_item) - items = ItemFactory(new_items, 1) - return self.get_state(items) - - -class WorldTestBase(unittest.TestCase): - options: typing.Dict[str, typing.Any] = {} - multiworld: MultiWorld - - game: typing.ClassVar[str] # define game name in subclass, example "Secret of Evermore" - auto_construct: typing.ClassVar[bool] = True - """ automatically set up a world for each test in this class """ - - def setUp(self) -> None: - if self.auto_construct: - self.world_setup() - - def world_setup(self, seed: typing.Optional[int] = None) -> None: - if type(self) is WorldTestBase or \ - (hasattr(WorldTestBase, self._testMethodName) - and not self.run_default_tests and - getattr(self, self._testMethodName).__code__ is - getattr(WorldTestBase, self._testMethodName, None).__code__): - return # setUp gets called for tests defined in the base class. We skip world_setup here. - if not hasattr(self, "game"): - raise NotImplementedError("didn't define game name") - self.multiworld = MultiWorld(1) - self.multiworld.game[1] = self.game - self.multiworld.player_name = {1: "Tester"} - self.multiworld.set_seed(seed) - self.multiworld.state = CollectionState(self.multiworld) - args = Namespace() - for name, option in AutoWorld.AutoWorldRegister.world_types[self.game].options_dataclass.type_hints.items(): - setattr(args, name, { - 1: option.from_any(self.options.get(name, getattr(option, "default"))) - }) - self.multiworld.set_options(args) - for step in gen_steps: - call_all(self.multiworld, step) - - # methods that can be called within tests - def collect_all_but(self, item_names: typing.Union[str, typing.Iterable[str]], - state: typing.Optional[CollectionState] = None) -> None: - """Collects all pre-placed items and items in the multiworld itempool except those provided""" - if isinstance(item_names, str): - item_names = (item_names,) - if not state: - state = self.multiworld.state - for item in self.multiworld.get_items(): - if item.name not in item_names: - state.collect(item) - - def get_item_by_name(self, item_name: str) -> Item: - """Returns the first item found in placed items, or in the itempool with the matching name""" - for item in self.multiworld.get_items(): - if item.name == item_name: - return item - raise ValueError("No such item") - - def get_items_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: - """Returns actual items from the itempool that match the provided name(s)""" - if isinstance(item_names, str): - item_names = (item_names,) - return [item for item in self.multiworld.itempool if item.name in item_names] - - def collect_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: - """ collect all of the items in the item pool that have the given names """ - items = self.get_items_by_name(item_names) - self.collect(items) - return items - - def collect(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None: - """Collects the provided item(s) into state""" - if isinstance(items, Item): - items = (items,) - for item in items: - self.multiworld.state.collect(item) - - def remove_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: - """Remove all of the items in the item pool with the given names from state""" - items = self.get_items_by_name(item_names) - self.remove(items) - return items - - def remove(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None: - """Removes the provided item(s) from state""" - if isinstance(items, Item): - items = (items,) - for item in items: - if item.location and item.location.event and item.location in self.multiworld.state.events: - self.multiworld.state.events.remove(item.location) - self.multiworld.state.remove(item) - - def can_reach_location(self, location: str) -> bool: - """Determines if the current state can reach the provided location name""" - return self.multiworld.state.can_reach(location, "Location", 1) - - def can_reach_entrance(self, entrance: str) -> bool: - """Determines if the current state can reach the provided entrance name""" - return self.multiworld.state.can_reach(entrance, "Entrance", 1) - - def can_reach_region(self, region: str) -> bool: - """Determines if the current state can reach the provided region name""" - return self.multiworld.state.can_reach(region, "Region", 1) - - def count(self, item_name: str) -> int: - """Returns the amount of an item currently in state""" - return self.multiworld.state.count(item_name, 1) - - def assertAccessDependency(self, - locations: typing.List[str], - possible_items: typing.Iterable[typing.Iterable[str]], - only_check_listed: bool = False) -> None: - """Asserts that the provided locations can't be reached without the listed items but can be reached with any - one of the provided combinations""" - all_items = [item_name for item_names in possible_items for item_name in item_names] - - state = CollectionState(self.multiworld) - self.collect_all_but(all_items, state) - if only_check_listed: - for location in locations: - self.assertFalse(state.can_reach(location, "Location", 1), f"{location} is reachable without {all_items}") - else: - for location in self.multiworld.get_locations(): - loc_reachable = state.can_reach(location, "Location", 1) - self.assertEqual(loc_reachable, location.name not in locations, - f"{location.name} is reachable without {all_items}" if loc_reachable - else f"{location.name} is not reachable without {all_items}") - for item_names in possible_items: - items = self.get_items_by_name(item_names) - for item in items: - state.collect(item) - for location in locations: - self.assertTrue(state.can_reach(location, "Location", 1), - f"{location} not reachable with {item_names}") - for item in items: - state.remove(item) - - def assertBeatable(self, beatable: bool): - """Asserts that the game can be beaten with the current state""" - self.assertEqual(self.multiworld.can_beat_game(self.multiworld.state), beatable) - - # following tests are automatically run - @property - def run_default_tests(self) -> bool: - """Not possible or identical to the base test that's always being run already""" - return (self.options - or self.setUp.__code__ is not WorldTestBase.setUp.__code__ - or self.world_setup.__code__ is not WorldTestBase.world_setup.__code__) - - @property - def constructed(self) -> bool: - """A multiworld has been constructed by this point""" - return hasattr(self, "game") and hasattr(self, "multiworld") - - def testAllStateCanReachEverything(self): - """Ensure all state can reach everything and complete the game with the defined options""" - if not (self.run_default_tests and self.constructed): - return - with self.subTest("Game", game=self.game): - excluded = self.multiworld.exclude_locations[1].value - state = self.multiworld.get_all_state(False) - for location in self.multiworld.get_locations(): - if location.name not in excluded: - with self.subTest("Location should be reached", location=location): - reachable = location.can_reach(state) - self.assertTrue(reachable, f"{location.name} unreachable") - with self.subTest("Beatable"): - self.multiworld.state = state - self.assertBeatable(True) - - def testEmptyStateCanReachSomething(self): - """Ensure empty state can reach at least one location with the defined options""" - if not (self.run_default_tests and self.constructed): - return - with self.subTest("Game", game=self.game): - state = CollectionState(self.multiworld) - locations = self.multiworld.get_reachable_locations(state, 1) - self.assertGreater(len(locations), 0, - "Need to be able to reach at least one location to get started.") - - def testFill(self): - """Generates a multiworld and validates placements with the defined options""" - if not (self.run_default_tests and self.constructed): - return - from Fill import distribute_items_restrictive - - # basically a shortened reimplementation of this method from core, in order to force the check is done - def fulfills_accessibility(): - locations = self.multiworld.get_locations(1).copy() - state = CollectionState(self.multiworld) - while locations: - sphere: typing.List[Location] = [] - for n in range(len(locations) - 1, -1, -1): - if locations[n].can_reach(state): - sphere.append(locations.pop(n)) - self.assertTrue(sphere or self.multiworld.accessibility[1] == "minimal", - f"Unreachable locations: {locations}") - if not sphere: - break - for location in sphere: - if location.item: - state.collect(location.item, True, location) - - return self.multiworld.has_beaten_game(state, 1) - - with self.subTest("Game", game=self.game, seed=self.multiworld.seed): - distribute_items_restrictive(self.multiworld) - call_all(self.multiworld, "post_fill") - self.assertTrue(fulfills_accessibility(), "Collected all locations, but can't beat the game.") - placed_items = [loc.item for loc in self.multiworld.get_locations() if loc.item and loc.item.code] - self.assertLessEqual(len(self.multiworld.itempool), len(placed_items), - "Unplaced Items remaining in itempool") +from .bases import TestBase, WorldTestBase +from warnings import warn +warn("TestBase was renamed to bases", DeprecationWarning) diff --git a/test/bases.py b/test/bases.py new file mode 100644 index 000000000000..5fe4df2014c1 --- /dev/null +++ b/test/bases.py @@ -0,0 +1,309 @@ +import typing +import unittest +from argparse import Namespace + +from test.general import gen_steps +from worlds import AutoWorld +from worlds.AutoWorld import call_all + +from BaseClasses import Location, MultiWorld, CollectionState, ItemClassification, Item +from worlds.alttp.Items import ItemFactory + + +class TestBase(unittest.TestCase): + multiworld: MultiWorld + _state_cache = {} + + def get_state(self, items): + if (self.multiworld, tuple(items)) in self._state_cache: + return self._state_cache[self.multiworld, tuple(items)] + state = CollectionState(self.multiworld) + for item in items: + item.classification = ItemClassification.progression + state.collect(item, event=True) + state.sweep_for_events() + state.update_reachable_regions(1) + self._state_cache[self.multiworld, tuple(items)] = state + return state + + def get_path(self, state, region): + def flist_to_iter(node): + while node: + value, node = node + yield value + + from itertools import zip_longest + reversed_path_as_flist = state.path.get(region, (region, None)) + string_path_flat = reversed(list(map(str, flist_to_iter(reversed_path_as_flist)))) + # Now we combine the flat string list into (region, exit) pairs + pathsiter = iter(string_path_flat) + pathpairs = zip_longest(pathsiter, pathsiter) + return list(pathpairs) + + def run_location_tests(self, access_pool): + for i, (location, access, *item_pool) in enumerate(access_pool): + items = item_pool[0] + all_except = item_pool[1] if len(item_pool) > 1 else None + state = self._get_items(item_pool, all_except) + path = self.get_path(state, self.multiworld.get_location(location, 1).parent_region) + with self.subTest(msg="Reach Location", location=location, access=access, items=items, + all_except=all_except, path=path, entry=i): + + self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), access, + f"failed {self.multiworld.get_location(location, 1)} with: {item_pool}") + + # check for partial solution + if not all_except and access: # we are not supposed to be able to reach location with partial inventory + for missing_item in item_pool[0]: + with self.subTest(msg="Location reachable without required item", location=location, + items=item_pool[0], missing_item=missing_item, entry=i): + state = self._get_items_partial(item_pool, missing_item) + + self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), False, + f"failed {self.multiworld.get_location(location, 1)}: succeeded with " + f"{missing_item} removed from: {item_pool}") + + def run_entrance_tests(self, access_pool): + for i, (entrance, access, *item_pool) in enumerate(access_pool): + items = item_pool[0] + all_except = item_pool[1] if len(item_pool) > 1 else None + state = self._get_items(item_pool, all_except) + path = self.get_path(state, self.multiworld.get_entrance(entrance, 1).parent_region) + with self.subTest(msg="Reach Entrance", entrance=entrance, access=access, items=items, + all_except=all_except, path=path, entry=i): + + self.assertEqual(self.multiworld.get_entrance(entrance, 1).can_reach(state), access) + + # check for partial solution + if not all_except and access: # we are not supposed to be able to reach location with partial inventory + for missing_item in item_pool[0]: + with self.subTest(msg="Entrance reachable without required item", entrance=entrance, + items=item_pool[0], missing_item=missing_item, entry=i): + state = self._get_items_partial(item_pool, missing_item) + self.assertEqual(self.multiworld.get_entrance(entrance, 1).can_reach(state), False, + f"failed {self.multiworld.get_entrance(entrance, 1)} with: {item_pool}") + + def _get_items(self, item_pool, all_except): + if all_except and len(all_except) > 0: + items = self.multiworld.itempool[:] + items = [item for item in items if + item.name not in all_except and not ("Bottle" in item.name and "AnyBottle" in all_except)] + items.extend(ItemFactory(item_pool[0], 1)) + else: + items = ItemFactory(item_pool[0], 1) + return self.get_state(items) + + def _get_items_partial(self, item_pool, missing_item): + new_items = item_pool[0].copy() + new_items.remove(missing_item) + items = ItemFactory(new_items, 1) + return self.get_state(items) + + +class WorldTestBase(unittest.TestCase): + options: typing.Dict[str, typing.Any] = {} + multiworld: MultiWorld + + game: typing.ClassVar[str] # define game name in subclass, example "Secret of Evermore" + auto_construct: typing.ClassVar[bool] = True + """ automatically set up a world for each test in this class """ + + def setUp(self) -> None: + if self.auto_construct: + self.world_setup() + + def world_setup(self, seed: typing.Optional[int] = None) -> None: + if type(self) is WorldTestBase or \ + (hasattr(WorldTestBase, self._testMethodName) + and not self.run_default_tests and + getattr(self, self._testMethodName).__code__ is + getattr(WorldTestBase, self._testMethodName, None).__code__): + return # setUp gets called for tests defined in the base class. We skip world_setup here. + if not hasattr(self, "game"): + raise NotImplementedError("didn't define game name") + self.multiworld = MultiWorld(1) + self.multiworld.game[1] = self.game + self.multiworld.player_name = {1: "Tester"} + self.multiworld.set_seed(seed) + self.multiworld.state = CollectionState(self.multiworld) + args = Namespace() + for name, option in AutoWorld.AutoWorldRegister.world_types[self.game].options_dataclass.type_hints.items(): + setattr(args, name, { + 1: option.from_any(self.options.get(name, getattr(option, "default"))) + }) + self.multiworld.set_options(args) + for step in gen_steps: + call_all(self.multiworld, step) + + # methods that can be called within tests + def collect_all_but(self, item_names: typing.Union[str, typing.Iterable[str]], + state: typing.Optional[CollectionState] = None) -> None: + """Collects all pre-placed items and items in the multiworld itempool except those provided""" + if isinstance(item_names, str): + item_names = (item_names,) + if not state: + state = self.multiworld.state + for item in self.multiworld.get_items(): + if item.name not in item_names: + state.collect(item) + + def get_item_by_name(self, item_name: str) -> Item: + """Returns the first item found in placed items, or in the itempool with the matching name""" + for item in self.multiworld.get_items(): + if item.name == item_name: + return item + raise ValueError("No such item") + + def get_items_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: + """Returns actual items from the itempool that match the provided name(s)""" + if isinstance(item_names, str): + item_names = (item_names,) + return [item for item in self.multiworld.itempool if item.name in item_names] + + def collect_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: + """ collect all of the items in the item pool that have the given names """ + items = self.get_items_by_name(item_names) + self.collect(items) + return items + + def collect(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None: + """Collects the provided item(s) into state""" + if isinstance(items, Item): + items = (items,) + for item in items: + self.multiworld.state.collect(item) + + def remove_by_name(self, item_names: typing.Union[str, typing.Iterable[str]]) -> typing.List[Item]: + """Remove all of the items in the item pool with the given names from state""" + items = self.get_items_by_name(item_names) + self.remove(items) + return items + + def remove(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None: + """Removes the provided item(s) from state""" + if isinstance(items, Item): + items = (items,) + for item in items: + if item.location and item.location.event and item.location in self.multiworld.state.events: + self.multiworld.state.events.remove(item.location) + self.multiworld.state.remove(item) + + def can_reach_location(self, location: str) -> bool: + """Determines if the current state can reach the provided location name""" + return self.multiworld.state.can_reach(location, "Location", 1) + + def can_reach_entrance(self, entrance: str) -> bool: + """Determines if the current state can reach the provided entrance name""" + return self.multiworld.state.can_reach(entrance, "Entrance", 1) + + def can_reach_region(self, region: str) -> bool: + """Determines if the current state can reach the provided region name""" + return self.multiworld.state.can_reach(region, "Region", 1) + + def count(self, item_name: str) -> int: + """Returns the amount of an item currently in state""" + return self.multiworld.state.count(item_name, 1) + + def assertAccessDependency(self, + locations: typing.List[str], + possible_items: typing.Iterable[typing.Iterable[str]], + only_check_listed: bool = False) -> None: + """Asserts that the provided locations can't be reached without the listed items but can be reached with any + one of the provided combinations""" + all_items = [item_name for item_names in possible_items for item_name in item_names] + + state = CollectionState(self.multiworld) + self.collect_all_but(all_items, state) + if only_check_listed: + for location in locations: + self.assertFalse(state.can_reach(location, "Location", 1), f"{location} is reachable without {all_items}") + else: + for location in self.multiworld.get_locations(): + loc_reachable = state.can_reach(location, "Location", 1) + self.assertEqual(loc_reachable, location.name not in locations, + f"{location.name} is reachable without {all_items}" if loc_reachable + else f"{location.name} is not reachable without {all_items}") + for item_names in possible_items: + items = self.get_items_by_name(item_names) + for item in items: + state.collect(item) + for location in locations: + self.assertTrue(state.can_reach(location, "Location", 1), + f"{location} not reachable with {item_names}") + for item in items: + state.remove(item) + + def assertBeatable(self, beatable: bool): + """Asserts that the game can be beaten with the current state""" + self.assertEqual(self.multiworld.can_beat_game(self.multiworld.state), beatable) + + # following tests are automatically run + @property + def run_default_tests(self) -> bool: + """Not possible or identical to the base test that's always being run already""" + return (self.options + or self.setUp.__code__ is not WorldTestBase.setUp.__code__ + or self.world_setup.__code__ is not WorldTestBase.world_setup.__code__) + + @property + def constructed(self) -> bool: + """A multiworld has been constructed by this point""" + return hasattr(self, "game") and hasattr(self, "multiworld") + + def test_all_state_can_reach_everything(self): + """Ensure all state can reach everything and complete the game with the defined options""" + if not (self.run_default_tests and self.constructed): + return + with self.subTest("Game", game=self.game): + excluded = self.multiworld.exclude_locations[1].value + state = self.multiworld.get_all_state(False) + for location in self.multiworld.get_locations(): + if location.name not in excluded: + with self.subTest("Location should be reached", location=location): + reachable = location.can_reach(state) + self.assertTrue(reachable, f"{location.name} unreachable") + with self.subTest("Beatable"): + self.multiworld.state = state + self.assertBeatable(True) + + def test_empty_state_can_reach_something(self): + """Ensure empty state can reach at least one location with the defined options""" + if not (self.run_default_tests and self.constructed): + return + with self.subTest("Game", game=self.game): + state = CollectionState(self.multiworld) + locations = self.multiworld.get_reachable_locations(state, 1) + self.assertGreater(len(locations), 0, + "Need to be able to reach at least one location to get started.") + + def test_fill(self): + """Generates a multiworld and validates placements with the defined options""" + if not (self.run_default_tests and self.constructed): + return + from Fill import distribute_items_restrictive + + # basically a shortened reimplementation of this method from core, in order to force the check is done + def fulfills_accessibility() -> bool: + locations = self.multiworld.get_locations(1).copy() + state = CollectionState(self.multiworld) + while locations: + sphere: typing.List[Location] = [] + for n in range(len(locations) - 1, -1, -1): + if locations[n].can_reach(state): + sphere.append(locations.pop(n)) + self.assertTrue(sphere or self.multiworld.accessibility[1] == "minimal", + f"Unreachable locations: {locations}") + if not sphere: + break + for location in sphere: + if location.item: + state.collect(location.item, True, location) + return self.multiworld.has_beaten_game(state, 1) + + with self.subTest("Game", game=self.game, seed=self.multiworld.seed): + distribute_items_restrictive(self.multiworld) + call_all(self.multiworld, "post_fill") + self.assertTrue(fulfills_accessibility(), "Collected all locations, but can't beat the game.") + placed_items = [loc.item for loc in self.multiworld.get_locations() if loc.item and loc.item.code] + self.assertLessEqual(len(self.multiworld.itempool), len(placed_items), + "Unplaced Items remaining in itempool") diff --git a/test/general/__init__.py b/test/general/__init__.py index d7ecc9574930..5e0f22f4ecfa 100644 --- a/test/general/__init__.py +++ b/test/general/__init__.py @@ -8,6 +8,13 @@ def setup_solo_multiworld(world_type: Type[World], steps: Tuple[str, ...] = gen_steps) -> MultiWorld: + """ + Creates a multiworld with a single player of `world_type`, sets default options, and calls provided gen steps. + + :param world_type: Type of the world to generate a multiworld for + :param steps: The gen steps that should be called on the generated multiworld before returning. Default calls + steps through pre_fill + """ multiworld = MultiWorld(1) multiworld.game[1] = world_type.game multiworld.player_name = {1: "Tester"} diff --git a/test/general/TestFill.py b/test/general/test_fill.py similarity index 92% rename from test/general/TestFill.py rename to test/general/test_fill.py index 0933603dfdd0..4e8cc2edb7c5 100644 --- a/test/general/TestFill.py +++ b/test/general/test_fill.py @@ -72,7 +72,7 @@ def generate_region(self, parent: Region, size: int, access_rule: CollectionRule return region -def fillRegion(world: MultiWorld, region: Region, items: List[Item]) -> List[Item]: +def fill_region(world: MultiWorld, region: Region, items: List[Item]) -> List[Item]: items = items.copy() while len(items) > 0: location = region.locations.pop(0) @@ -86,7 +86,7 @@ def fillRegion(world: MultiWorld, region: Region, items: List[Item]) -> List[Ite return items -def regionContains(region: Region, item: Item) -> bool: +def region_contains(region: Region, item: Item) -> bool: for location in region.locations: if location.item == item: return True @@ -133,6 +133,7 @@ def names(objs: list) -> Iterable[str]: class TestFillRestrictive(unittest.TestCase): def test_basic_fill(self): + """Tests `fill_restrictive` fills and removes the locations and items from their respective lists""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) @@ -150,6 +151,7 @@ def test_basic_fill(self): self.assertEqual([], player1.prog_items) def test_ordered_fill(self): + """Tests `fill_restrictive` fulfills set rules""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) items = player1.prog_items @@ -166,6 +168,7 @@ def test_ordered_fill(self): self.assertEqual(locations[1].item, items[1]) def test_partial_fill(self): + """Tests that `fill_restrictive` returns unfilled locations""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 3, 2) @@ -191,6 +194,7 @@ def test_partial_fill(self): self.assertEqual(player1.locations[0], loc2) def test_minimal_fill(self): + """Test that fill for minimal player can have unreachable items""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) @@ -246,6 +250,7 @@ def test_minimal_mixed_fill(self): f'{item} is unreachable in {item.location}') def test_reversed_fill(self): + """Test a different set of rules can be satisfied""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) @@ -264,6 +269,7 @@ def test_reversed_fill(self): self.assertEqual(loc1.item, item0) def test_multi_step_fill(self): + """Test that fill is able to satisfy multiple spheres""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 4, 4) @@ -288,6 +294,7 @@ def test_multi_step_fill(self): self.assertEqual(locations[3].item, items[3]) def test_impossible_fill(self): + """Test that fill raises an error when it can't place any items""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) items = player1.prog_items @@ -304,6 +311,7 @@ def test_impossible_fill(self): player1.locations.copy(), player1.prog_items.copy()) def test_circular_fill(self): + """Test that fill raises an error when it can't place all items""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 3, 3) @@ -324,6 +332,7 @@ def test_circular_fill(self): player1.locations.copy(), player1.prog_items.copy()) def test_competing_fill(self): + """Test that fill raises an error when it can't place items in a way to satisfy the conditions""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) @@ -340,6 +349,7 @@ def test_competing_fill(self): player1.locations.copy(), player1.prog_items.copy()) def test_multiplayer_fill(self): + """Test that items can be placed across worlds""" multi_world = generate_multi_world(2) player1 = generate_player_data(multi_world, 1, 2, 2) player2 = generate_player_data(multi_world, 2, 2, 2) @@ -360,6 +370,7 @@ def test_multiplayer_fill(self): self.assertEqual(player2.locations[1].item, player2.prog_items[0]) def test_multiplayer_rules_fill(self): + """Test that fill across worlds satisfies the rules""" multi_world = generate_multi_world(2) player1 = generate_player_data(multi_world, 1, 2, 2) player2 = generate_player_data(multi_world, 2, 2, 2) @@ -383,6 +394,7 @@ def test_multiplayer_rules_fill(self): self.assertEqual(player2.locations[1].item, player1.prog_items[1]) def test_restrictive_progress(self): + """Test that various spheres with different requirements can be filled""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, prog_item_count=25) items = player1.prog_items.copy() @@ -405,6 +417,7 @@ def test_restrictive_progress(self): locations, player1.prog_items) def test_swap_to_earlier_location_with_item_rule(self): + """Test that item swap happens and works as intended""" # test for PR#1109 multi_world = generate_multi_world(1) player1 = generate_player_data(multi_world, 1, 4, 4) @@ -430,6 +443,7 @@ def test_swap_to_earlier_location_with_item_rule(self): self.assertEqual(sphere1_loc.item, allowed_item, "Wrong item in Sphere 1") def test_double_sweep(self): + """Test that sweep doesn't duplicate Event items when sweeping""" # test for PR1114 multi_world = generate_multi_world(1) player1 = generate_player_data(multi_world, 1, 1, 1) @@ -445,6 +459,7 @@ def test_double_sweep(self): self.assertEqual(multi_world.state.prog_items[item.name, item.player], 1, "Sweep collected multiple times") def test_correct_item_instance_removed_from_pool(self): + """Test that a placed item gets removed from the submitted pool""" multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) @@ -461,6 +476,7 @@ def test_correct_item_instance_removed_from_pool(self): class TestDistributeItemsRestrictive(unittest.TestCase): def test_basic_distribute(self): + """Test that distribute_items_restrictive is deterministic""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -480,6 +496,7 @@ def test_basic_distribute(self): self.assertFalse(locations[3].event) def test_excluded_distribute(self): + """Test that distribute_items_restrictive doesn't put advancement items on excluded locations""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -494,6 +511,7 @@ def test_excluded_distribute(self): self.assertFalse(locations[2].item.advancement) def test_non_excluded_item_distribute(self): + """Test that useful items aren't placed on excluded locations""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -508,6 +526,7 @@ def test_non_excluded_item_distribute(self): self.assertEqual(locations[1].item, basic_items[0]) def test_too_many_excluded_distribute(self): + """Test that fill fails if it can't place all progression items due to too many excluded locations""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -520,6 +539,7 @@ def test_too_many_excluded_distribute(self): self.assertRaises(FillError, distribute_items_restrictive, multi_world) def test_non_excluded_item_must_distribute(self): + """Test that fill fails if it can't place useful items due to too many excluded locations""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -534,6 +554,7 @@ def test_non_excluded_item_must_distribute(self): self.assertRaises(FillError, distribute_items_restrictive, multi_world) def test_priority_distribute(self): + """Test that priority locations receive advancement items""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -548,6 +569,7 @@ def test_priority_distribute(self): self.assertTrue(locations[3].item.advancement) def test_excess_priority_distribute(self): + """Test that if there's more priority locations than advancement items, they can still fill""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -562,6 +584,7 @@ def test_excess_priority_distribute(self): self.assertFalse(locations[3].item.advancement) def test_multiple_world_priority_distribute(self): + """Test that priority fill can be satisfied for multiple worlds""" multi_world = generate_multi_world(3) player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -591,7 +614,7 @@ def test_multiple_world_priority_distribute(self): self.assertTrue(player3.locations[3].item.advancement) def test_can_remove_locations_in_fill_hook(self): - + """Test that distribute_items_restrictive calls the fill hook and allows for item and location removal""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, 4, prog_item_count=2, basic_item_count=2) @@ -611,6 +634,7 @@ def fill_hook(progitempool, usefulitempool, filleritempool, fill_locations): self.assertIsNone(removed_location[0].item) def test_seed_robust_to_item_order(self): + """Test deterministic fill""" mw1 = generate_multi_world() gen1 = generate_player_data( mw1, 1, 4, prog_item_count=2, basic_item_count=2) @@ -628,6 +652,7 @@ def test_seed_robust_to_item_order(self): self.assertEqual(gen1.locations[3].item, gen2.locations[3].item) def test_seed_robust_to_location_order(self): + """Test deterministic fill even if locations in a region are reordered""" mw1 = generate_multi_world() gen1 = generate_player_data( mw1, 1, 4, prog_item_count=2, basic_item_count=2) @@ -646,6 +671,7 @@ def test_seed_robust_to_location_order(self): self.assertEqual(gen1.locations[3].item, gen2.locations[3].item) def test_can_reserve_advancement_items_for_general_fill(self): + """Test that priority locations fill still satisfies item rules""" multi_world = generate_multi_world() player1 = generate_player_data( multi_world, 1, location_count=5, prog_item_count=5) @@ -655,14 +681,14 @@ def test_can_reserve_advancement_items_for_general_fill(self): location = player1.locations[0] location.progress_type = LocationProgressType.PRIORITY - location.item_rule = lambda item: item != items[ - 0] and item != items[1] and item != items[2] and item != items[3] + location.item_rule = lambda item: item not in items[:4] distribute_items_restrictive(multi_world) self.assertEqual(location.item, items[4]) def test_non_excluded_local_items(self): + """Test that local items get placed locally in a multiworld""" multi_world = generate_multi_world(2) player1 = generate_player_data( multi_world, 1, location_count=5, basic_item_count=5) @@ -683,6 +709,7 @@ def test_non_excluded_local_items(self): self.assertFalse(item.location.event, False) def test_early_items(self) -> None: + """Test that the early items API successfully places items early""" mw = generate_multi_world(2) player1 = generate_player_data(mw, 1, location_count=5, basic_item_count=5) player2 = generate_player_data(mw, 2, location_count=5, basic_item_count=5) @@ -762,21 +789,22 @@ def setUp(self) -> None: # Sphere 1 region = player1.generate_region(player1.menu, 20) - items = fillRegion(multi_world, region, [ + items = fill_region(multi_world, region, [ player1.prog_items[0]] + items) # Sphere 2 region = player1.generate_region( player1.regions[1], 20, lambda state: state.has(player1.prog_items[0].name, player1.id)) - items = fillRegion( + items = fill_region( multi_world, region, [player1.prog_items[1], player2.prog_items[0]] + items) # Sphere 3 region = player2.generate_region( player2.menu, 20, lambda state: state.has(player2.prog_items[0].name, player2.id)) - fillRegion(multi_world, region, [player2.prog_items[1]] + items) + fill_region(multi_world, region, [player2.prog_items[1]] + items) def test_balances_progression(self) -> None: + """Tests that progression balancing moves progression items earlier""" self.multi_world.progression_balancing[self.player1.id].value = 50 self.multi_world.progression_balancing[self.player2.id].value = 50 @@ -789,6 +817,7 @@ def test_balances_progression(self) -> None: self.player1.regions[1], self.player2.prog_items[0]) def test_balances_progression_light(self) -> None: + """Test that progression balancing still moves items earlier on minimum value""" self.multi_world.progression_balancing[self.player1.id].value = 1 self.multi_world.progression_balancing[self.player2.id].value = 1 @@ -802,6 +831,7 @@ def test_balances_progression_light(self) -> None: self.player1.regions[1], self.player2.prog_items[0]) def test_balances_progression_heavy(self) -> None: + """Test that progression balancing moves items earlier on maximum value""" self.multi_world.progression_balancing[self.player1.id].value = 99 self.multi_world.progression_balancing[self.player2.id].value = 99 @@ -815,6 +845,7 @@ def test_balances_progression_heavy(self) -> None: self.player1.regions[1], self.player2.prog_items[0]) def test_skips_balancing_progression(self) -> None: + """Test that progression balancing is skipped when players have it disabled""" self.multi_world.progression_balancing[self.player1.id].value = 0 self.multi_world.progression_balancing[self.player2.id].value = 0 @@ -827,6 +858,7 @@ def test_skips_balancing_progression(self) -> None: self.player1.regions[2], self.player2.prog_items[0]) def test_ignores_priority_locations(self) -> None: + """Test that progression items on priority locations don't get moved by balancing""" self.multi_world.progression_balancing[self.player1.id].value = 50 self.multi_world.progression_balancing[self.player2.id].value = 50 diff --git a/test/general/TestHelpers.py b/test/general/test_helpers.py similarity index 90% rename from test/general/TestHelpers.py rename to test/general/test_helpers.py index 17fdce653c8c..83b56b34386b 100644 --- a/test/general/TestHelpers.py +++ b/test/general/test_helpers.py @@ -1,8 +1,7 @@ -from argparse import Namespace -from typing import Dict, Optional, Callable - -from BaseClasses import MultiWorld, CollectionState, Region import unittest +from typing import Callable, Dict, Optional + +from BaseClasses import CollectionState, MultiWorld, Region class TestHelpers(unittest.TestCase): @@ -15,7 +14,8 @@ def setUp(self) -> None: self.multiworld.player_name = {1: "Tester"} self.multiworld.set_seed() - def testRegionHelpers(self) -> None: + def test_region_helpers(self) -> None: + """Tests `Region.add_locations()` and `Region.add_exits()` have correct behavior""" regions: Dict[str, str] = { "TestRegion1": "I'm an apple", "TestRegion2": "I'm a banana", @@ -79,4 +79,5 @@ def testRegionHelpers(self) -> None: current_region.add_exits(reg_exit_set[region]) exit_names = {_exit.name for _exit in current_region.exits} for reg_exit in reg_exit_set[region]: - self.assertTrue(f"{region} -> {reg_exit}" in exit_names, f"{region} -> {reg_exit} not in {exit_names}") + self.assertTrue(f"{region} -> {reg_exit}" in exit_names, + f"{region} -> {reg_exit} not in {exit_names}") diff --git a/test/general/TestHostYAML.py b/test/general/test_host_yaml.py similarity index 87% rename from test/general/TestHostYAML.py rename to test/general/test_host_yaml.py index f5fd406cac84..9408f95b1658 100644 --- a/test/general/TestHostYAML.py +++ b/test/general/test_host_yaml.py @@ -15,6 +15,7 @@ def setUpClass(cls) -> None: cls.yaml_options = Utils.parse_yaml(f.read()) def test_utils_in_yaml(self) -> None: + """Tests that the auto generated host.yaml has default settings in it""" for option_key, option_set in Utils.get_default_options().items(): with self.subTest(option_key): self.assertIn(option_key, self.yaml_options) @@ -22,6 +23,7 @@ def test_utils_in_yaml(self) -> None: self.assertIn(sub_option_key, self.yaml_options[option_key]) def test_yaml_in_utils(self) -> None: + """Tests that the auto generated host.yaml shows up in reference calls""" utils_options = Utils.get_default_options() for option_key, option_set in self.yaml_options.items(): with self.subTest(option_key): diff --git a/test/general/TestIDs.py b/test/general/test_ids.py similarity index 82% rename from test/general/TestIDs.py rename to test/general/test_ids.py index db1c9461b91a..4edfb8d994ef 100644 --- a/test/general/TestIDs.py +++ b/test/general/test_ids.py @@ -3,35 +3,37 @@ class TestIDs(unittest.TestCase): - def testUniqueItems(self): + def test_unique_items(self): + """Tests that every game has a unique ID per item in the datapackage""" known_item_ids = set() for gamename, world_type in AutoWorldRegister.world_types.items(): current = len(known_item_ids) known_item_ids |= set(world_type.item_id_to_name) self.assertEqual(len(known_item_ids) - len(world_type.item_id_to_name), current) - def testUniqueLocations(self): + def test_unique_locations(self): + """Tests that every game has a unique ID per location in the datapackage""" known_location_ids = set() for gamename, world_type in AutoWorldRegister.world_types.items(): current = len(known_location_ids) known_location_ids |= set(world_type.location_id_to_name) self.assertEqual(len(known_location_ids) - len(world_type.location_id_to_name), current) - def testRangeItems(self): + def test_range_items(self): """There are Javascript clients, which are limited to Number.MAX_SAFE_INTEGER due to 64bit float precision.""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): for item_id in world_type.item_id_to_name: self.assertLess(item_id, 2**53) - def testRangeLocations(self): + def test_range_locations(self): """There are Javascript clients, which are limited to Number.MAX_SAFE_INTEGER due to 64bit float precision.""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): for location_id in world_type.location_id_to_name: self.assertLess(location_id, 2**53) - def testReservedItems(self): + def test_reserved_items(self): """negative item IDs are reserved to the special "Archipelago" world.""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): @@ -42,7 +44,7 @@ def testReservedItems(self): for item_id in world_type.item_id_to_name: self.assertGreater(item_id, 0) - def testReservedLocations(self): + def test_reserved_locations(self): """negative location IDs are reserved to the special "Archipelago" world.""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): @@ -53,12 +55,14 @@ def testReservedLocations(self): for location_id in world_type.location_id_to_name: self.assertGreater(location_id, 0) - def testDuplicateItemIDs(self): + def test_duplicate_item_ids(self): + """Test that a game doesn't have item id overlap within its own datapackage""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): self.assertEqual(len(world_type.item_id_to_name), len(world_type.item_name_to_id)) - def testDuplicateLocationIDs(self): + def test_duplicate_location_ids(self): + """Test that a game doesn't have location id overlap within its own datapackage""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): self.assertEqual(len(world_type.location_id_to_name), len(world_type.location_name_to_id)) diff --git a/test/general/TestImplemented.py b/test/general/test_implemented.py similarity index 93% rename from test/general/TestImplemented.py rename to test/general/test_implemented.py index 22c546eff18b..67d0e5ff72f0 100644 --- a/test/general/TestImplemented.py +++ b/test/general/test_implemented.py @@ -5,7 +5,7 @@ class TestImplemented(unittest.TestCase): - def testCompletionCondition(self): + def test_completion_condition(self): """Ensure a completion condition is set that has requirements.""" for game_name, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden and game_name not in {"Sudoku"}: @@ -13,7 +13,7 @@ def testCompletionCondition(self): multiworld = setup_solo_multiworld(world_type) self.assertFalse(multiworld.completion_condition[1](multiworld.state)) - def testEntranceParents(self): + def test_entrance_parents(self): """Tests that the parents of created Entrances match the exiting Region.""" for game_name, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden: @@ -23,7 +23,7 @@ def testEntranceParents(self): for exit in region.exits: self.assertEqual(exit.parent_region, region) - def testStageMethods(self): + def test_stage_methods(self): """Tests that worlds don't try to implement certain steps that are only ever called as stage.""" for game_name, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden: diff --git a/test/general/TestItems.py b/test/general/test_items.py similarity index 88% rename from test/general/TestItems.py rename to test/general/test_items.py index 95eb8d28d9af..464d246e1fa3 100644 --- a/test/general/TestItems.py +++ b/test/general/test_items.py @@ -4,7 +4,8 @@ class TestBase(unittest.TestCase): - def testCreateItem(self): + def test_create_item(self): + """Test that a world can successfully create all items in its datapackage""" for game_name, world_type in AutoWorldRegister.world_types.items(): proxy_world = world_type(None, 0) # this is identical to MultiServer.py creating worlds for item_name in world_type.item_name_to_id: @@ -12,7 +13,7 @@ def testCreateItem(self): item = proxy_world.create_item(item_name) self.assertEqual(item.name, item_name) - def testItemNameGroupHasValidItem(self): + def test_item_name_group_has_valid_item(self): """Test that all item name groups contain valid items. """ # This cannot test for Event names that you may have declared for logic, only sendable Items. # In such a case, you can add your entries to this Exclusion dict. Game Name -> Group Names @@ -33,7 +34,7 @@ def testItemNameGroupHasValidItem(self): for item in items: self.assertIn(item, world_type.item_name_to_id) - def testItemNameGroupConflict(self): + def test_item_name_group_conflict(self): """Test that all item name groups aren't also item names.""" for game_name, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game_name, game_name=game_name): @@ -41,7 +42,8 @@ def testItemNameGroupConflict(self): with self.subTest(group_name, group_name=group_name): self.assertNotIn(group_name, world_type.item_name_to_id) - def testItemCountGreaterEqualLocations(self): + def test_item_count_greater_equal_locations(self): + """Test that by the pre_fill step under default settings, each game submits items >= locations""" for game_name, world_type in AutoWorldRegister.world_types.items(): with self.subTest("Game", game=game_name): multiworld = setup_solo_multiworld(world_type) diff --git a/test/general/TestLocations.py b/test/general/test_locations.py similarity index 96% rename from test/general/TestLocations.py rename to test/general/test_locations.py index e77e7a6332bb..2e609a756f09 100644 --- a/test/general/TestLocations.py +++ b/test/general/test_locations.py @@ -5,7 +5,7 @@ class TestBase(unittest.TestCase): - def testCreateDuplicateLocations(self): + def test_create_duplicate_locations(self): """Tests that no two Locations share a name or ID.""" for game_name, world_type in AutoWorldRegister.world_types.items(): multiworld = setup_solo_multiworld(world_type) @@ -20,7 +20,7 @@ def testCreateDuplicateLocations(self): self.assertLessEqual(locations.most_common(1)[0][1], 1, f"{world_type.game} has duplicate of location ID {locations.most_common(1)}") - def testLocationsInDatapackage(self): + def test_locations_in_datapackage(self): """Tests that created locations not filled before fill starts exist in the datapackage.""" for game_name, world_type in AutoWorldRegister.world_types.items(): with self.subTest("Game", game_name=game_name): @@ -30,7 +30,7 @@ def testLocationsInDatapackage(self): self.assertIn(location.name, world_type.location_name_to_id) self.assertEqual(location.address, world_type.location_name_to_id[location.name]) - def testLocationCreationSteps(self): + def test_location_creation_steps(self): """Tests that Regions and Locations aren't created after `create_items`.""" gen_steps = ("generate_early", "create_regions", "create_items") for game_name, world_type in AutoWorldRegister.world_types.items(): @@ -60,7 +60,7 @@ def testLocationCreationSteps(self): self.assertGreaterEqual(location_count, len(multiworld.get_locations()), f"{game_name} modified locations count during pre_fill") - def testLocationGroup(self): + def test_location_group(self): """Test that all location name groups contain valid locations and don't share names.""" for game_name, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game_name, game_name=game_name): diff --git a/test/general/TestNames.py b/test/general/test_names.py similarity index 92% rename from test/general/TestNames.py rename to test/general/test_names.py index 6dae53240d10..7be76eed4ba9 100644 --- a/test/general/TestNames.py +++ b/test/general/test_names.py @@ -3,7 +3,7 @@ class TestNames(unittest.TestCase): - def testItemNamesFormat(self): + def test_item_names_format(self): """Item names must not be all numeric in order to differentiate between ID and name in !hint""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): @@ -11,7 +11,7 @@ def testItemNamesFormat(self): self.assertFalse(item_name.isnumeric(), f"Item name \"{item_name}\" is invalid. It must not be numeric.") - def testLocationNameFormat(self): + def test_location_name_format(self): """Location names must not be all numeric in order to differentiate between ID and name in !hint_location""" for gamename, world_type in AutoWorldRegister.world_types.items(): with self.subTest(game=gamename): diff --git a/test/general/TestOptions.py b/test/general/test_options.py similarity index 78% rename from test/general/TestOptions.py rename to test/general/test_options.py index 4a3bd0b02a0a..e1136f93c96f 100644 --- a/test/general/TestOptions.py +++ b/test/general/test_options.py @@ -3,7 +3,8 @@ class TestOptions(unittest.TestCase): - def testOptionsHaveDocString(self): + def test_options_have_doc_string(self): + """Test that submitted options have their own specified docstring""" for gamename, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden: for option_key, option in world_type.options_dataclass.type_hints.items(): diff --git a/test/general/TestReachability.py b/test/general/test_reachability.py similarity index 91% rename from test/general/TestReachability.py rename to test/general/test_reachability.py index dd786b8352f5..828912ee35a3 100644 --- a/test/general/TestReachability.py +++ b/test/general/test_reachability.py @@ -31,7 +31,8 @@ class TestBase(unittest.TestCase): } } - def testDefaultAllStateCanReachEverything(self): + def test_default_all_state_can_reach_everything(self): + """Ensure all state can reach everything and complete the game with the defined options""" for game_name, world_type in AutoWorldRegister.world_types.items(): unreachable_regions = self.default_settings_unreachable_regions.get(game_name, set()) with self.subTest("Game", game=game_name): @@ -54,7 +55,8 @@ def testDefaultAllStateCanReachEverything(self): with self.subTest("Completion Condition"): self.assertTrue(world.can_beat_game(state)) - def testDefaultEmptyStateCanReachSomething(self): + def test_default_empty_state_can_reach_something(self): + """Ensure empty state can reach at least one location with the defined options""" for game_name, world_type in AutoWorldRegister.world_types.items(): with self.subTest("Game", game=game_name): world = setup_solo_multiworld(world_type) diff --git a/test/netutils/TestLocationStore.py b/test/netutils/test_location_store.py similarity index 100% rename from test/netutils/TestLocationStore.py rename to test/netutils/test_location_store.py diff --git a/test/programs/data/OnePlayer/test.yaml b/test/programs/data/one_player/test.yaml similarity index 100% rename from test/programs/data/OnePlayer/test.yaml rename to test/programs/data/one_player/test.yaml diff --git a/test/programs/TestGenerate.py b/test/programs/test_generate.py similarity index 98% rename from test/programs/TestGenerate.py rename to test/programs/test_generate.py index 73e1d3b8348c..887a417ec9f9 100644 --- a/test/programs/TestGenerate.py +++ b/test/programs/test_generate.py @@ -16,7 +16,7 @@ class TestGenerateMain(unittest.TestCase): generate_dir = Path(Generate.__file__).parent run_dir = generate_dir / "test" # reproducible cwd that's neither __file__ nor Generate.__file__ - abs_input_dir = Path(__file__).parent / 'data' / 'OnePlayer' + abs_input_dir = Path(__file__).parent / 'data' / 'one_player' rel_input_dir = abs_input_dir.relative_to(run_dir) # directly supplied relative paths are relative to cwd yaml_input_dir = abs_input_dir.relative_to(generate_dir) # yaml paths are relative to user_path diff --git a/test/programs/TestMultiServer.py b/test/programs/test_multi_server.py similarity index 100% rename from test/programs/TestMultiServer.py rename to test/programs/test_multi_server.py diff --git a/test/utils/TestSIPrefix.py b/test/utils/test_si_prefix.py similarity index 100% rename from test/utils/TestSIPrefix.py rename to test/utils/test_si_prefix.py diff --git a/test/webhost/TestAPIGenerate.py b/test/webhost/test_api_generate.py similarity index 93% rename from test/webhost/TestAPIGenerate.py rename to test/webhost/test_api_generate.py index 8ea78f27f93a..b8bdcb38c764 100644 --- a/test/webhost/TestAPIGenerate.py +++ b/test/webhost/test_api_generate.py @@ -19,11 +19,11 @@ def setUpClass(cls) -> None: cls.client = app.test_client() - def testCorrectErrorEmptyRequest(self): + def test_correct_error_empty_request(self): response = self.client.post("/api/generate") self.assertIn("No options found. Expected file attachment or json weights.", response.text) - def testGenerationQueued(self): + def test_generation_queued(self): options = { "Tester1": { diff --git a/test/webhost/TestDocs.py b/test/webhost/test_docs.py similarity index 96% rename from test/webhost/TestDocs.py rename to test/webhost/test_docs.py index f6ede1543e26..68aba05f9dcc 100644 --- a/test/webhost/TestDocs.py +++ b/test/webhost/test_docs.py @@ -11,7 +11,7 @@ class TestDocs(unittest.TestCase): def setUpClass(cls) -> None: cls.tutorials_data = WebHost.create_ordered_tutorials_file() - def testHasTutorial(self): + def test_has_tutorial(self): games_with_tutorial = set(entry["gameTitle"] for entry in self.tutorials_data) for game_name, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden: @@ -27,7 +27,7 @@ def testHasTutorial(self): self.fail(f"{game_name} has no setup tutorial. " f"Games with Tutorial: {games_with_tutorial}") - def testHasGameInfo(self): + def test_has_game_info(self): for game_name, world_type in AutoWorldRegister.world_types.items(): if not world_type.hidden: target_path = Utils.local_path("WebHostLib", "static", "generated", "docs", game_name) diff --git a/test/webhost/TestFileGeneration.py b/test/webhost/test_file_generation.py similarity index 96% rename from test/webhost/TestFileGeneration.py rename to test/webhost/test_file_generation.py index f01b70e14f90..059f6b49a1fd 100644 --- a/test/webhost/TestFileGeneration.py +++ b/test/webhost/test_file_generation.py @@ -13,7 +13,7 @@ def setUpClass(cls) -> None: # should not create the folder *here* cls.incorrect_path = os.path.join(os.path.split(os.path.dirname(__file__))[0], "WebHostLib") - def testOptions(self): + def test_options(self): from WebHostLib.options import create as create_options_files create_options_files() target = os.path.join(self.correct_path, "static", "generated", "configs") @@ -30,7 +30,7 @@ def testOptions(self): for value in roll_options({file.name: f.read()})[0].values(): self.assertTrue(value is True, f"Default Options for template {file.name} cannot be run.") - def testTutorial(self): + def test_tutorial(self): WebHost.create_ordered_tutorials_file() self.assertTrue(os.path.exists(os.path.join(self.correct_path, "static", "generated", "tutorials.json"))) self.assertFalse(os.path.exists(os.path.join(self.incorrect_path, "static", "generated", "tutorials.json"))) From 50244342d9b64bfd0c8534da181c0aa5f292aaed Mon Sep 17 00:00:00 2001 From: BootsinSoots <102177943+BootsinSoots@users.noreply.github.com> Date: Sun, 22 Oct 2023 07:11:19 -0400 Subject: [PATCH 23/24] Docs: Added Note Explaining BK and fix typo in advanced settings (#2316) * Added Note Explaining BK Added suggested change regarding BK mode from Issue #2295 * Changed to Glossary hyperlink * Fix minor typo in exclude_locations * Update worlds/generic/docs/advanced_settings_en.md Co-authored-by: kindasneaki * Docs: Reformat advanced_settings_en/progression_balancing --------- Co-authored-by: kindasneaki Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> --- worlds/generic/docs/advanced_settings_en.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/worlds/generic/docs/advanced_settings_en.md b/worlds/generic/docs/advanced_settings_en.md index 456795dac4a7..6d5e20462f13 100644 --- a/worlds/generic/docs/advanced_settings_en.md +++ b/worlds/generic/docs/advanced_settings_en.md @@ -108,7 +108,9 @@ guide: [Archipelago Plando Guide](/tutorial/Archipelago/plando/en) * `minimal` will only guarantee that the seed is beatable. You will be guaranteed able to finish the seed logically but may not be able to access all locations or acquire all items. A good example of this is having a big key in the big chest in a dungeon in ALTTP making it impossible to get and finish the dungeon. -* `progression_balancing` is a system the Archipelago generator uses to try and reduce "BK mode" as much as possible. +* `progression_balancing` is a system the Archipelago generator uses to try and reduce + ["BK mode"](/glossary/en/#burger-king-/-bk-mode) + as much as possible. This primarily involves moving necessary progression items into earlier logic spheres to make the games more accessible so that players almost always have something to do. This can be in a range from 0 to 99, and is 50 by default. This number represents a percentage of the furthest progressible player. @@ -130,7 +132,7 @@ guide: [Archipelago Plando Guide](/tutorial/Archipelago/plando/en) there without using any hint points. * `exclude_locations` lets you define any locations that you don't want to do and during generation will force a "junk" item which isn't necessary for progression to go in these locations. -* `priority_locations` is the inverse of `exlcude_locations`, forcing a progression item in the defined locations. +* `priority_locations` is the inverse of `exclude_locations`, forcing a progression item in the defined locations. * `item_links` allows players to link their items into a group with the same item link name and game. The items declared in `item_pool` get combined and when an item is found for the group, all players in the group receive it. Item links can also have local and non local items, forcing the items to either be placed within the worlds of the group or in From 724999fc43c377161c96dee553f362a551b58c22 Mon Sep 17 00:00:00 2001 From: espeon65536 <81029175+espeon65536@users.noreply.github.com> Date: Sun, 22 Oct 2023 10:38:47 -0600 Subject: [PATCH 24/24] Ocarina of Time: long-awaited bugfixes (#2344) - Added location name groups, so you can make your entire Water Temple priority to annoy everyone else - Significant improvement to ER generation success rate (~80% to >99%) - Changed `adult_trade_start` option to a choice option instead of a list (this shouldn't actually break any YAMLs though, due to the lesser-known property of lists parsing as a uniformly-weighted choice) - Major improvements to the option tooltips where needed. (Possibly too much text now) - Changed default hint distribution to `async` to help people's generation times. The tooltip explains that it removes WOTH hints so people hopefully don't get tripped up. - Makes stick and nut capacity upgrades useful items - Added shop prices and required trials to spoiler log - Added Cojiro to adult trade item group, because it had been forgotten previously - Fixed size-modified chests not being moved properly due to trap appearance changing the size - Fixed Thieves Hideout keyring not being allowed in start inventory - Fixed hint generation not accurately flagging barren locations on certain dungeon item shuffle settings - Fixed bug where you could plando arbitrarily-named items into the world, breaking everything --- worlds/oot/ItemPool.py | 4 +- worlds/oot/Location.py | 58 ++++- worlds/oot/LocationList.py | 2 +- worlds/oot/Options.py | 489 ++++++++++++++++++++++--------------- worlds/oot/Patches.py | 30 ++- worlds/oot/Rules.py | 3 - worlds/oot/__init__.py | 90 ++++--- 7 files changed, 424 insertions(+), 252 deletions(-) diff --git a/worlds/oot/ItemPool.py b/worlds/oot/ItemPool.py index 94e1011ddc63..6ca6bc9268a9 100644 --- a/worlds/oot/ItemPool.py +++ b/worlds/oot/ItemPool.py @@ -350,7 +350,7 @@ def generate_itempool(ootworld): ootworld.itempool = [ootworld.create_item(item) for item in pool] for (location_name, item) in placed_items.items(): location = world.get_location(location_name, player) - location.place_locked_item(ootworld.create_item(item)) + location.place_locked_item(ootworld.create_item(item, allow_arbitrary_name=True)) def get_pool_core(world): @@ -675,7 +675,7 @@ def get_pool_core(world): world.remove_from_start_inventory.append('Scarecrow Song') if world.no_epona_race: - world.multiworld.push_precollected(world.create_item('Epona')) + world.multiworld.push_precollected(world.create_item('Epona', allow_arbitrary_name=True)) world.remove_from_start_inventory.append('Epona') if world.shuffle_smallkeys == 'vanilla': diff --git a/worlds/oot/Location.py b/worlds/oot/Location.py index e2b0e52e4dc5..3f7d75517e30 100644 --- a/worlds/oot/Location.py +++ b/worlds/oot/Location.py @@ -2,6 +2,8 @@ from .LocationList import location_table from BaseClasses import Location +non_indexed_location_types = {'Boss', 'Event', 'Drop', 'HintStone', 'Hint'} + location_id_offset = 67000 locnames_pre_70 = { "Gift from Sages", @@ -18,7 +20,7 @@ else 0) location_name_to_id = {name: (location_id_offset + index) for (index, name) in enumerate(new_name_order) - if location_table[name][0] not in {'Boss', 'Event', 'Drop', 'HintStone', 'Hint'}} + if location_table[name][0] not in non_indexed_location_types} class DisableType(Enum): ENABLED = 0 @@ -83,3 +85,57 @@ def LocationFactory(locations, player: int): return ret +def build_location_name_groups() -> dict: + + def fix_sing(t) -> tuple: + if isinstance(t, str): + return (t,) + return t + + def rename(d, k1, k2) -> None: + d[k2] = d[k1] + del d[k1] + + # whoever wrote the location table didn't realize they need to add a comma to mark a singleton as a tuple + # so we have to check types unfortunately + tags = set() + for v in location_table.values(): + if v[5] is not None: + tags.update(fix_sing(v[5])) + + sorted_tags = sorted(list(tags)) + + ret = { + tag: {k for k, v in location_table.items() + if v[5] is not None + and tag in fix_sing(v[5]) + and v[0] not in non_indexed_location_types} + for tag in sorted_tags + } + + # Delete tags which are a combination of other tags + del ret['Death Mountain'] + del ret['Forest'] + del ret['Gerudo'] + del ret['Kakariko'] + del ret['Market'] + + # Delete Vanilla and MQ tags because they are just way too broad + del ret['Vanilla'] + del ret['Master Quest'] + + rename(ret, 'Beehive', 'Beehives') + rename(ret, 'Cow', 'Cows') + rename(ret, 'Crate', 'Crates') + rename(ret, 'Deku Scrub', 'Deku Scrubs') + rename(ret, 'FlyingPot', 'Flying Pots') + rename(ret, 'Freestanding', 'Freestanding Items') + rename(ret, 'Pot', 'Pots') + rename(ret, 'RupeeTower', 'Rupee Groups') + rename(ret, 'SmallCrate', 'Small Crates') + rename(ret, 'the Market', 'Market') + rename(ret, 'the Graveyard', 'Graveyard') + rename(ret, 'the Lost Woods', 'Lost Woods') + + return ret + diff --git a/worlds/oot/LocationList.py b/worlds/oot/LocationList.py index 3f4602c428c1..27ad575699f5 100644 --- a/worlds/oot/LocationList.py +++ b/worlds/oot/LocationList.py @@ -238,7 +238,7 @@ def shop_address(shop_id, shelf_id): ("Market Night Green Rupee Crate 1", ("Crate", 0x21, (0,0,24), None, 'Rupee (1)', ("the Market", "Market", "Crate"))), ("Market Night Green Rupee Crate 2", ("Crate", 0x21, (0,0,25), None, 'Rupee (1)', ("the Market", "Market", "Crate"))), ("Market Night Green Rupee Crate 3", ("Crate", 0x21, (0,0,26), None, 'Rupee (1)', ("the Market", "Market", "Crate"))), - ("Market Dog Lady House Crate", ("Crate", 0x35, (0,0,3), None, 'Rupees (5)', ("Market", "Market", "Crate"))), + ("Market Dog Lady House Crate", ("Crate", 0x35, (0,0,3), None, 'Rupees (5)', ("the Market", "Market", "Crate"))), ("Market Guard House Child Crate", ("Crate", 0x4D, (0,0,6), None, 'Rupee (1)', ("the Market", "Market", "Crate"))), ("Market Guard House Child Pot 1", ("Pot", 0x4D, (0,0,9), None, 'Rupee (1)', ("the Market", "Market", "Pot"))), ("Market Guard House Child Pot 2", ("Pot", 0x4D, (0,0,10), None, 'Rupee (1)', ("the Market", "Market", "Pot"))), diff --git a/worlds/oot/Options.py b/worlds/oot/Options.py index 03f5346ceeed..120027e29dfa 100644 --- a/worlds/oot/Options.py +++ b/worlds/oot/Options.py @@ -30,7 +30,17 @@ def from_any(cls, data: typing.Any) -> Range: class Logic(Choice): - """Set the logic used for the generator.""" + """Set the logic used for the generator. + Glitchless: Normal gameplay. Can enable more difficult logical paths using the Logic Tricks option. + Glitched: Many powerful glitches expected, such as bomb hovering and clipping. + Glitched is incompatible with the following settings: + - All forms of entrance randomizer + - MQ dungeons + - Pot shuffle + - Freestanding item shuffle + - Crate shuffle + - Beehive shuffle + No Logic: No logic is used when placing items. Not recommended for most players.""" display_name = "Logic Rules" option_glitchless = 0 option_glitched = 1 @@ -38,12 +48,16 @@ class Logic(Choice): class NightTokens(Toggle): - """Nighttime skulltulas will logically require Sun's Song.""" + """When enabled, nighttime skulltulas logically require Sun's Song.""" display_name = "Nighttime Skulltulas Expect Sun's Song" class Forest(Choice): - """Set the state of Kokiri Forest and the path to Deku Tree.""" + """Set the state of Kokiri Forest and the path to Deku Tree. + Open: Neither the forest exit nor the path to Deku Tree is blocked. + Closed Deku: The forest exit is not blocked; the path to Deku Tree requires Kokiri Sword and Deku Shield. + Closed: Path to Deku Tree requires sword and shield. The forest exit is blocked until Deku Tree is beaten. + Closed forest will force child start, and becomes Closed Deku if interior entrances, overworld entrances, warp songs, or random spawn positions are enabled.""" display_name = "Forest" option_open = 0 option_closed_deku = 1 @@ -53,7 +67,10 @@ class Forest(Choice): class Gate(Choice): - """Set the state of the Kakariko Village gate.""" + """Set the state of the Kakariko Village gate for child. The gate is always open as adult. + Open: The gate starts open. Happy Mask Shop opens upon receiving Zelda's Letter. + Zelda: The gate and Mask Shop open upon receiving Zelda's Letter, without needing to show it to the guard. + Closed: Vanilla behavior; the gate and Mask Shop open upon showing Zelda's Letter to the gate guard.""" display_name = "Kakariko Gate" option_open = 0 option_zelda = 1 @@ -61,12 +78,15 @@ class Gate(Choice): class DoorOfTime(DefaultOnToggle): - """Open the Door of Time by default, without the Song of Time.""" + """When enabled, the Door of Time starts opened, without needing Song of Time.""" display_name = "Open Door of Time" class Fountain(Choice): - """Set the state of King Zora, blocking the way to Zora's Fountain.""" + """Set the state of King Zora, blocking the way to Zora's Fountain. + Open: King Zora starts moved as both ages. Ruto's Letter is removed. + Adult: King Zora must be moved as child, but is always moved for adult. + Closed: Vanilla behavior; King Zora must be shown Ruto's Letter as child to move him as both ages.""" display_name = "Zora's Fountain" option_open = 0 option_adult = 1 @@ -75,7 +95,10 @@ class Fountain(Choice): class Fortress(Choice): - """Set the requirements for access to Gerudo Fortress.""" + """Set the requirements for access to Gerudo Fortress. + Normal: Vanilla behavior; all four carpenters must be rescued. + Fast: Only one carpenter must be rescued, which is the one in the bottom-left of the fortress. + Open: The Gerudo Valley bridge starts repaired. Gerudo Membership Card is given to start if not shuffled.""" display_name = "Gerudo Fortress" option_normal = 0 option_fast = 1 @@ -84,7 +107,14 @@ class Fortress(Choice): class Bridge(Choice): - """Set the requirements for the Rainbow Bridge.""" + """Set the requirements for the Rainbow Bridge. + Open: The bridge is always present. + Vanilla: Bridge requires Shadow Medallion, Spirit Medallion, and Light Arrows. + Stones: Bridge requires a configurable amount of Spiritual Stones. + Medallions: Bridge requires a configurable amount of medallions. + Dungeons: Bridge requires a configurable amount of rewards (stones + medallions). + Tokens: Bridge requires a configurable amount of gold skulltula tokens. + Hearts: Bridge requires a configurable amount of hearts.""" display_name = "Rainbow Bridge Requirement" option_open = 0 option_vanilla = 1 @@ -122,8 +152,9 @@ class StartingAge(Choice): class InteriorEntrances(Choice): - """Shuffles interior entrances. "Simple" shuffles houses and Great Fairies; "All" includes Windmill, Link's House, - Temple of Time, and Kak potion shop.""" + """Shuffles interior entrances. + Simple: Houses and Great Fairies are shuffled. + All: In addition to Simple, includes Windmill, Link's House, Temple of Time, and the Kakariko potion shop.""" display_name = "Shuffle Interior Entrances" option_off = 0 option_simple = 1 @@ -137,7 +168,9 @@ class GrottoEntrances(Toggle): class DungeonEntrances(Choice): - """Shuffles dungeon entrances. Opens Deku, Fire and BotW to both ages. "All" includes Ganon's Castle.""" + """Shuffles dungeon entrances. When enabled, both ages will have access to Fire Temple, Bottom of the Well, and Deku Tree. + Simple: Shuffle dungeon entrances except for Ganon's Castle. + All: Include Ganon's Castle as well.""" display_name = "Shuffle Dungeon Entrances" option_off = 0 option_simple = 1 @@ -146,7 +179,9 @@ class DungeonEntrances(Choice): class BossEntrances(Choice): - """Shuffles boss entrances. "Limited" prevents age-mixing of bosses.""" + """Shuffles boss entrances. + Limited: Bosses will be limited to the ages that typically fight them. + Full: Bosses may be fought as different ages than usual. Child can defeat Phantom Ganon and Bongo Bongo.""" display_name = "Shuffle Boss Entrances" option_off = 0 option_limited = 1 @@ -178,19 +213,19 @@ class SpawnPositions(Choice): alias_true = 3 -class MixEntrancePools(Choice): - """Shuffles entrances into a mixed pool instead of separate ones. "indoor" keeps overworld entrances separate; "all" - mixes them in.""" - display_name = "Mix Entrance Pools" - option_off = 0 - option_indoor = 1 - option_all = 2 +# class MixEntrancePools(Choice): +# """Shuffles entrances into a mixed pool instead of separate ones. "indoor" keeps overworld entrances separate; "all" +# mixes them in.""" +# display_name = "Mix Entrance Pools" +# option_off = 0 +# option_indoor = 1 +# option_all = 2 -class DecoupleEntrances(Toggle): - """Decouple entrances when shuffling them. Also adds the one-way entrance from Gerudo Valley to Lake Hylia if - overworld is shuffled.""" - display_name = "Decouple Entrances" +# class DecoupleEntrances(Toggle): +# """Decouple entrances when shuffling them. Also adds the one-way entrance from Gerudo Valley to Lake Hylia if +# overworld is shuffled.""" +# display_name = "Decouple Entrances" class TriforceHunt(Toggle): @@ -216,13 +251,17 @@ class ExtraTriforces(Range): class LogicalChus(Toggle): - """Bombchus are properly considered in logic. The first found pack will have 20 chus; Kokiri Shop and Bazaar sell - refills; bombchus open Bombchu Bowling.""" + """Bombchus are properly considered in logic. + The first found pack will always have 20 chus. + Kokiri Shop and Bazaar will sell refills at reduced cost. + Bombchus open Bombchu Bowling.""" display_name = "Bombchus Considered in Logic" class DungeonShortcuts(Choice): - """Shortcuts to dungeon bosses are available without any requirements.""" + """Shortcuts to dungeon bosses are available without any requirements. + If enabled, this will impact the logic of dungeons where shortcuts are available. + Choice: Use the option "dungeon_shortcuts_list" to choose shortcuts.""" display_name = "Dungeon Boss Shortcuts Mode" option_off = 0 option_choice = 1 @@ -246,7 +285,11 @@ class DungeonShortcutsList(OptionSet): class MQDungeons(Choice): - """Choose between vanilla and Master Quest dungeon layouts.""" + """Choose between vanilla and Master Quest dungeon layouts. + Vanilla: All layouts are vanilla. + MQ: All layouts are Master Quest. + Specific: Use the option "mq_dungeons_list" to choose which dungeons are MQ. + Count: Use the option "mq_dungeons_count" to choose a number of random dungeons as MQ.""" display_name = "MQ Dungeon Mode" option_vanilla = 0 option_mq = 1 @@ -255,7 +298,7 @@ class MQDungeons(Choice): class MQDungeonList(OptionSet): - """Chosen dungeons to be MQ layout.""" + """With MQ dungeons as Specific: chosen dungeons to be MQ layout.""" display_name = "MQ Dungeon List" valid_keys = { "Deku Tree", @@ -274,41 +317,41 @@ class MQDungeonList(OptionSet): class MQDungeonCount(TrackRandomRange): - """Number of MQ dungeons, chosen randomly.""" + """With MQ dungeons as Count: number of randomly-selected dungeons to be MQ layout.""" display_name = "MQ Dungeon Count" range_start = 0 range_end = 12 default = 0 -class EmptyDungeons(Choice): - """Pre-completed dungeons are barren and rewards are given for free.""" - display_name = "Pre-completed Dungeons Mode" - option_none = 0 - option_specific = 1 - option_count = 2 +# class EmptyDungeons(Choice): +# """Pre-completed dungeons are barren and rewards are given for free.""" +# display_name = "Pre-completed Dungeons Mode" +# option_none = 0 +# option_specific = 1 +# option_count = 2 -class EmptyDungeonList(OptionSet): - """Chosen dungeons to be pre-completed.""" - display_name = "Pre-completed Dungeon List" - valid_keys = { - "Deku Tree", - "Dodongo's Cavern", - "Jabu Jabu's Belly", - "Forest Temple", - "Fire Temple", - "Water Temple", - "Shadow Temple", - "Spirit Temple", - } +# class EmptyDungeonList(OptionSet): +# """Chosen dungeons to be pre-completed.""" +# display_name = "Pre-completed Dungeon List" +# valid_keys = { +# "Deku Tree", +# "Dodongo's Cavern", +# "Jabu Jabu's Belly", +# "Forest Temple", +# "Fire Temple", +# "Water Temple", +# "Shadow Temple", +# "Spirit Temple", +# } -class EmptyDungeonCount(Range): - display_name = "Pre-completed Dungeon Count" - range_start = 1 - range_end = 8 - default = 2 +# class EmptyDungeonCount(Range): +# display_name = "Pre-completed Dungeon Count" +# range_start = 1 +# range_end = 8 +# default = 2 world_options: typing.Dict[str, type(Option)] = { @@ -341,59 +384,8 @@ class EmptyDungeonCount(Range): } -# class LacsCondition(Choice): -# """Set the requirements for the Light Arrow Cutscene in the Temple of Time.""" -# display_name = "Light Arrow Cutscene Requirement" -# option_vanilla = 0 -# option_stones = 1 -# option_medallions = 2 -# option_dungeons = 3 -# option_tokens = 4 - - -# class LacsStones(Range): -# """Set the number of Spiritual Stones required for LACS.""" -# display_name = "Spiritual Stones Required for LACS" -# range_start = 0 -# range_end = 3 -# default = 3 - - -# class LacsMedallions(Range): -# """Set the number of medallions required for LACS.""" -# display_name = "Medallions Required for LACS" -# range_start = 0 -# range_end = 6 -# default = 6 - - -# class LacsRewards(Range): -# """Set the number of dungeon rewards required for LACS.""" -# display_name = "Dungeon Rewards Required for LACS" -# range_start = 0 -# range_end = 9 -# default = 9 - - -# class LacsTokens(Range): -# """Set the number of Gold Skulltula Tokens required for LACS.""" -# display_name = "Tokens Required for LACS" -# range_start = 0 -# range_end = 100 -# default = 40 - - -# lacs_options: typing.Dict[str, type(Option)] = { -# "lacs_condition": LacsCondition, -# "lacs_stones": LacsStones, -# "lacs_medallions": LacsMedallions, -# "lacs_rewards": LacsRewards, -# "lacs_tokens": LacsTokens, -# } - - class BridgeStones(Range): - """Set the number of Spiritual Stones required for the rainbow bridge.""" + """With Stones bridge: set the number of Spiritual Stones required.""" display_name = "Spiritual Stones Required for Bridge" range_start = 0 range_end = 3 @@ -401,7 +393,7 @@ class BridgeStones(Range): class BridgeMedallions(Range): - """Set the number of medallions required for the rainbow bridge.""" + """With Medallions bridge: set the number of medallions required.""" display_name = "Medallions Required for Bridge" range_start = 0 range_end = 6 @@ -409,7 +401,7 @@ class BridgeMedallions(Range): class BridgeRewards(Range): - """Set the number of dungeon rewards required for the rainbow bridge.""" + """With Dungeons bridge: set the number of dungeon rewards required.""" display_name = "Dungeon Rewards Required for Bridge" range_start = 0 range_end = 9 @@ -417,7 +409,7 @@ class BridgeRewards(Range): class BridgeTokens(Range): - """Set the number of Gold Skulltula Tokens required for the rainbow bridge.""" + """With Tokens bridge: set the number of Gold Skulltula Tokens required.""" display_name = "Tokens Required for Bridge" range_start = 0 range_end = 100 @@ -425,7 +417,7 @@ class BridgeTokens(Range): class BridgeHearts(Range): - """Set the number of hearts required for the rainbow bridge.""" + """With Hearts bridge: set the number of hearts required.""" display_name = "Hearts Required for Bridge" range_start = 4 range_end = 20 @@ -442,7 +434,15 @@ class BridgeHearts(Range): class SongShuffle(Choice): - """Set where songs can appear.""" + """Set where songs can appear. + Song: Songs are shuffled into other song locations. + Dungeon: Songs are placed into end-of-dungeon locations: + - The 8 boss heart containers + - Sheik in Ice Cavern + - Lens of Truth chest in Bottom of the Well + - Ice Arrows chest in Gerudo Training Ground + - Impa at Hyrule Castle + Any: Songs can appear anywhere in the multiworld.""" display_name = "Shuffle Songs" option_song = 0 option_dungeon = 1 @@ -450,8 +450,10 @@ class SongShuffle(Choice): class ShopShuffle(Choice): - """Randomizes shop contents. "fixed_number" randomizes a specific number of items per shop; - "random_number" randomizes the value for each shop. """ + """Randomizes shop contents. + Off: Shops are not randomized at all. + Fixed Number: Shop contents are shuffled, and a specific number of multiworld locations exist in each shop, controlled by the "shop_slots" option. + Random Number: Same as Fixed Number, but the number of locations per shop is random and may differ between shops.""" display_name = "Shopsanity" option_off = 0 option_fixed_number = 1 @@ -459,15 +461,20 @@ class ShopShuffle(Choice): class ShopSlots(Range): - """Number of items per shop to be randomized into the main itempool. - Only active if Shopsanity is set to "fixed_number." """ + """With Shopsanity fixed number: quantity of multiworld locations per shop to be randomized.""" display_name = "Shuffled Shop Slots" range_start = 0 range_end = 4 class ShopPrices(Choice): - """Controls prices of shop items. "Normal" is a distribution from 0 to 300. "X Wallet" requires that wallet at max. "Affordable" is always 10 rupees.""" + """Controls prices of shop locations. + Normal: Balanced distribution from 0 to 300. + Affordable: Every shop location costs 10 rupees. + Starting Wallet: Prices capped at 99 rupees. + Adult's Wallet: Prices capped at 200 rupees. + Giant's Wallet: Prices capped at 500 rupees. + Tycoon's Wallet: Prices capped at 999 rupees.""" display_name = "Shopsanity Prices" option_normal = 0 option_affordable = 1 @@ -478,7 +485,10 @@ class ShopPrices(Choice): class TokenShuffle(Choice): - """Token rewards from Gold Skulltulas are shuffled into the pool.""" + """Token rewards from Gold Skulltulas can be shuffled into the pool. + Dungeons: Only skulltulas in dungeons are shuffled. + Overworld: Only skulltulas on the overworld (all skulltulas not in dungeons) are shuffled. + All: Every skulltula is shuffled.""" display_name = "Tokensanity" option_off = 0 option_dungeons = 1 @@ -487,7 +497,11 @@ class TokenShuffle(Choice): class ScrubShuffle(Choice): - """Shuffle the items sold by Business Scrubs, and set the prices.""" + """Shuffle the items sold by Business Scrubs, and set the prices. + Off: Only the three business scrubs that sell one-time upgrades in vanilla will have items at their vanilla prices. + Low/"Affordable": All scrub prices are 10 rupees. + Regular/"Expensive": All scrub prices are vanilla. + Random Prices: All scrub prices are randomized between 0 and 99 rupees.""" display_name = "Scrub Shuffle" option_off = 0 option_low = 1 @@ -513,7 +527,11 @@ class ShuffleOcarinas(Toggle): class ShuffleChildTrade(Choice): - """Controls the behavior of the start of the child trade quest.""" + """Controls the behavior of the start of the child trade quest. + Vanilla: Malon will give you the Weird Egg at Hyrule Castle. + Shuffle: Malon will give you a random item, and the Weird Egg is shuffled. + Skip Child Zelda: The game starts with Zelda already met, Zelda's Letter obtained, and the item from Impa obtained. + """ display_name = "Shuffle Child Trade Item" option_vanilla = 0 option_shuffle = 1 @@ -538,30 +556,39 @@ class ShuffleMedigoronCarpet(Toggle): class ShuffleFreestanding(Choice): - """Shuffles freestanding rupees, recovery hearts, Shadow Temple Spinning Pots, and Goron Pot.""" + """Shuffles freestanding rupees, recovery hearts, Shadow Temple Spinning Pots, and Goron Pot drops. + Dungeons: Only freestanding items in dungeons are shuffled. + Overworld: Only freestanding items in the overworld are shuffled. + All: All freestanding items are shuffled.""" display_name = "Shuffle Rupees & Hearts" option_off = 0 - option_all = 1 + option_dungeons = 1 option_overworld = 2 - option_dungeons = 3 + option_all = 3 class ShufflePots(Choice): - """Shuffles pots and flying pots which normally contain an item.""" + """Shuffles pots and flying pots which normally contain an item. + Dungeons: Only pots in dungeons are shuffled. + Overworld: Only pots in the overworld are shuffled. + All: All pots are shuffled.""" display_name = "Shuffle Pots" option_off = 0 - option_all = 1 + option_dungeons = 1 option_overworld = 2 - option_dungeons = 3 + option_all = 3 class ShuffleCrates(Choice): - """Shuffles large and small crates containing an item.""" + """Shuffles large and small crates containing an item. + Dungeons: Only crates in dungeons are shuffled. + Overworld: Only crates in the overworld are shuffled. + All: All crates are shuffled.""" display_name = "Shuffle Crates" option_off = 0 - option_all = 1 + option_dungeons = 1 option_overworld = 2 - option_dungeons = 3 + option_all = 3 class ShuffleBeehives(Toggle): @@ -597,72 +624,113 @@ class ShuffleFrogRupees(Toggle): class ShuffleMapCompass(Choice): - """Control where to shuffle dungeon maps and compasses.""" + """Control where to shuffle dungeon maps and compasses. + Remove: There will be no maps or compasses in the itempool. + Startwith: You start with all maps and compasses. + Vanilla: Maps and compasses remain vanilla. + Dungeon: Maps and compasses are shuffled within their original dungeon. + Regional: Maps and compasses are shuffled only in regions near the original dungeon. + Overworld: Maps and compasses are shuffled locally outside of dungeons. + Any Dungeon: Maps and compasses are shuffled locally in any dungeon. + Keysanity: Maps and compasses can be anywhere in the multiworld.""" display_name = "Maps & Compasses" option_remove = 0 option_startwith = 1 option_vanilla = 2 option_dungeon = 3 - option_overworld = 4 - option_any_dungeon = 5 - option_keysanity = 6 - option_regional = 7 + option_regional = 4 + option_overworld = 5 + option_any_dungeon = 6 + option_keysanity = 7 default = 1 - alias_anywhere = 6 + alias_anywhere = 7 class ShuffleKeys(Choice): - """Control where to shuffle dungeon small keys.""" + """Control where to shuffle dungeon small keys. + Remove/"Keysy": There will be no small keys in the itempool. All small key doors are automatically unlocked. + Vanilla: Small keys remain vanilla. You may start with extra small keys in some dungeons to prevent softlocks. + Dungeon: Small keys are shuffled within their original dungeon. + Regional: Small keys are shuffled only in regions near the original dungeon. + Overworld: Small keys are shuffled locally outside of dungeons. + Any Dungeon: Small keys are shuffled locally in any dungeon. + Keysanity: Small keys can be anywhere in the multiworld.""" display_name = "Small Keys" option_remove = 0 option_vanilla = 2 option_dungeon = 3 - option_overworld = 4 - option_any_dungeon = 5 - option_keysanity = 6 - option_regional = 7 + option_regional = 4 + option_overworld = 5 + option_any_dungeon = 6 + option_keysanity = 7 default = 3 alias_keysy = 0 - alias_anywhere = 6 + alias_anywhere = 7 class ShuffleGerudoKeys(Choice): - """Control where to shuffle the Thieves' Hideout small keys.""" + """Control where to shuffle the Thieves' Hideout small keys. + Vanilla: Hideout keys remain vanilla. + Regional: Hideout keys are shuffled only in the Gerudo Valley/Desert Colossus area. + Overworld: Hideout keys are shuffled locally outside of dungeons. + Any Dungeon: Hideout keys are shuffled locally in any dungeon. + Keysanity: Hideout keys can be anywhere in the multiworld.""" display_name = "Thieves' Hideout Keys" option_vanilla = 0 - option_overworld = 1 - option_any_dungeon = 2 - option_keysanity = 3 - option_regional = 4 - alias_anywhere = 3 + option_regional = 1 + option_overworld = 2 + option_any_dungeon = 3 + option_keysanity = 4 + alias_anywhere = 4 class ShuffleBossKeys(Choice): - """Control where to shuffle boss keys, except the Ganon's Castle Boss Key.""" + """Control where to shuffle boss keys, except the Ganon's Castle Boss Key. + Remove/"Keysy": There will be no boss keys in the itempool. All boss key doors are automatically unlocked. + Vanilla: Boss keys remain vanilla. You may start with extra small keys in some dungeons to prevent softlocks. + Dungeon: Boss keys are shuffled within their original dungeon. + Regional: Boss keys are shuffled only in regions near the original dungeon. + Overworld: Boss keys are shuffled locally outside of dungeons. + Any Dungeon: Boss keys are shuffled locally in any dungeon. + Keysanity: Boss keys can be anywhere in the multiworld.""" display_name = "Boss Keys" option_remove = 0 option_vanilla = 2 option_dungeon = 3 - option_overworld = 4 - option_any_dungeon = 5 - option_keysanity = 6 - option_regional = 7 + option_regional = 4 + option_overworld = 5 + option_any_dungeon = 6 + option_keysanity = 7 default = 3 alias_keysy = 0 - alias_anywhere = 6 + alias_anywhere = 7 class ShuffleGanonBK(Choice): - """Control how to shuffle the Ganon's Castle Boss Key.""" + """Control how to shuffle the Ganon's Castle Boss Key (GCBK). + Remove: GCBK is removed, and the boss key door is automatically unlocked. + Vanilla: GCBK remains vanilla. + Dungeon: GCBK is shuffled within its original dungeon. + Regional: GCBK is shuffled only in Hyrule Field, Market, and Hyrule Castle areas. + Overworld: GCBK is shuffled locally outside of dungeons. + Any Dungeon: GCBK is shuffled locally in any dungeon. + Keysanity: GCBK can be anywhere in the multiworld. + On LACS: GCBK is on the Light Arrow Cutscene, which requires Shadow and Spirit Medallions. + Stones: GCBK will be awarded when reaching the target number of Spiritual Stones. + Medallions: GCBK will be awarded when reaching the target number of medallions. + Dungeons: GCBK will be awarded when reaching the target number of dungeon rewards. + Tokens: GCBK will be awarded when reaching the target number of Gold Skulltula Tokens. + Hearts: GCBK will be awarded when reaching the target number of hearts. + """ display_name = "Ganon's Boss Key" option_remove = 0 option_vanilla = 2 option_dungeon = 3 - option_overworld = 4 - option_any_dungeon = 5 - option_keysanity = 6 - option_on_lacs = 7 - option_regional = 8 + option_regional = 4 + option_overworld = 5 + option_any_dungeon = 6 + option_keysanity = 7 + option_on_lacs = 8 option_stones = 9 option_medallions = 10 option_dungeons = 11 @@ -670,7 +738,7 @@ class ShuffleGanonBK(Choice): option_hearts = 13 default = 0 alias_keysy = 0 - alias_anywhere = 6 + alias_anywhere = 7 class EnhanceMC(Toggle): @@ -679,7 +747,7 @@ class EnhanceMC(Toggle): class GanonBKMedallions(Range): - """Set how many medallions are required to receive Ganon BK.""" + """With medallions GCBK: set how many medallions are required to receive GCBK.""" display_name = "Medallions Required for Ganon's BK" range_start = 1 range_end = 6 @@ -687,7 +755,7 @@ class GanonBKMedallions(Range): class GanonBKStones(Range): - """Set how many Spiritual Stones are required to receive Ganon BK.""" + """With stones GCBK: set how many Spiritual Stones are required to receive GCBK.""" display_name = "Spiritual Stones Required for Ganon's BK" range_start = 1 range_end = 3 @@ -695,7 +763,7 @@ class GanonBKStones(Range): class GanonBKRewards(Range): - """Set how many dungeon rewards are required to receive Ganon BK.""" + """With dungeons GCBK: set how many dungeon rewards are required to receive GCBK.""" display_name = "Dungeon Rewards Required for Ganon's BK" range_start = 1 range_end = 9 @@ -703,7 +771,7 @@ class GanonBKRewards(Range): class GanonBKTokens(Range): - """Set how many Gold Skulltula Tokens are required to receive Ganon BK.""" + """With tokens GCBK: set how many Gold Skulltula Tokens are required to receive GCBK.""" display_name = "Tokens Required for Ganon's BK" range_start = 1 range_end = 100 @@ -711,7 +779,7 @@ class GanonBKTokens(Range): class GanonBKHearts(Range): - """Set how many hearts are required to receive Ganon BK.""" + """With hearts GCBK: set how many hearts are required to receive GCBK.""" display_name = "Hearts Required for Ganon's BK" range_start = 4 range_end = 20 @@ -719,7 +787,9 @@ class GanonBKHearts(Range): class KeyRings(Choice): - """Dungeons have all small keys found at once, rather than individually.""" + """A key ring grants all dungeon small keys at once, rather than individually. + Choose: Use the option "key_rings_list" to choose which dungeons have key rings. + All: All dungeons have key rings instead of small keys.""" display_name = "Key Rings Mode" option_off = 0 option_choose = 1 @@ -728,7 +798,7 @@ class KeyRings(Choice): class KeyRingList(OptionSet): - """Select areas with keyrings rather than individual small keys.""" + """With key rings as Choose: select areas with key rings rather than individual small keys.""" display_name = "Key Ring Areas" valid_keys = { "Thieves' Hideout", @@ -828,7 +898,8 @@ class BigPoeCount(Range): class FAETorchCount(Range): - """Number of lit torches required to open Shadow Temple.""" + """Number of lit torches required to open Shadow Temple. + Does not affect logic; use the trick Shadow Temple Entry with Fire Arrows if desired.""" display_name = "Fire Arrow Entry Torch Count" range_start = 1 range_end = 24 @@ -853,7 +924,11 @@ class FAETorchCount(Range): class CorrectChestAppearance(Choice): - """Changes chest textures and/or sizes to match their contents. "Classic" is the old behavior of CSMC.""" + """Changes chest textures and/or sizes to match their contents. + Off: All chests have their vanilla size/appearance. + Textures: Chest textures reflect their contents. + Both: Like Textures, but progression items and boss keys get big chests, and other items get small chests. + Classic: Old behavior of CSMC; textures distinguish keys from non-keys, and size distinguishes importance.""" display_name = "Chest Appearance Matches Contents" option_off = 0 option_textures = 1 @@ -872,15 +947,24 @@ class InvisibleChests(Toggle): class CorrectPotCrateAppearance(Choice): - """Unchecked pots and crates have a different texture; unchecked beehives will wiggle. With textures_content, pots and crates have an appearance based on their contents; with textures_unchecked, all unchecked pots/crates have the same appearance.""" + """Changes the appearance of pots, crates, and beehives that contain items. + Off: Vanilla appearance for all containers. + Textures (Content): Unchecked pots and crates have a texture reflecting their contents. Unchecked beehives with progression items will wiggle. + Textures (Unchecked): Unchecked pots and crates are golden. Unchecked beehives will wiggle. + """ display_name = "Pot, Crate, and Beehive Appearance" option_off = 0 option_textures_content = 1 option_textures_unchecked = 2 + default = 2 class Hints(Choice): - """Gossip Stones can give hints about item locations.""" + """Gossip Stones can give hints about item locations. + None: Gossip Stones do not give hints. + Mask: Gossip Stones give hints with Mask of Truth. + Agony: Gossip Stones give hints wtih Stone of Agony. + Always: Gossip Stones always give hints.""" display_name = "Gossip Stones" option_none = 0 option_mask = 1 @@ -895,7 +979,9 @@ class MiscHints(DefaultOnToggle): class HintDistribution(Choice): - """Choose the hint distribution to use. Affects the frequency of strong hints, which items are always hinted, etc.""" + """Choose the hint distribution to use. Affects the frequency of strong hints, which items are always hinted, etc. + Detailed documentation on hint distributions can be found on the Archipelago GitHub or OoTRandomizer.com. + The Async hint distribution is intended for async multiworlds. It removes Way of the Hero hints to improve generation times, since they are not very useful in asyncs.""" display_name = "Hint Distribution" option_balanced = 0 option_ddr = 1 @@ -907,10 +993,13 @@ class HintDistribution(Choice): option_useless = 7 option_very_strong = 8 option_async = 9 + default = 9 class TextShuffle(Choice): - """Randomizes text in the game for comedic effect.""" + """Randomizes text in the game for comedic effect. + Except Hints: does not randomize important text such as hints, small/boss key information, and item prices. + Complete: randomizes every textbox, including the useful ones.""" display_name = "Text Shuffle" option_none = 0 option_except_hints = 1 @@ -946,7 +1035,8 @@ class HeroMode(Toggle): class StartingToD(Choice): - """Change the starting time of day.""" + """Change the starting time of day. + Daytime starts at Sunrise and ends at Sunset. Default is between Morning and Noon.""" display_name = "Starting Time of Day" option_default = 0 option_sunrise = 1 @@ -999,7 +1089,11 @@ class RupeeStart(Toggle): } class ItemPoolValue(Choice): - """Changes the number of items available in the game.""" + """Changes the number of items available in the game. + Plentiful: One extra copy of every major item. + Balanced: Original item pool. + Scarce: Extra copies of major items are removed. Heart containers are removed. + Minimal: All major item upgrades not used for locations are removed. All health is removed.""" display_name = "Item Pool" option_plentiful = 0 option_balanced = 1 @@ -1009,7 +1103,12 @@ class ItemPoolValue(Choice): class IceTraps(Choice): - """Adds ice traps to the item pool.""" + """Adds ice traps to the item pool. + Off: All ice traps are removed. + Normal: The vanilla quantity of ice traps are placed. + On/"Extra": There is a chance for some extra ice traps to be placed. + Mayhem: All added junk items are ice traps. + Onslaught: All junk items are replaced by ice traps, even those in the base pool.""" display_name = "Ice Traps" option_off = 0 option_normal = 1 @@ -1021,34 +1120,27 @@ class IceTraps(Choice): class IceTrapVisual(Choice): - """Changes the appearance of ice traps as freestanding items.""" - display_name = "Ice Trap Appearance" + """Changes the appearance of traps, including other games' traps, as freestanding items.""" + display_name = "Trap Appearance" option_major_only = 0 option_junk_only = 1 option_anything = 2 -class AdultTradeStart(OptionSet): - """Choose the items that can appear to start the adult trade sequence. By default it is Claim Check only.""" - display_name = "Adult Trade Sequence Items" - default = {"Claim Check"} - valid_keys = { - "Pocket Egg", - "Pocket Cucco", - "Cojiro", - "Odd Mushroom", - "Poachers Saw", - "Broken Sword", - "Prescription", - "Eyeball Frog", - "Eyedrops", - "Claim Check", - } - - def __init__(self, value: typing.Iterable[str]): - if not value: - value = self.default - super().__init__(value) +class AdultTradeStart(Choice): + """Choose the item that starts the adult trade sequence.""" + display_name = "Adult Trade Sequence Start" + option_pocket_egg = 0 + option_pocket_cucco = 1 + option_cojiro = 2 + option_odd_mushroom = 3 + option_poachers_saw = 4 + option_broken_sword = 5 + option_prescription = 6 + option_eyeball_frog = 7 + option_eyedrops = 8 + option_claim_check = 9 + default = 9 itempool_options: typing.Dict[str, type(Option)] = { @@ -1068,7 +1160,7 @@ class Targeting(Choice): class DisplayDpad(DefaultOnToggle): - """Show dpad icon on HUD for quick actions (ocarina, hover boots, iron boots).""" + """Show dpad icon on HUD for quick actions (ocarina, hover boots, iron boots, mask).""" display_name = "Display D-Pad HUD" @@ -1191,7 +1283,6 @@ class LogicTricks(OptionList): **world_options, **bridge_options, **dungeon_items_options, - # **lacs_options, **shuffle_options, **timesavers_options, **misc_options, diff --git a/worlds/oot/Patches.py b/worlds/oot/Patches.py index ab1e75d1b997..f83b34183cb8 100644 --- a/worlds/oot/Patches.py +++ b/worlds/oot/Patches.py @@ -2094,10 +2094,14 @@ def update_scrub_text(message, text_replacement, default_price, price, item_name if not world.dungeon_mq['Ganons Castle']: chest_name = 'Ganons Castle Light Trial Lullaby Chest' location = world.get_location(chest_name) - if location.item.game == 'Ocarina of Time': - item = read_rom_item(rom, location.item.index) + if not location.item.trap: + if location.item.game == 'Ocarina of Time': + item = read_rom_item(rom, location.item.index) + else: + item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) else: - item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) + looks_like_index = get_override_entry(world, location)[5] + item = read_rom_item(rom, looks_like_index) if item['chest_type'] in (GOLD_CHEST, GILDED_CHEST, SKULL_CHEST_BIG): rom.write_int16(0x321B176, 0xFC40) # original 0xFC48 @@ -2106,10 +2110,14 @@ def update_scrub_text(message, text_replacement, default_price, price, item_name chest_name = 'Spirit Temple Compass Chest' chest_address = 0x2B6B07C location = world.get_location(chest_name) - if location.item.game == 'Ocarina of Time': - item = read_rom_item(rom, location.item.index) + if not location.item.trap: + if location.item.game == 'Ocarina of Time': + item = read_rom_item(rom, location.item.index) + else: + item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) else: - item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) + looks_like_index = get_override_entry(world, location)[5] + item = read_rom_item(rom, looks_like_index) if item['chest_type'] in (BROWN_CHEST, SILVER_CHEST, SKULL_CHEST_SMALL): rom.write_int16(chest_address + 2, 0x0190) # X pos rom.write_int16(chest_address + 6, 0xFABC) # Z pos @@ -2120,10 +2128,14 @@ def update_scrub_text(message, text_replacement, default_price, price, item_name chest_address_0 = 0x21A02D0 # Address in setup 0 chest_address_2 = 0x21A06E4 # Address in setup 2 location = world.get_location(chest_name) - if location.item.game == 'Ocarina of Time': - item = read_rom_item(rom, location.item.index) + if not location.item.trap: + if location.item.game == 'Ocarina of Time': + item = read_rom_item(rom, location.item.index) + else: + item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) else: - item = read_rom_item(rom, AP_PROGRESSION if location.item.advancement else AP_JUNK) + looks_like_index = get_override_entry(world, location)[5] + item = read_rom_item(rom, looks_like_index) if item['chest_type'] in (BROWN_CHEST, SILVER_CHEST, SKULL_CHEST_SMALL): rom.write_int16(chest_address_0 + 6, 0x0172) # Z pos rom.write_int16(chest_address_2 + 6, 0x0172) # Z pos diff --git a/worlds/oot/Rules.py b/worlds/oot/Rules.py index 1f44cebdcfe2..fa198e0ce10e 100644 --- a/worlds/oot/Rules.py +++ b/worlds/oot/Rules.py @@ -223,9 +223,6 @@ def set_shop_rules(ootworld): # The goal is to automatically set item rules based on age requirements in case entrances were shuffled def set_entrances_based_rules(ootworld): - if ootworld.multiworld.accessibility == 'beatable': - return - all_state = ootworld.multiworld.get_all_state(False) for location in filter(lambda location: location.type == 'Shop', ootworld.get_locations()): diff --git a/worlds/oot/__init__.py b/worlds/oot/__init__.py index 539abd96747f..6af19683f460 100644 --- a/worlds/oot/__init__.py +++ b/worlds/oot/__init__.py @@ -10,7 +10,7 @@ logger = logging.getLogger("Ocarina of Time") -from .Location import OOTLocation, LocationFactory, location_name_to_id +from .Location import OOTLocation, LocationFactory, location_name_to_id, build_location_name_groups from .Entrance import OOTEntrance from .EntranceShuffle import shuffle_random_entrances, entrance_shuffle_table, EntranceShuffleError from .HintList import getRequiredHints @@ -163,11 +163,13 @@ class OOTWorld(World): "Bottle with Big Poe", "Bottle with Red Potion", "Bottle with Green Potion", "Bottle with Blue Potion", "Bottle with Fairy", "Bottle with Fish", "Bottle with Blue Fire", "Bottle with Bugs", "Bottle with Poe"}, - "Adult Trade Item": {"Pocket Egg", "Pocket Cucco", "Odd Mushroom", + "Adult Trade Item": {"Pocket Egg", "Pocket Cucco", "Cojiro", "Odd Mushroom", "Odd Potion", "Poachers Saw", "Broken Sword", "Prescription", - "Eyeball Frog", "Eyedrops", "Claim Check"} + "Eyeball Frog", "Eyedrops", "Claim Check"}, } + location_name_groups = build_location_name_groups() + def __init__(self, world, player): self.hint_data_available = threading.Event() self.collectible_flags_available = threading.Event() @@ -384,6 +386,7 @@ def generate_early(self): self.mq_dungeons_mode = 'count' self.mq_dungeons_count = 0 self.dungeon_mq = {item['name']: (item['name'] in mq_dungeons) for item in dungeon_table} + self.dungeon_mq['Thieves Hideout'] = False # fix for bug in SaveContext:287 # Empty dungeon placeholder for the moment self.empty_dungeons = {name: False for name in self.dungeon_mq} @@ -409,6 +412,9 @@ def generate_early(self): self.starting_tod = self.starting_tod.replace('_', '-') self.shuffle_scrubs = self.shuffle_scrubs.replace('_prices', '') + # Convert adult trade option to expected Set + self.adult_trade_start = {self.adult_trade_start.title().replace('_', ' ')} + # Get hint distribution self.hint_dist_user = read_json(data_path('Hints', f'{self.hint_dist}.json')) @@ -446,7 +452,7 @@ def generate_early(self): self.always_hints = [hint.name for hint in getRequiredHints(self)] # Determine items which are not considered advancement based on settings. They will never be excluded. - self.nonadvancement_items = {'Double Defense'} + self.nonadvancement_items = {'Double Defense', 'Deku Stick Capacity', 'Deku Nut Capacity'} if (self.damage_multiplier != 'ohko' and self.damage_multiplier != 'quadruple' and self.shuffle_scrubs == 'off' and not self.shuffle_grotto_entrances): # nayru's love may be required to prevent forced damage @@ -633,16 +639,18 @@ def fill_bosses(self, bossCount=9): self.multiworld.itempool.remove(item) self.hinted_dungeon_reward_locations[item.name] = loc - def create_item(self, name: str): + def create_item(self, name: str, allow_arbitrary_name: bool = False): if name in item_table: return OOTItem(name, self.player, item_table[name], False, (name in self.nonadvancement_items if getattr(self, 'nonadvancement_items', None) else False)) - return OOTItem(name, self.player, ('Event', True, None, None), True, False) + if allow_arbitrary_name: + return OOTItem(name, self.player, ('Event', True, None, None), True, False) + raise Exception(f"Invalid item name: {name}") def make_event_item(self, name, location, item=None): if item is None: - item = self.create_item(name) + item = self.create_item(name, allow_arbitrary_name=True) self.multiworld.push_item(location, item, collect=False) location.locked = True location.event = True @@ -800,23 +808,25 @@ def pre_fill(self): self.multiworld.itempool.remove(item) self.multiworld.random.shuffle(locations) fill_restrictive(self.multiworld, self.multiworld.get_all_state(False), locations, stage_items, - single_player_placement=True, lock=True) + single_player_placement=True, lock=True, allow_excluded=True) else: for dungeon_info in dungeon_table: dungeon_name = dungeon_info['name'] locations = gather_locations(self.multiworld, fill_stage, self.player, dungeon=dungeon_name) if isinstance(locations, list): dungeon_items = list(filter(lambda item: dungeon_name in item.name, stage_items)) + if not dungeon_items: + continue for item in dungeon_items: self.multiworld.itempool.remove(item) self.multiworld.random.shuffle(locations) fill_restrictive(self.multiworld, self.multiworld.get_all_state(False), locations, dungeon_items, - single_player_placement=True, lock=True) + single_player_placement=True, lock=True, allow_excluded=True) # Place songs # 5 built-in retries because this section can fail sometimes if self.shuffle_song_items != 'any': - tries = 5 + tries = 10 if self.shuffle_song_items == 'song': song_locations = list(filter(lambda location: location.type == 'Song', self.multiworld.get_unfilled_locations(player=self.player))) @@ -852,7 +862,7 @@ def pre_fill(self): try: self.multiworld.random.shuffle(song_locations) fill_restrictive(self.multiworld, self.multiworld.get_all_state(False), song_locations[:], songs[:], - True, True) + single_player_placement=True, lock=True, allow_excluded=True) logger.debug(f"Successfully placed songs for player {self.player} after {6 - tries} attempt(s)") except FillError as e: tries -= 1 @@ -888,7 +898,8 @@ def pre_fill(self): self.multiworld.random.shuffle(shop_locations) for item in shop_prog + shop_junk: self.multiworld.itempool.remove(item) - fill_restrictive(self.multiworld, self.multiworld.get_all_state(False), shop_locations, shop_prog, True, True) + fill_restrictive(self.multiworld, self.multiworld.get_all_state(False), shop_locations, shop_prog, + single_player_placement=True, lock=True, allow_excluded=True) fast_fill(self.multiworld, shop_junk, shop_locations) for loc in shop_locations: loc.locked = True @@ -963,7 +974,7 @@ def stage_pre_fill(cls, multiworld: MultiWorld): multiworld.itempool.remove(item) multiworld.random.shuffle(locations) fill_restrictive(multiworld, multiworld.get_all_state(False), locations, group_stage_items, - single_player_placement=False, lock=True) + single_player_placement=False, lock=True, allow_excluded=True) if fill_stage == 'Song': # We don't want song locations to contain progression unless it's a song # or it was marked as priority. @@ -984,7 +995,7 @@ def stage_pre_fill(cls, multiworld: MultiWorld): multiworld.itempool.remove(item) multiworld.random.shuffle(locations) fill_restrictive(multiworld, multiworld.get_all_state(False), locations, group_dungeon_items, - single_player_placement=False, lock=True) + single_player_placement=False, lock=True, allow_excluded=True) def generate_output(self, output_directory: str): if self.hints != 'none': @@ -1051,7 +1062,10 @@ def generate_output(self, output_directory: str): def stage_generate_output(cls, multiworld: MultiWorld, output_directory: str): def hint_type_players(hint_type: str) -> set: return {autoworld.player for autoworld in multiworld.get_game_worlds("Ocarina of Time") - if autoworld.hints != 'none' and autoworld.hint_dist_user['distribution'][hint_type]['copies'] > 0} + if autoworld.hints != 'none' + and autoworld.hint_dist_user['distribution'][hint_type]['copies'] > 0 + and (autoworld.hint_dist_user['distribution'][hint_type]['fixed'] > 0 + or autoworld.hint_dist_user['distribution'][hint_type]['weight'] > 0)} try: item_hint_players = hint_type_players('item') @@ -1078,10 +1092,10 @@ def hint_type_players(hint_type: str) -> set: if loc.game == "Ocarina of Time" and loc.item.code and (not loc.locked or (oot_is_item_of_type(loc.item, 'Song') or - (oot_is_item_of_type(loc.item, 'SmallKey') and multiworld.worlds[loc.player].shuffle_smallkeys == 'any_dungeon') or - (oot_is_item_of_type(loc.item, 'HideoutSmallKey') and multiworld.worlds[loc.player].shuffle_hideoutkeys == 'any_dungeon') or - (oot_is_item_of_type(loc.item, 'BossKey') and multiworld.worlds[loc.player].shuffle_bosskeys == 'any_dungeon') or - (oot_is_item_of_type(loc.item, 'GanonBossKey') and multiworld.worlds[loc.player].shuffle_ganon_bosskey == 'any_dungeon'))): + (oot_is_item_of_type(loc.item, 'SmallKey') and multiworld.worlds[loc.player].shuffle_smallkeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'HideoutSmallKey') and multiworld.worlds[loc.player].shuffle_hideoutkeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'BossKey') and multiworld.worlds[loc.player].shuffle_bosskeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'GanonBossKey') and multiworld.worlds[loc.player].shuffle_ganon_bosskey in ('overworld', 'any_dungeon', 'regional')))): if loc.player in barren_hint_players: hint_area = get_hint_area(loc) items_by_region[loc.player][hint_area]['weight'] += 1 @@ -1096,7 +1110,12 @@ def hint_type_players(hint_type: str) -> set: elif barren_hint_players or woth_hint_players: # Check only relevant oot locations for barren/woth for player in (barren_hint_players | woth_hint_players): for loc in multiworld.worlds[player].get_locations(): - if loc.item.code and (not loc.locked or oot_is_item_of_type(loc.item, 'Song')): + if loc.item.code and (not loc.locked or + (oot_is_item_of_type(loc.item, 'Song') or + (oot_is_item_of_type(loc.item, 'SmallKey') and multiworld.worlds[loc.player].shuffle_smallkeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'HideoutSmallKey') and multiworld.worlds[loc.player].shuffle_hideoutkeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'BossKey') and multiworld.worlds[loc.player].shuffle_bosskeys in ('overworld', 'any_dungeon', 'regional')) or + (oot_is_item_of_type(loc.item, 'GanonBossKey') and multiworld.worlds[loc.player].shuffle_ganon_bosskey in ('overworld', 'any_dungeon', 'regional')))): if player in barren_hint_players: hint_area = get_hint_area(loc) items_by_region[player][hint_area]['weight'] += 1 @@ -1183,6 +1202,15 @@ def get_entrance_to_region(region): er_hint_data[self.player][location.address] = main_entrance.name logger.debug(f"Set {location.name} hint data to {main_entrance.name}") + def write_spoiler(self, spoiler_handle: typing.TextIO) -> None: + required_trials_str = ", ".join(t for t in self.skipped_trials if not self.skipped_trials[t]) + spoiler_handle.write(f"\n\nTrials ({self.multiworld.get_player_name(self.player)}): {required_trials_str}\n") + + if self.shopsanity != 'off': + spoiler_handle.write(f"\nShop Prices ({self.multiworld.get_player_name(self.player)}):\n") + for k, v in self.shop_prices.items(): + spoiler_handle.write(f"{k}: {v} Rupees\n") + # Key ring handling: # Key rings are multiple items glued together into one, so we need to give # the appropriate number of keys in the collection state when they are @@ -1265,25 +1293,13 @@ def is_major_item(self, item: OOTItem): # Specifically ensures that only real items are gotten, not any events. # In particular, ensures that Time Travel needs to be found. def get_state_with_complete_itempool(self): - all_state = self.multiworld.get_all_state(use_cache=False) - # Remove event progression items - for item, player in all_state.prog_items: - if player == self.player and (item not in item_table or item_table[item][2] is None): - all_state.prog_items[(item, player)] = 0 - # Remove all events and checked locations - all_state.locations_checked = {loc for loc in all_state.locations_checked if loc.player != self.player} - all_state.events = {loc for loc in all_state.events if loc.player != self.player} + all_state = CollectionState(self.multiworld) + for item in self.multiworld.itempool: + if item.player == self.player: + self.multiworld.worlds[item.player].collect(all_state, item) # If free_scarecrow give Scarecrow Song if self.free_scarecrow: all_state.collect(self.create_item("Scarecrow Song"), event=True) - - # Invalidate caches - all_state.child_reachable_regions[self.player] = set() - all_state.adult_reachable_regions[self.player] = set() - all_state.child_blocked_connections[self.player] = set() - all_state.adult_blocked_connections[self.player] = set() - all_state.day_reachable_regions[self.player] = set() - all_state.dampe_reachable_regions[self.player] = set() all_state.stale[self.player] = True return all_state @@ -1349,7 +1365,7 @@ def gather_locations(multiworld: MultiWorld, condition = lambda location: location.name in dungeon_song_locations locations += filter(condition, multiworld.get_unfilled_locations(player=player)) else: - if any(map(lambda v: v in {'keysanity'}, fill_opts.values())): + if any(map(lambda v: v == 'keysanity', fill_opts.values())): return None for player, option in fill_opts.items(): condition = functools.partial(valid_dungeon_item_location,