Skip to content

Commit

Permalink
Move ERType to Entrance.Type, fix typing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
BadMagic100 committed Nov 20, 2023
1 parent ab4856c commit 7be8ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 8 additions & 3 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions EntranceRando.py
Original file line number Diff line number Diff line change
@@ -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]]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7be8ce5

Please sign in to comment.