Refactor to avoid floating imports (Violet part 3).

This commit is contained in:
massimilianodelliubaldini
2025-05-08 17:50:21 -04:00
parent 965e9e3a5c
commit dba95d12f9
19 changed files with 87 additions and 52 deletions

View File

@@ -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

View File

@@ -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}) "

View File

@@ -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!

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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