diff --git a/Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py b/Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py index 3a2c70e..10a6f17 100644 --- a/Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py +++ b/Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py @@ -3,7 +3,7 @@ import random from collections.abc import MutableSequence, Sequence from copy import copy -from enum import IntEnum +from enum import IntEnum, auto from itertools import starmap from typing import NamedTuple @@ -13,24 +13,29 @@ from lib.utils import follow_pointer_path, state +class NoConnectionFoundError(Exception): + "Raised when the algorithm fails to find a valid connection to break open" + pass + + class Transition(NamedTuple): from_: int to: int class Choice(IntEnum): - CONNECT = 1 - INBETWEEN = 2 + CONNECT = auto() + INBETWEEN = auto() class BucketType(IntEnum): - ORIGIN = 1 - REDIRECT = 2 + ORIGIN = auto() + REDIRECT = auto() class Priority(IntEnum): - CLOSED = 1 - OPEN = 2 + CLOSED = auto() + OPEN = auto() one_way_exits = ( @@ -485,7 +490,7 @@ def find_and_break_open_connection(link_list: list[tuple[Transition, Transition] index = increment_index(index, len(link_list), direc) crash_counter += 1 if crash_counter > len(link_list): - raise Exception("NO CONNECTION FOUND") + raise NoConnectionFoundError() delete_connection(link_list[index][0], link_list[index][1]) @@ -582,14 +587,12 @@ def set_transitions_map(): # noqa: PLR0915 # TODO: Break up in smaller function else: try: find_and_break_open_connection(link_list) - except Exception as e: - if str(e) == "NO CONNECTION FOUND": - print() - print("ATTENTION ATTENTION: THE RANDOMIZER CRASHED!!!") - print("Please notify a developer!") - print() - break - raise + except NoConnectionFoundError: + print(" ") + print("ATTENTION ATTENTION: THE RANDOMIZER CRASHED!!!") + print("Please notify a developer!") + print(" ") + break continue index += 1 diff --git a/Dolphin scripts/Entrance Randomizer/lib/graph_creation.py b/Dolphin scripts/Entrance Randomizer/lib/graph_creation.py index 3f0e315..440fc1e 100644 --- a/Dolphin scripts/Entrance Randomizer/lib/graph_creation.py +++ b/Dolphin scripts/Entrance Randomizer/lib/graph_creation.py @@ -2,7 +2,7 @@ from collections.abc import Mapping, MutableMapping, Sequence from copy import copy -from enum import IntEnum +from enum import IntEnum, auto from pathlib import Path from lib.constants import * # noqa: F403 @@ -12,13 +12,13 @@ class Direction(IntEnum): - ONEWAY = 1 - TWOWAY = 2 + ONEWAY = auto() + TWOWAY = auto() class LineType(IntEnum): - SOLID = 1 - DASHED = 2 + SOLID = auto() + DASHED = auto() STARTING_AREA_COLOR = "#ff8000" # Orange @@ -44,6 +44,9 @@ class LineType(IntEnum): LevelCRC.GATES_OF_EL_DORADO, } +UNRANDOMIZED_EDGE_COLOR = "#000000" # Black +CLOSED_DOOR_EDGE_COLOR = "#ff0000" # Red + def create_vertices( transitions_map: Mapping[tuple[int, int], tuple[int, int]], @@ -76,7 +79,8 @@ def create_vertices( output_text += ( f'