Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging koala's Randomizer work for 0.4.0 #40

Merged
merged 70 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3fa0bc8
WIP link to proper entrance, anti door softlock, add back crash site,…
Avasam May 25, 2024
b69b971
Linters updates and fixes
Avasam May 25, 2024
e91603a
typo
Avasam May 25, 2024
d9e5f66
redundant return
Avasam May 25, 2024
c821721
Forgot to update requirements
Avasam May 25, 2024
cd95019
Fix altar of ages not being accessible and two non-existant transitio…
Avasam May 26, 2024
7935db1
Add unrandomized log and indicate that typings is vendored
Avasam May 26, 2024
38e6a66
test commit
May 27, 2024
81af201
moving transition_infos for easy of testing
May 27, 2024
d8fd921
create graphml file
May 29, 2024
3b917cf
bugfixes & small rewrites
May 29, 2024
3084630
typo fix, now it won't crash anymore :)
May 29, 2024
6fba948
simplification by removing troublesome levels from randomization
May 29, 2024
6b8daf7
ST_CLAIRE_DAY now has correct area_id
May 29, 2024
20953b0
Graph now has colors for important levels
May 29, 2024
ebd6c90
reduced graphml clutter a bit
May 29, 2024
d72b893
Algorithm added to guarantee all levels are linked together
May 30, 2024
8386b2e
Added support for the four 1-way transitions (correct entrance doesn'…
May 31, 2024
2d86cdc
Jaguar 1 re-enabled, to make sure we get Jaguar 2 later
May 31, 2024
41b5399
Disabled Mouth of Inti & added all missing levels to transition_infos
May 31, 2024
cf5efe1
Updated list of undesirable starting areas
May 31, 2024
1f26223
Disabled "Twin Outposts (Underwater Cave)" for now
Jun 1, 2024
0dfe92b
now starting_area has no impact on random calls
Jun 1, 2024
bb14a12
Some polishing before Merging for 0.5.0
Jun 1, 2024
f8ce2bd
Merge pull request #1 from wossnameGitHub/rando_generator_testing
wossnameGitHub Jun 2, 2024
4bc9540
Merge branch 'main' into Rando-0.5.0-merge
wossnameGitHub Jun 2, 2024
c99054e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2024
3533d22
cleaned up set_transitions_map a bit by creating some functions + oth…
Jun 2, 2024
4fe7106
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2024
6773454
made functions for create_graphml + more small ruff fixes
Jun 2, 2024
0d545da
Merge local branch 'Rando-0.5.0-merge'
Jun 2, 2024
bcf35e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2024
34d89f0
made parameter types in functions explicit
Jun 2, 2024
2d7cfe4
Merge branch 'Rando-0.5.0-merge' of https://github.com/wossnameGitHub…
Jun 2, 2024
5511d62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2024
2b61bc4
1st wave of changes made per Avasam's request
Jun 6, 2024
308fece
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 6, 2024
0609b2e
some more pyright adjustments
Jun 6, 2024
970e88b
Added all levels to LevelCRC + alphabetical order
Jun 7, 2024
0b35f4c
re-ordered levels in transition_infos.json, no functional changes
Jun 7, 2024
6cd685f
More assorted changes per Avasam's request
Jun 8, 2024
2b4df4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2024
c3dc3cf
single "line too long" fix
Jun 8, 2024
cd7a85a
moved all graph creation logic to it's own module
Jun 8, 2024
05d012f
All 38 missing exits added to json, and disabled in entrance_rando
Jun 8, 2024
197f0d3
Small updates to Readme & Configs descriptions
Jun 8, 2024
43723fe
typo fix: tuple( ) --> tuple[ ]
Jun 8, 2024
4cb9bb4
Apply suggestions from code review
Avasam Jun 8, 2024
ad6e68a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2024
6175a7c
Merge branch 'main' into Rando-0.5.0-merge
Avasam Jun 8, 2024
dd62b06
Update Dolphin scripts/Entrance Randomizer/CONFIGS.py
Avasam Jun 8, 2024
db843bd
Merge branch 'main' into Rando-0.5.0-merge
Avasam Jun 8, 2024
178a84a
Post-merge fixes
Avasam Jun 9, 2024
a3f9e95
Merge branch 'main' into Rando-0.5.0-merge
Avasam Jun 9, 2024
f06f487
Fix major areas creation
Avasam Jun 9, 2024
eb757d1
Update Dolphin scripts/Entrance Randomizer/__main__.py
Avasam Jun 9, 2024
2d4c92b
even more small adjustments per Avasam's request
Jun 9, 2024
aedba85
Spoiler log now lists transitions in alphabetical order
Jun 9, 2024
aa60ba3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 9, 2024
0ec2628
bit of linting and list comprehension
Jun 10, 2024
ee418ea
reworked disabled_exits
Jun 10, 2024
dbcc918
2 small `ruff` fixes
Jun 10, 2024
0067ab4
small update to blue text
Jun 10, 2024
3d9c14f
simplification of area.con_left
Jun 10, 2024
abbd9c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
b6ee7b5
tiny pyright fix
Jun 10, 2024
ede571c
Merge branch 'Rando-0.5.0-merge' of https://github.com/wossnameGitHub…
Jun 10, 2024
da9b454
Reorder transitin_infos based on world_infos
Avasam Jun 10, 2024
81a6740
some final(?) small changes per Avasam's request
Jun 11, 2024
83c50b3
Merge pull request #2 from Avasam/revert-transition_infos-reordering
wossnameGitHub Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Dolphin scripts/Entrance Randomizer/CONFIGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
Set your own seed, can be an `int`, `float`, `str`, `bytes` or `bytearray`.

Use `None` or any Falsy value to generate a random seed.
Use `None` or any False value to generate a random seed.
Avasam marked this conversation as resolved.
Show resolved Hide resolved

default = None
"""
Expand All @@ -15,15 +15,16 @@
"""
The ID of the Area to start in. `None` for random, `0xEE8F6900` for Crash Site.

See `transition_infos.json` for all available IDs
See `transition_infos.json` for all available IDs.

default = None
"""

LINKED_TRANSITIONS: bool = True
"""
Whether the new destination will contain an exit back to the area you came from.
Assuming both areas have as many entrances as they have exits.
If True, going through any given transition and then backing out will always result
in you returning to the area you came from (assuming it's not a one-way transition).
wossnameGitHub marked this conversation as resolved.
Show resolved Hide resolved
If False, no such guarantees are given.

default = True
"""
Expand All @@ -41,8 +42,8 @@
"""
Whether you can buy maps in the Shaman Shop.

When maps are disabled, and using original shop prices,
the 4 lowest prices (0, 1, 2, 2) are also removed form the pool.
When maps are disabled (and using original shop prices)
the 4 lowest prices (0, 1, 2, 2) are also removed from the pool.

default = True
"""
Expand Down
6 changes: 4 additions & 2 deletions Dolphin scripts/Entrance Randomizer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
from lib.entrance_rando import (
highjack_transition,
highjack_transition_rando,
remove_disabled_exits,
set_transitions_map,
starting_area,
transitions_map,
)
from lib.graph_creation import create_graphml
from lib.shaman_shop import patch_shaman_shop, randomize_shaman_shop
from lib.utils import (
create_graphml,
draw_text,
dump_spoiler_logs,
follow_pointer_path,
Expand All @@ -37,6 +38,7 @@
state,
)

remove_disabled_exits()
wossnameGitHub marked this conversation as resolved.
Show resolved Hide resolved
set_transitions_map()
randomize_shaman_shop()

Expand Down Expand Up @@ -89,7 +91,7 @@ async def main_loop():

# Skip both Jaguar fights if noted in CONFIGS
if CONFIGS.SKIP_JAGUAR:
if highjack_transition(0x0, LevelCRC.JAGUAR, starting_area):
if highjack_transition(LevelCRC.MAIN_MENU, LevelCRC.JAGUAR, starting_area):
return
if highjack_transition(LevelCRC.GATES_OF_EL_DORADO, LevelCRC.JAGUAR, LevelCRC.PUSCA):
return
Expand Down
1 change: 1 addition & 0 deletions Dolphin scripts/Entrance Randomizer/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class LevelCRC(IntEnum):
JUNGLE_TRAIL = 0x7A9B3870
KABOOM = 0xE411440A
LADDER_OF_MILES = 0x619E1126
MAIN_MENU = 0x00000000
MAMA_OULLO_TOWER = 0x07ECCC35
MONKEY_SPIRIT = 0x02C7B675
MONKEY_TEMPLE = 0xF3B4DC8E
Expand Down
99 changes: 86 additions & 13 deletions Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import random
from collections.abc import Iterable, Sequence
from collections.abc import Iterable, MutableMapping, Sequence
from enum import IntEnum
from itertools import starmap
from typing import NamedTuple
from typing import NamedTuple, Sized

import CONFIGS
from lib.constants import * # noqa: F403
Expand All @@ -16,6 +17,11 @@
to: int


class Choice(IntEnum):
CONNECT = 1
INBETWEEN = 2


_possible_starting_areas = [
area for area in ALL_TRANSITION_AREAS
# Remove certain starting areas from the list of possibilities
Expand All @@ -29,11 +35,14 @@
LevelCRC.ST_CLAIRE_NIGHT, # gives all items + access to El Dorado
LevelCRC.JAGUAR, # sends to final bosses
LevelCRC.PUSCA, # sends to final bosses
# Temples and spirits are effectively duplicates, so we remove half of them here
LevelCRC.MONKEY_TEMPLE,
LevelCRC.PENGUIN_TEMPLE,
}
]

starting_area = random.choice(_possible_starting_areas)
# Call RNG even if this is unused to not impact randomization of other things for the same seed
starting_area = random.choice(_possible_starting_areas)
wossnameGitHub marked this conversation as resolved.
Show resolved Hide resolved
if CONFIGS.STARTING_AREA is not None:
starting_area = CONFIGS.STARTING_AREA

Expand All @@ -44,6 +53,66 @@
}
```"""

disabled_exits: list[tuple[int, int]] = [
wossnameGitHub marked this conversation as resolved.
Show resolved Hide resolved
# Temporarily disabled levels
(LevelCRC.EYES_OF_DOOM, LevelCRC.SCORPION_TEMPLE),
(LevelCRC.SCORPION_TEMPLE, LevelCRC.EYES_OF_DOOM),
(LevelCRC.ALTAR_OF_HUITACA, LevelCRC.MOUTH_OF_INTI),
(LevelCRC.MOUTH_OF_INTI, LevelCRC.ALTAR_OF_HUITACA),
(LevelCRC.TWIN_OUTPOSTS, LevelCRC.TWIN_OUTPOSTS_UNDERWATER),
(LevelCRC.TWIN_OUTPOSTS_UNDERWATER, LevelCRC.TWIN_OUTPOSTS),
# The 4 one-way exits
(LevelCRC.WHITE_VALLEY, LevelCRC.MOUNTAIN_SLED_RUN),
(LevelCRC.MOUNTAIN_SLED_RUN, LevelCRC.APU_ILLAPU_SHRINE),
(LevelCRC.APU_ILLAPU_SHRINE, LevelCRC.WHITE_VALLEY),
(LevelCRC.CAVERN_LAKE, LevelCRC.JUNGLE_CANYON),
# The 3 Spirit Fights
(LevelCRC.MONKEY_TEMPLE, LevelCRC.MONKEY_SPIRIT),
(LevelCRC.MONKEY_SPIRIT, LevelCRC.MONKEY_TEMPLE),
(LevelCRC.SCORPION_TEMPLE, LevelCRC.SCORPION_SPIRIT),
(LevelCRC.SCORPION_SPIRIT, LevelCRC.SCORPION_TEMPLE),
(LevelCRC.PENGUIN_TEMPLE, LevelCRC.PENGUIN_SPIRIT),
(LevelCRC.PENGUIN_SPIRIT, LevelCRC.PENGUIN_TEMPLE),
# The 5 Native Games
(LevelCRC.NATIVE_VILLAGE, LevelCRC.WHACK_A_TUCO),
(LevelCRC.WHACK_A_TUCO, LevelCRC.NATIVE_VILLAGE),
(LevelCRC.NATIVE_VILLAGE, LevelCRC.TUCO_SHOOT),
(LevelCRC.TUCO_SHOOT, LevelCRC.NATIVE_VILLAGE),
(LevelCRC.NATIVE_VILLAGE, LevelCRC.RAFT_BOWLING),
(LevelCRC.RAFT_BOWLING, LevelCRC.NATIVE_VILLAGE),
(LevelCRC.NATIVE_VILLAGE, LevelCRC.PICKAXE_RACE),
(LevelCRC.PICKAXE_RACE, LevelCRC.NATIVE_VILLAGE),
(LevelCRC.NATIVE_VILLAGE, LevelCRC.KABOOM),
(LevelCRC.KABOOM, LevelCRC.NATIVE_VILLAGE),
# The 2 CUTSCENE Levels
(LevelCRC.JAGUAR, LevelCRC.PLANE_CUTSCENE),
(LevelCRC.PLANE_CUTSCENE, LevelCRC.CRASH_SITE),
(LevelCRC.SPINJA_LAIR, LevelCRC.VIRACOCHA_MONOLITHS_CUTSCENE),
(LevelCRC.VIRACOCHA_MONOLITHS_CUTSCENE, LevelCRC.VIRACOCHA_MONOLITHS),
# Specific one-time, one-way warps
(LevelCRC.ALTAR_OF_AGES, LevelCRC.BITTENBINDERS_CAMP),
(LevelCRC.ST_CLAIRE_DAY, LevelCRC.ST_CLAIRE_NIGHT),
(LevelCRC.ST_CLAIRE_NIGHT, LevelCRC.ST_CLAIRE_DAY),
(LevelCRC.GATES_OF_EL_DORADO, LevelCRC.JAGUAR),
(LevelCRC.JAGUAR, LevelCRC.PUSCA),
(LevelCRC.PUSCA, LevelCRC.GATES_OF_EL_DORADO),
# The Unused Beta Volcano Level
(LevelCRC.BETA_VOLCANO, LevelCRC.JUNGLE_CANYON),
(LevelCRC.BETA_VOLCANO, LevelCRC.PLANE_COCKPIT),
]


def remove_disabled_exits():
for disabled in disabled_exits:
for area in TRANSITION_INFOS_DICT.values():
if area.area_id == disabled[0]:
for ex in area.exits:
if ex.area_id == disabled[1]:
area.exits.remove(ex)
ALL_POSSIBLE_TRANSITIONS.remove(disabled)
break
break


def highjack_transition(
from_: int | None,
Expand Down Expand Up @@ -133,9 +202,9 @@


def check_part_of_loop(
link: list[Area],
link_list: list[list[Area]],
area_list: list[Area],
link: tuple[Area, Area],
link_list: list[tuple[Area, Area]],
area_list: Sized,
):
unchecked_links = link_list.copy()
unchecked_links.remove(link)
Expand Down Expand Up @@ -185,10 +254,10 @@


def link_list_to_transitions(
link_list: list[list[Area]],
transitions_map: dict[tuple[int, int], Transition],
origins_bucket: Iterable[Transition],
redirections_bucket: Iterable[Transition],
link_list: list[tuple[Area, Area]],
transitions_map: MutableMapping[Transition, Transition],
Avasam marked this conversation as resolved.
Show resolved Hide resolved
origins_bucket: list[Transition],
redirections_bucket: list[Transition],
):
for link in link_list:
options_original = [
Expand Down Expand Up @@ -258,11 +327,15 @@

index = 2
while index < len(level_list):
r = random.choice(["1", "2"])
if total_con_left > 0 and (level_list[index].con_left == 1 or r == "1"):
choice = random.choice([Choice.CONNECT, Choice.INBETWEEN])
wossnameGitHub marked this conversation as resolved.
Show resolved Hide resolved
if total_con_left > 0 and (
level_list[index].con_left == 1 or choice == Choice.CONNECT
):
# option 1: connect to one or more existing levels
connect_to_existing(level_list, index, link_list)
elif level_list[index].con_left > 1 and (total_con_left == 0 or r == "2"):
elif level_list[index].con_left > 1 and (
total_con_left == 0 or choice == Choice.INBETWEEN
):
# option 2: put the current level inbetween an already established connection
total_con_left += level_list[index].con_left
level_a, level_b = link_list.pop(random.randrange(len(link_list)))
Expand All @@ -281,7 +354,7 @@

link_list_to_transitions(
link_list,
transitions_map,

Check failure on line 357 in Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "dict[tuple[int, int], Transition]" cannot be assigned to parameter "transitions_map" of type "MutableMapping[Transition, Transition]" in function "link_list_to_transitions"   "dict[tuple[int, int], Transition]" is incompatible with "MutableMapping[Transition, Transition]"     Type parameter "_KT@MutableMapping" is invariant, but "tuple[int, int]" is not the same as "Transition" (reportArgumentType)
_possible_origins_bucket,
_possible_redirections_bucket,
)
Expand All @@ -301,9 +374,9 @@
for to_og in (exit_.area_id for exit_ in area.exits):
original = Transition(from_=area.area_id, to=to_og)
redirect = get_random_redirection(original, _possible_redirections_bucket)
transitions_map[original] = redirect

Check failure on line 377 in Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "Transition | None" cannot be assigned to parameter "value" of type "Transition" in function "__setitem__"   Type "Transition | None" is incompatible with type "Transition"     "None" is incompatible with "Transition" (reportArgumentType)
_possible_redirections_bucket.remove(redirect)

Check failure on line 378 in Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "Transition | None" cannot be assigned to parameter "value" of type "Transition" in function "remove"   Type "Transition | None" is incompatible with type "Transition"     "None" is incompatible with "Transition" (reportArgumentType)
for original in one_way_list:
redirect = get_random_redirection(original, _possible_redirections_bucket)
transitions_map[original] = redirect

Check failure on line 381 in Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "Transition | None" cannot be assigned to parameter "value" of type "Transition" in function "__setitem__"   Type "Transition | None" is incompatible with type "Transition"     "None" is incompatible with "Transition" (reportArgumentType)
_possible_redirections_bucket.remove(redirect)

Check failure on line 382 in Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "Transition | None" cannot be assigned to parameter "value" of type "Transition" in function "remove"   Type "Transition | None" is incompatible with type "Transition"     "None" is incompatible with "Transition" (reportArgumentType)
127 changes: 127 additions & 0 deletions Dolphin scripts/Entrance Randomizer/lib/graph_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from __future__ import annotations

from collections.abc import Mapping
from pathlib import Path

from lib.constants import * # noqa: F403
from lib.constants import __version__
from lib.transition_infos import Area
from lib.types_ import SeedType


Avasam marked this conversation as resolved.
Show resolved Hide resolved
def create_vertices(
transitions_map: Mapping[tuple[int, int], tuple[int, int]],
starting_area: int,
):
output_text = ""
areas_randomized: list[Area] = []
for original, redirect in transitions_map.items():
if TRANSITION_INFOS_DICT[original[0]] not in areas_randomized:
areas_randomized.append(TRANSITION_INFOS_DICT[original[0]])
if TRANSITION_INFOS_DICT[redirect[1]] not in areas_randomized:
areas_randomized.append(TRANSITION_INFOS_DICT[redirect[1]])
Avasam marked this conversation as resolved.
Show resolved Hide resolved
counter_x = 0
counter_y = 0
for area in areas_randomized:
output_text += (
f'<node positionX="{counter_x * 100 + counter_y * 20}" '
+ f'positionY="{counter_x * 50 + counter_y * 50}" '
+ f'id="{area.small_id}" mainText="{area.name}" '
)
# Starting area: Orange
if area.area_id == starting_area:
output_text += (
'ownStyles = "{&quot;0&quot;:{&quot;fillStyle&quot;:&quot;#ff8000&quot;}}" '
)
# Areas with Upgrades: Blue
elif area.area_id in {
LevelCRC.PLANE_COCKPIT,
LevelCRC.BITTENBINDERS_CAMP,
LevelCRC.MOUTH_OF_INTI,
LevelCRC.FLOODED_COURTYARD,
LevelCRC.TURTLE_MONUMENT,
LevelCRC.NATIVE_VILLAGE,
LevelCRC.RENEGADE_HEADQUARTERS,
LevelCRC.CAVERN_LAKE,
LevelCRC.MOUNTAIN_SLED_RUN,
LevelCRC.MOUNTAIN_OVERLOOK,
LevelCRC.APU_ILLAPU_SHRINE,
}:
output_text += (
'ownStyles = "{&quot;0&quot;:{&quot;fillStyle&quot;:&quot;#0080ff&quot;}}" '
)
# Important Story Triggers: Red
elif area.area_id in {
LevelCRC.ALTAR_OF_AGES,
LevelCRC.ST_CLAIRE_DAY,
LevelCRC.ST_CLAIRE_NIGHT,
LevelCRC.GATES_OF_EL_DORADO,
}:
output_text += (
'ownStyles = "{&quot;0&quot;:{&quot;fillStyle&quot;:&quot;#ff0000&quot;}}" '
Avasam marked this conversation as resolved.
Show resolved Hide resolved
)
output_text += "></node>\n"
row_length = 10
counter_x += 1
if counter_x == row_length:
counter_x = 0
counter_y += 1
return output_text


def create_edges(transitions_map: Mapping[tuple[int, int], tuple[int, int]]):
output_text = ""
connections: list[tuple[tuple[int, int], tuple[int, int]]] = []
connections_two_way: list[tuple[tuple[int, int], tuple[int, int]]] = []
connections_one_way: list[tuple[tuple[int, int], tuple[int, int]]] = []
for original, redirect in transitions_map.items():
connections.append([original[0], redirect[1]])

Check failure on line 78 in Dolphin scripts/Entrance Randomizer/lib/graph_creation.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "list[int]" cannot be assigned to parameter "object" of type "tuple[tuple[int, int], tuple[int, int]]" in function "append"   "list[int]" is incompatible with "tuple[tuple[int, int], tuple[int, int]]" (reportArgumentType)
for pairing in connections:
if [pairing[1], pairing[0]] not in connections_two_way:

Check failure on line 80 in Dolphin scripts/Entrance Randomizer/lib/graph_creation.py

View workflow job for this annotation

GitHub Actions / Run pyright

Expression will always evaluate to True since the types "list[tuple[int, int]]" and "tuple[tuple[int, int], tuple[int, int]]" have no overlap (reportUnnecessaryContains)
if [pairing[1], pairing[0]] in connections:

Check failure on line 81 in Dolphin scripts/Entrance Randomizer/lib/graph_creation.py

View workflow job for this annotation

GitHub Actions / Run pyright

Expression will always evaluate to False since the types "list[tuple[int, int]]" and "tuple[tuple[int, int], tuple[int, int]]" have no overlap (reportUnnecessaryContains)
Avasam marked this conversation as resolved.
Show resolved Hide resolved
connections_two_way.append(pairing)
else:
connections_one_way.append(pairing)
counter = 10000
for pairing in connections_two_way:
output_text += (
f'<edge source="{TRANSITION_INFOS_DICT[pairing[0]].small_id}" '

Check failure on line 88 in Dolphin scripts/Entrance Randomizer/lib/graph_creation.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "tuple[int, int]" cannot be assigned to parameter "key" of type "int" in function "__getitem__"   "tuple[int, int]" is incompatible with "int" (reportArgumentType)
+ f'target="{TRANSITION_INFOS_DICT[pairing[1]].small_id}" isDirect="false" '

Check failure on line 89 in Dolphin scripts/Entrance Randomizer/lib/graph_creation.py

View workflow job for this annotation

GitHub Actions / Run pyright

Argument of type "tuple[int, int]" cannot be assigned to parameter "key" of type "int" in function "__getitem__"   "tuple[int, int]" is incompatible with "int" (reportArgumentType)
+ f'id="{counter}" ></edge>\n'
)
counter += 1
for pairing in connections_one_way:
output_text += (
f'<edge source="{TRANSITION_INFOS_DICT[pairing[0]].small_id}" '
+ f'target="{TRANSITION_INFOS_DICT[pairing[1]].small_id}" isDirect="true" '
+ f'id="{counter}" ></edge>\n'
)
counter += 1
return output_text


def create_graphml(
transitions_map: Mapping[tuple[int, int], tuple[int, int]],
seed_string: SeedType,
starting_area: int,
):

Avasam marked this conversation as resolved.
Show resolved Hide resolved
graphml_text = (
'<?xml version="1.0" encoding="UTF-8"?>'
+ '<graphml><graph id="Graph" uidGraph="1" uidEdge="1">\n'
+ create_vertices(transitions_map, starting_area)
+ create_edges(transitions_map)
+ "</graph></graphml>"
)
Avasam marked this conversation as resolved.
Show resolved Hide resolved

# TODO (Avasam): Get actual user folder based whether Dolphin Emulator is in AppData/Roaming
# and if the current installation is portable.
dolphin_path = Path().absolute()
graphml_file = (
dolphin_path
/ "User"
/ "Logs"
/ f"RANDOMIZED_MAP_v{__version__}_{seed_string}.graphml"
)
Path.write_text(graphml_file, graphml_text)
print("Graphml file written to", graphml_file)
Loading