mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Core: remove module level AutoWorld import (#2790)
With BaseClasses running `worlds.__init__.py` and worlds importing `from BaseClasses`, this is likely to result in some extra code being run because of partial recursive imports. This now lazily loads `worlds` when needed, at which point `sys.modules` should be properly populated.
This commit is contained in:
@@ -18,11 +18,14 @@ import NetUtils
|
|||||||
import Options
|
import Options
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from worlds import AutoWorld
|
||||||
|
|
||||||
|
|
||||||
class Group(TypedDict, total=False):
|
class Group(TypedDict, total=False):
|
||||||
name: str
|
name: str
|
||||||
game: str
|
game: str
|
||||||
world: auto_world
|
world: "AutoWorld.World"
|
||||||
players: Set[int]
|
players: Set[int]
|
||||||
item_pool: Set[str]
|
item_pool: Set[str]
|
||||||
replacement_items: Dict[int, Optional[str]]
|
replacement_items: Dict[int, Optional[str]]
|
||||||
@@ -55,7 +58,7 @@ class MultiWorld():
|
|||||||
plando_texts: List[Dict[str, str]]
|
plando_texts: List[Dict[str, str]]
|
||||||
plando_items: List[List[Dict[str, Any]]]
|
plando_items: List[List[Dict[str, Any]]]
|
||||||
plando_connections: List
|
plando_connections: List
|
||||||
worlds: Dict[int, auto_world]
|
worlds: Dict[int, "AutoWorld.World"]
|
||||||
groups: Dict[int, Group]
|
groups: Dict[int, Group]
|
||||||
regions: RegionManager
|
regions: RegionManager
|
||||||
itempool: List[Item]
|
itempool: List[Item]
|
||||||
@@ -219,6 +222,8 @@ class MultiWorld():
|
|||||||
def add_group(self, name: str, game: str, players: Set[int] = frozenset()) -> Tuple[int, Group]:
|
def add_group(self, name: str, game: str, players: Set[int] = frozenset()) -> Tuple[int, Group]:
|
||||||
"""Create a group with name and return the assigned player ID and group.
|
"""Create a group with name and return the assigned player ID and group.
|
||||||
If a group of this name already exists, the set of players is extended instead of creating a new one."""
|
If a group of this name already exists, the set of players is extended instead of creating a new one."""
|
||||||
|
from worlds import AutoWorld
|
||||||
|
|
||||||
for group_id, group in self.groups.items():
|
for group_id, group in self.groups.items():
|
||||||
if group["name"] == name:
|
if group["name"] == name:
|
||||||
group["players"] |= players
|
group["players"] |= players
|
||||||
@@ -253,6 +258,8 @@ class MultiWorld():
|
|||||||
|
|
||||||
def set_options(self, args: Namespace) -> None:
|
def set_options(self, args: Namespace) -> None:
|
||||||
# TODO - remove this section once all worlds use options dataclasses
|
# TODO - remove this section once all worlds use options dataclasses
|
||||||
|
from worlds import AutoWorld
|
||||||
|
|
||||||
all_keys: Set[str] = {key for player in self.player_ids for key in
|
all_keys: Set[str] = {key for player in self.player_ids for key in
|
||||||
AutoWorld.AutoWorldRegister.world_types[self.game[player]].options_dataclass.type_hints}
|
AutoWorld.AutoWorldRegister.world_types[self.game[player]].options_dataclass.type_hints}
|
||||||
for option_key in all_keys:
|
for option_key in all_keys:
|
||||||
@@ -270,6 +277,8 @@ class MultiWorld():
|
|||||||
for option_key in options_dataclass.type_hints})
|
for option_key in options_dataclass.type_hints})
|
||||||
|
|
||||||
def set_item_links(self):
|
def set_item_links(self):
|
||||||
|
from worlds import AutoWorld
|
||||||
|
|
||||||
item_links = {}
|
item_links = {}
|
||||||
replacement_prio = [False, True, None]
|
replacement_prio = [False, True, None]
|
||||||
for player in self.player_ids:
|
for player in self.player_ids:
|
||||||
@@ -1327,6 +1336,8 @@ class Spoiler:
|
|||||||
get_path(state, multiworld.get_region('Inverted Big Bomb Shop', player))
|
get_path(state, multiworld.get_region('Inverted Big Bomb Shop', player))
|
||||||
|
|
||||||
def to_file(self, filename: str) -> None:
|
def to_file(self, filename: str) -> None:
|
||||||
|
from worlds import AutoWorld
|
||||||
|
|
||||||
def write_option(option_key: str, option_obj: Options.AssembleOptions) -> None:
|
def write_option(option_key: str, option_obj: Options.AssembleOptions) -> None:
|
||||||
res = getattr(self.multiworld.worlds[player].options, option_key)
|
res = getattr(self.multiworld.worlds[player].options, option_key)
|
||||||
display_name = getattr(option_obj, "display_name", option_key)
|
display_name = getattr(option_obj, "display_name", option_key)
|
||||||
@@ -1450,8 +1461,3 @@ def get_seed(seed: Optional[int] = None) -> int:
|
|||||||
random.seed(None)
|
random.seed(None)
|
||||||
return random.randint(0, pow(10, seeddigits) - 1)
|
return random.randint(0, pow(10, seeddigits) - 1)
|
||||||
return seed
|
return seed
|
||||||
|
|
||||||
|
|
||||||
from worlds import AutoWorld
|
|
||||||
|
|
||||||
auto_world = AutoWorld.World
|
|
||||||
|
|||||||
Reference in New Issue
Block a user