From dba95d12f98ed4a3c83e139f926efcb9d82dcdf7 Mon Sep 17 00:00:00 2001 From: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> Date: Thu, 8 May 2025 17:50:21 -0400 Subject: [PATCH] Refactor to avoid floating imports (Violet part 3). --- worlds/jakanddaxter/Regions.py | 7 ++--- worlds/jakanddaxter/Rules.py | 26 ++++++++++--------- worlds/jakanddaxter/__init__.py | 10 +++---- worlds/jakanddaxter/regs/BoggySwampRegions.py | 6 +++-- worlds/jakanddaxter/regs/FireCanyonRegions.py | 6 +++-- .../regs/ForbiddenJungleRegions.py | 6 +++-- worlds/jakanddaxter/regs/GeyserRockRegions.py | 6 +++-- .../regs/GolAndMaiasCitadelRegions.py | 6 +++-- worlds/jakanddaxter/regs/LavaTubeRegions.py | 6 +++-- .../regs/LostPrecursorCityRegions.py | 6 +++-- .../jakanddaxter/regs/MistyIslandRegions.py | 6 +++-- .../jakanddaxter/regs/MountainPassRegions.py | 6 +++-- .../regs/PrecursorBasinRegions.py | 6 +++-- .../jakanddaxter/regs/RockVillageRegions.py | 6 +++-- .../regs/SandoverVillageRegions.py | 6 +++-- .../jakanddaxter/regs/SentinelBeachRegions.py | 6 +++-- .../jakanddaxter/regs/SnowyMountainRegions.py | 6 +++-- worlds/jakanddaxter/regs/SpiderCaveRegions.py | 6 +++-- .../regs/VolcanicCraterRegions.py | 6 +++-- 19 files changed, 87 insertions(+), 52 deletions(-) diff --git a/worlds/jakanddaxter/Regions.py b/worlds/jakanddaxter/Regions.py index 38f2f77fd8..2ab55f9227 100644 --- a/worlds/jakanddaxter/Regions.py +++ b/worlds/jakanddaxter/Regions.py @@ -1,7 +1,5 @@ import typing - from Options import OptionError -from . import JakAndDaxterWorld from .Items import item_table from .Options import EnableOrbsanity, CompletionCondition from .Rules import can_reach_orbs_global @@ -24,8 +22,11 @@ from .regs import (GeyserRockRegions as GeyserRock, GolAndMaiasCitadelRegions as GolAndMaiasCitadel) from .regs.RegionBase import JakAndDaxterRegion +if typing.TYPE_CHECKING: + from . import JakAndDaxterWorld -def create_regions(world: JakAndDaxterWorld): + +def create_regions(world: "JakAndDaxterWorld"): multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/Rules.py b/worlds/jakanddaxter/Rules.py index 56dd0ec848..ec9b2e1447 100644 --- a/worlds/jakanddaxter/Rules.py +++ b/worlds/jakanddaxter/Rules.py @@ -1,7 +1,6 @@ import typing from BaseClasses import CollectionState from Options import OptionError -from . import JakAndDaxterWorld from .Options import (EnableOrbsanity, GlobalOrbsanityBundleSize, PerLevelOrbsanityBundleSize, @@ -14,8 +13,11 @@ from .locs import CellLocations as Cells from .Locations import location_table from .Levels import level_table +if typing.TYPE_CHECKING: + from . import JakAndDaxterWorld -def set_orb_trade_rule(world: JakAndDaxterWorld): + +def set_orb_trade_rule(world: "JakAndDaxterWorld"): options = world.options player = world.player @@ -27,7 +29,7 @@ def set_orb_trade_rule(world: JakAndDaxterWorld): can_trade_orbsanity(state, player, world, required_orbs, required_previous_trade)) -def recalculate_reachable_orbs(state: CollectionState, player: int, world: JakAndDaxterWorld) -> None: +def recalculate_reachable_orbs(state: CollectionState, player: int, world: "JakAndDaxterWorld") -> None: # Recalculate every level, every time the cache is stale, because you don't know # when a specific bundle of orbs in one level may unlock access to another. @@ -43,7 +45,7 @@ def recalculate_reachable_orbs(state: CollectionState, player: int, world: JakAn def count_reachable_orbs_global(state: CollectionState, - world: JakAndDaxterWorld) -> int: + world: "JakAndDaxterWorld") -> int: accessible_orbs = 0 for level_regions in world.level_to_orb_regions.values(): @@ -54,7 +56,7 @@ def count_reachable_orbs_global(state: CollectionState, def count_reachable_orbs_level(state: CollectionState, - world: JakAndDaxterWorld, + world: "JakAndDaxterWorld", level_name: str = "") -> int: accessible_orbs = 0 @@ -66,7 +68,7 @@ def count_reachable_orbs_level(state: CollectionState, def can_reach_orbs_global(state: CollectionState, player: int, - world: JakAndDaxterWorld, + world: "JakAndDaxterWorld", orb_amount: int) -> bool: if not state.prog_items[player]["Reachable Orbs Fresh"]: @@ -77,7 +79,7 @@ def can_reach_orbs_global(state: CollectionState, def can_reach_orbs_level(state: CollectionState, player: int, - world: JakAndDaxterWorld, + world: "JakAndDaxterWorld", level_name: str, orb_amount: int) -> bool: @@ -89,7 +91,7 @@ def can_reach_orbs_level(state: CollectionState, def can_trade_vanilla(state: CollectionState, player: int, - world: JakAndDaxterWorld, + world: "JakAndDaxterWorld", required_orbs: int, required_previous_trade: typing.Optional[int] = None) -> bool: @@ -106,7 +108,7 @@ def can_trade_vanilla(state: CollectionState, def can_trade_orbsanity(state: CollectionState, player: int, - world: JakAndDaxterWorld, + world: "JakAndDaxterWorld", required_orbs: int, required_previous_trade: typing.Optional[int] = None) -> bool: @@ -129,7 +131,7 @@ def can_fight(state: CollectionState, player: int) -> bool: return state.has_any(("Jump Dive", "Jump Kick", "Punch", "Kick"), player) -def enforce_multiplayer_limits(world: JakAndDaxterWorld): +def enforce_multiplayer_limits(world: "JakAndDaxterWorld"): options = world.options friendly_message = "" @@ -188,7 +190,7 @@ def enforce_multiplayer_limits(world: JakAndDaxterWorld): f"(Use at your own risk!)") -def enforce_singleplayer_limits(world: JakAndDaxterWorld): +def enforce_singleplayer_limits(world: "JakAndDaxterWorld"): options = world.options friendly_message = "" @@ -219,7 +221,7 @@ def enforce_singleplayer_limits(world: JakAndDaxterWorld): f"(Use at your own risk!)") -def verify_orb_trade_amounts(world: JakAndDaxterWorld): +def verify_orb_trade_amounts(world: "JakAndDaxterWorld"): if world.total_trade_orbs > 2000: raise OptionError(f"{world.player_name}: Required number of orbs for all trades ({world.total_trade_orbs}) " diff --git a/worlds/jakanddaxter/__init__.py b/worlds/jakanddaxter/__init__.py index bb2542e238..54fea4b428 100644 --- a/worlds/jakanddaxter/__init__.py +++ b/worlds/jakanddaxter/__init__.py @@ -34,6 +34,11 @@ from .Locations import (JakAndDaxterLocation, special_location_table, cache_location_table, orb_location_table) +from .Regions import create_regions +from .Rules import (enforce_multiplayer_limits, + enforce_singleplayer_limits, + verify_orb_trade_amounts, + set_orb_trade_rule) from .locs import (CellLocations as Cells, ScoutLocations as Scouts, SpecialLocations as Specials, @@ -263,10 +268,8 @@ class JakAndDaxterWorld(World): enforce_friendly_options = self.settings.enforce_friendly_options if enforce_friendly_options: if self.multiworld.players > 1: - from .Rules import enforce_multiplayer_limits enforce_multiplayer_limits(self) else: - from .Rules import enforce_singleplayer_limits enforce_singleplayer_limits(self) # Calculate the number of power cells needed for full region access, the number being replaced by traps, @@ -283,7 +286,6 @@ class JakAndDaxterWorld(World): # Verify that we didn't overload the trade amounts with more orbs than exist in the world. # This is easy to do by accident even in a singleplayer world. self.total_trade_orbs = (9 * self.options.citizen_orb_trade_amount) + (6 * self.options.oracle_orb_trade_amount) - from .Rules import verify_orb_trade_amounts verify_orb_trade_amounts(self) # Cache the orb bundle size and item name for quicker reference. @@ -313,12 +315,10 @@ class JakAndDaxterWorld(World): self.trap_weights = self.options.trap_weights.weights_pair # Options drive which trade rules to use, so they need to be setup before we create_regions. - from .Rules import set_orb_trade_rule set_orb_trade_rule(self) # This will also set Locations, Location access rules, Region access rules, etc. def create_regions(self) -> None: - from .Regions import create_regions create_regions(self) # Don't forget to add the created regions to the multiworld! diff --git a/worlds/jakanddaxter/regs/BoggySwampRegions.py b/worlds/jakanddaxter/regs/BoggySwampRegions.py index 9f8dce154a..0c067570ec 100644 --- a/worlds/jakanddaxter/regs/BoggySwampRegions.py +++ b/worlds/jakanddaxter/regs/BoggySwampRegions.py @@ -1,11 +1,13 @@ from BaseClasses import CollectionState from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/FireCanyonRegions.py b/worlds/jakanddaxter/regs/FireCanyonRegions.py index d2d58fc83e..f113558e81 100644 --- a/worlds/jakanddaxter/regs/FireCanyonRegions.py +++ b/worlds/jakanddaxter/regs/FireCanyonRegions.py @@ -1,11 +1,13 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_reach_orbs_level from ..locs import CellLocations as Cells, ScoutLocations as Scouts -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/ForbiddenJungleRegions.py b/worlds/jakanddaxter/regs/ForbiddenJungleRegions.py index d73212b029..12020a5da3 100644 --- a/worlds/jakanddaxter/regs/ForbiddenJungleRegions.py +++ b/worlds/jakanddaxter/regs/ForbiddenJungleRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> tuple[JakAndDaxterRegion, ...]: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> tuple[JakAndDaxterRegion, ...]: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/GeyserRockRegions.py b/worlds/jakanddaxter/regs/GeyserRockRegions.py index c680c5f3cf..fb1736c248 100644 --- a/worlds/jakanddaxter/regs/GeyserRockRegions.py +++ b/worlds/jakanddaxter/regs/GeyserRockRegions.py @@ -1,11 +1,13 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_reach_orbs_level from ..locs import ScoutLocations as Scouts -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/GolAndMaiasCitadelRegions.py b/worlds/jakanddaxter/regs/GolAndMaiasCitadelRegions.py index 2bc73ad5cb..735eb449e1 100644 --- a/worlds/jakanddaxter/regs/GolAndMaiasCitadelRegions.py +++ b/worlds/jakanddaxter/regs/GolAndMaiasCitadelRegions.py @@ -1,12 +1,14 @@ from BaseClasses import CollectionState from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity, CompletionCondition -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level # God help me... here we go. -def build_regions(level_name: str, world: JakAndDaxterWorld) -> tuple[JakAndDaxterRegion | None, ...]: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> tuple[JakAndDaxterRegion | None, ...]: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/LavaTubeRegions.py b/worlds/jakanddaxter/regs/LavaTubeRegions.py index cf504113b4..91ecd54d66 100644 --- a/worlds/jakanddaxter/regs/LavaTubeRegions.py +++ b/worlds/jakanddaxter/regs/LavaTubeRegions.py @@ -1,11 +1,13 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_reach_orbs_level from ..locs import CellLocations as Cells, ScoutLocations as Scouts -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/LostPrecursorCityRegions.py b/worlds/jakanddaxter/regs/LostPrecursorCityRegions.py index f2db996375..79b9a70b17 100644 --- a/worlds/jakanddaxter/regs/LostPrecursorCityRegions.py +++ b/worlds/jakanddaxter/regs/LostPrecursorCityRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/MistyIslandRegions.py b/worlds/jakanddaxter/regs/MistyIslandRegions.py index 1bd294947d..a41bf5e8d4 100644 --- a/worlds/jakanddaxter/regs/MistyIslandRegions.py +++ b/worlds/jakanddaxter/regs/MistyIslandRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/MountainPassRegions.py b/worlds/jakanddaxter/regs/MountainPassRegions.py index 1cf795baa0..763a86afee 100644 --- a/worlds/jakanddaxter/regs/MountainPassRegions.py +++ b/worlds/jakanddaxter/regs/MountainPassRegions.py @@ -1,12 +1,14 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_reach_orbs_level from ..locs import ScoutLocations as Scouts from worlds.generic.Rules import add_rule -def build_regions(level_name: str, world: JakAndDaxterWorld) -> tuple[JakAndDaxterRegion, ...]: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> tuple[JakAndDaxterRegion, ...]: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/PrecursorBasinRegions.py b/worlds/jakanddaxter/regs/PrecursorBasinRegions.py index f7fb97180d..236039deaa 100644 --- a/worlds/jakanddaxter/regs/PrecursorBasinRegions.py +++ b/worlds/jakanddaxter/regs/PrecursorBasinRegions.py @@ -1,11 +1,13 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_reach_orbs_level from ..locs import CellLocations as Cells, ScoutLocations as Scouts -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/RockVillageRegions.py b/worlds/jakanddaxter/regs/RockVillageRegions.py index 0053a3efa1..ccc228e299 100644 --- a/worlds/jakanddaxter/regs/RockVillageRegions.py +++ b/worlds/jakanddaxter/regs/RockVillageRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> tuple[JakAndDaxterRegion, ...]: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> tuple[JakAndDaxterRegion, ...]: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/SandoverVillageRegions.py b/worlds/jakanddaxter/regs/SandoverVillageRegions.py index a727afcea4..d5c32d677f 100644 --- a/worlds/jakanddaxter/regs/SandoverVillageRegions.py +++ b/worlds/jakanddaxter/regs/SandoverVillageRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/SentinelBeachRegions.py b/worlds/jakanddaxter/regs/SentinelBeachRegions.py index d651bca9a6..73e08d9fc3 100644 --- a/worlds/jakanddaxter/regs/SentinelBeachRegions.py +++ b/worlds/jakanddaxter/regs/SentinelBeachRegions.py @@ -1,11 +1,13 @@ from BaseClasses import CollectionState from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/SnowyMountainRegions.py b/worlds/jakanddaxter/regs/SnowyMountainRegions.py index 67782195ec..c19a8bc1fe 100644 --- a/worlds/jakanddaxter/regs/SnowyMountainRegions.py +++ b/worlds/jakanddaxter/regs/SnowyMountainRegions.py @@ -1,12 +1,14 @@ from BaseClasses import CollectionState from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level # God help me... here we go. -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/SpiderCaveRegions.py b/worlds/jakanddaxter/regs/SpiderCaveRegions.py index e99fbcf62d..71bfd77487 100644 --- a/worlds/jakanddaxter/regs/SpiderCaveRegions.py +++ b/worlds/jakanddaxter/regs/SpiderCaveRegions.py @@ -1,10 +1,12 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_fight, can_reach_orbs_level -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player diff --git a/worlds/jakanddaxter/regs/VolcanicCraterRegions.py b/worlds/jakanddaxter/regs/VolcanicCraterRegions.py index 4c310c4b22..d59917ff17 100644 --- a/worlds/jakanddaxter/regs/VolcanicCraterRegions.py +++ b/worlds/jakanddaxter/regs/VolcanicCraterRegions.py @@ -1,11 +1,13 @@ from .RegionBase import JakAndDaxterRegion from ..Options import EnableOrbsanity -from .. import JakAndDaxterWorld +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from .. import JakAndDaxterWorld from ..Rules import can_free_scout_flies, can_reach_orbs_level from ..locs import ScoutLocations as Scouts -def build_regions(level_name: str, world: JakAndDaxterWorld) -> JakAndDaxterRegion: +def build_regions(level_name: str, world: "JakAndDaxterWorld") -> JakAndDaxterRegion: multiworld = world.multiworld options = world.options player = world.player