Skip to content

Commit

Permalink
first wave of changes per Avasam's request
Browse files Browse the repository at this point in the history
  • Loading branch information
wossnameGitHub committed Jul 14, 2024
1 parent 7fe7812 commit da60fc1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
35 changes: 19 additions & 16 deletions Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = (
Expand Down Expand Up @@ -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])


Expand Down Expand Up @@ -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
Expand Down
43 changes: 23 additions & 20 deletions Dolphin scripts/Entrance Randomizer/lib/graph_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]],
Expand Down Expand Up @@ -76,7 +79,8 @@ def create_vertices(
output_text += (
f'<node positionX="{counter_x * 100 + counter_y * 20}" '
+ f'positionY="{counter_x * 50 + counter_y * 50}" '
+ f'id="{int(area_id)}" mainText="{area_name}"'
+ f'id="{int(area_id)}" '
+ f'mainText="{area_name}"'
)
if area_id == starting_area:
output_text += (
Expand Down Expand Up @@ -105,20 +109,19 @@ def create_vertices(
return output_text


def edge_text(
def edge_component(
start: int,
end: int,
counter: int,
direct: Direction,
color: str | None,
line_type: LineType,
):
direct_str = "true"
if direct == Direction.TWOWAY:
direct_str = "false"
direct_str = str(direct == Direction.ONEWAY).lower()
output = (
f'<edge source="{transition_infos_dict_rando[start].area_id}" '
+ f'target="{transition_infos_dict_rando[end].area_id}" isDirect="{direct_str}" '
+ f'target="{transition_infos_dict_rando[end].area_id}" '
+ f'isDirect="{direct_str}" '
+ f'id="{counter}"'
)
if line_type == LineType.DASHED or color is not None:
Expand All @@ -136,8 +139,8 @@ def edge_text(

def create_edges(
transitions_map: Mapping[tuple[int, int], tuple[int, int]],
temp_disabled_exits: list[tuple[int, int]],
closed_door_exits: list[tuple[int, int]],
temp_disabled_exits: Iterable[tuple[int, int]],
closed_door_exits: Container[tuple[int, int]],
):
connections = list(transitions_map.items())
connections_two_way: list[tuple[tuple[int, int], tuple[int, int]]] = []
Expand All @@ -163,26 +166,26 @@ def create_edges(
counter = 1 # Can't start at 0 since that's the MAIN_MENU id
for pairing in connections_two_way:
if pairing[1] in temp_disabled_exits:
output_text += edge_text(
output_text += edge_component(
pairing[0][0], pairing[1][1],
counter, Direction.TWOWAY, "#000000", LineType.SOLID,
counter, Direction.TWOWAY, UNRANDOMIZED_EDGE_COLOR, LineType.SOLID,
)
else:
output_text += edge_text(
output_text += edge_component(
pairing[0][0], pairing[1][1],
counter, Direction.TWOWAY, None, LineType.SOLID,
)
counter += 1
for pairing in connections_one_way:
output_text += edge_text(
output_text += edge_component(
pairing[0][0], pairing[1][1],
counter, Direction.ONEWAY, None, LineType.DASHED,
)
counter += 1
for pairing in connections_closed_door:
output_text += edge_text(
output_text += edge_component(
pairing[1][1], pairing[0][0],
counter, Direction.ONEWAY, "#ff0000", LineType.SOLID,
counter, Direction.ONEWAY, CLOSED_DOOR_EDGE_COLOR, LineType.SOLID,
)
counter += 1
return output_text
Expand All @@ -191,7 +194,7 @@ def create_edges(
def create_graphml(
transitions_map: MutableMapping[tuple[int, int], tuple[int, int]],
temp_disabled_exits: Sequence[tuple[int, int]],
closed_door_exits: list[tuple[int, int]],
closed_door_exits: Container[tuple[int, int]],
seed_string: SeedType,
starting_area: int,
):
Expand Down

0 comments on commit da60fc1

Please sign in to comment.