diff --git a/BaseClasses.py b/BaseClasses.py index 682876c351b3..71d728fd8c7b 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -17,7 +17,9 @@ import NetUtils import Options import Utils -from EntranceRando import ERType, ERPlacementState + +if typing.TYPE_CHECKING: + from EntranceRando import ERPlacementState class Group(TypedDict, total=False): @@ -767,6 +769,9 @@ def remove(self, item: Item): class Entrance: + class Type(IntEnum): + ONE_WAY = 1 + TWO_WAY = 2 access_rule: Callable[[CollectionState], bool] = staticmethod(lambda state: True) hide_path: bool = False @@ -775,13 +780,13 @@ class Entrance: parent_region: Optional[Region] connected_region: Optional[Region] = None er_group: str - er_type: ERType + er_type: Type # LttP specific, TODO: should make a LttPEntrance addresses = None target = None def __init__(self, player: int, name: str = '', parent: Region = None, - er_group: str = 'Default', er_type: ERType = ERType.ONE_WAY): + er_group: str = 'Default', er_type: Type = Type.ONE_WAY): self.name = name self.parent_region = parent self.player = player diff --git a/EntranceRando.py b/EntranceRando.py index 2d0d4cc63ce8..a3386f9b63b8 100644 --- a/EntranceRando.py +++ b/EntranceRando.py @@ -1,19 +1,12 @@ import functools import queue import random -from dataclasses import dataclass -from enum import IntEnum from typing import Set, Tuple, List, Dict, Iterable, Callable, Union from BaseClasses import Region, Entrance, CollectionState from worlds.AutoWorld import World -class ERType(IntEnum): - ONE_WAY = 1 - TWO_WAY = 2 - - class EntranceLookup: class GroupLookup: _lookup: Dict[str, List[Entrance]] @@ -44,6 +37,7 @@ def __init__(self, rng: random.Random): self.dead_ends = EntranceLookup.GroupLookup() self.others = EntranceLookup.GroupLookup() + # todo - investigate whether this might leak memory (holds references to Entrances)? @staticmethod @functools.cache def _is_dead_end(entrance: Entrance): @@ -192,7 +186,7 @@ def connect(self, source_exit: Entrance, target_entrance: Entrance) -> Iterable[ self._connect_one_way(source_exit, target_entrance) # if we're doing coupled randomization place the reverse transition as well. - if self.coupled and source_exit.er_type == ERType.TWO_WAY: + if self.coupled and source_exit.er_type == Entrance.Type.TWO_WAY: # todo - better exceptions here for reverse_entrance in source_region.entrances: if reverse_entrance.name == source_exit.name: