Skip to content

Commit

Permalink
Make the "No connections found" error message obvious on screen, not …
Browse files Browse the repository at this point in the history
…just in logs
  • Loading branch information
Avasam committed Jul 18, 2024
1 parent f9945d1 commit ae69ff1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Dolphin scripts/Entrance Randomizer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from lib.constants import __version__
from lib.entrance_rando import (
CLOSED_DOOR_EXITS,
NO_CONNECTION_FOUND_ERROR,
SHOWN_DISABLED_TRANSITIONS,
highjack_transition_rando,
set_transitions_map,
Expand Down Expand Up @@ -82,6 +83,8 @@ async def main_loop():
f"From entrance: {hex(previous_area_id).upper()} "
+ (f"({previous_area.name})" if previous_area else ""),
)
if state.no_connection_found_error:
draw_text(NO_CONNECTION_FOUND_ERROR)

# Always re-enable Item Swap
if memory.read_u32(ADDRESSES.item_swap) == 1:
Expand Down
28 changes: 13 additions & 15 deletions Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from lib.transition_infos import Area, Exit, Transition
from lib.utils import follow_pointer_path, state


class NoConnectionFoundError(Exception):
"""Raised when the algorithm fails to find a valid connection to break open."""
NO_CONNECTION_FOUND_ERROR = """
ATTENTION ATTENTION: THE RANDOMIZER ABORTED GENERATION!!!
(failed to find a valid connection to break open)
Please notify a developer!
"""


class Choice(IntEnum):
Expand Down Expand Up @@ -470,18 +472,19 @@ def check_part_of_loop(
return False


def find_and_break_open_connection(link_list: list[tuple[Transition, Transition]]):
direc = random.choice((-1, 1))
def find_and_break_open_connection(link_list: MutableSequence[tuple[Transition, Transition]]):
direction = random.choice((-1, 1))
index = random.randrange(len(link_list))
valid_link = False
crash_counter = 0
while not valid_link:
valid_link = check_part_of_loop(link_list[index], link_list)
if not valid_link:
index = increment_index(index, len(link_list), direc)
index = increment_index(index, len(link_list), direction)
crash_counter += 1
if crash_counter > len(link_list):
raise NoConnectionFoundError
state.no_connection_found_error = True
return
delete_connection(link_list[index][0], link_list[index][1])


Expand Down Expand Up @@ -577,15 +580,10 @@ def set_transitions_map(): # noqa: C901, PLR0912, PLR0914, PLR0915

# Option 3: break open a connection that's part of a loop, then restart iteration
else:
try:
find_and_break_open_connection(link_list)
except NoConnectionFoundError:
# This reason this exception is caught and not raised again
# is because I still want to generate the graph.
# The graph can be really helpful in the process of fixing bugs.
find_and_break_open_connection(link_list)
if state.no_connection_found_error:
print(" ")
print("ATTENTION ATTENTION: THE RANDOMIZER CRASHED!!!")
print("Please notify a developer!")
print(NO_CONNECTION_FOUND_ERROR)
print(" ")
break
continue
Expand Down
2 changes: 2 additions & 0 deletions Dolphin scripts/Entrance Randomizer/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class State:
current_area_new = 0
"""Area ID of the current frame"""
visited_levels: ClassVar[set[int]] = set()
no_connection_found_error = False
"""Whether the algorithm fails to find a valid connection to break open."""


state = State()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the "No connections found" error message obvious on screen, not just in logs -- by @Avasam

0 comments on commit ae69ff1

Please sign in to comment.