Skip to content

Commit

Permalink
Make more types frozen and immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jun 8, 2024
1 parent 91ab2af commit 3383a65
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
64 changes: 32 additions & 32 deletions Dolphin scripts/Entrance Randomizer/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@
print("Seed set to:", seed_string)


@dataclass
@dataclass(frozen=True)
class Addresses:
version_string: str
prev_area: list[int]
prev_area: tuple[int, ...]
current_area: int
area_load_state: int
player_x: list[int]
player_y: list[int]
player_z: list[int]
player_x: tuple[int, ...]
player_y: tuple[int, ...]
player_z: tuple[int, ...]
item_swap: int
shaman_shop_struct: int


TRANSITION_INFOS_DICT = {
area.area_id: area for area in chain(*transition_infos)
}
ALL_TRANSITION_AREAS = {area.area_id for area in chain(*transition_infos)}
ALL_POSSIBLE_TRANSITIONS = [
ALL_TRANSITION_AREAS = frozenset(area.area_id for area in chain(*transition_infos))
ALL_POSSIBLE_TRANSITIONS = tuple(
(area.area_id, exit_.area_id)
for area in TRANSITION_INFOS_DICT.values()
for exit_ in area.exits
]
)


_game_id_base = "".join([
Expand All @@ -75,69 +75,69 @@ class Addresses:
"GPH": {
"D": Addresses(
version_string="GC DE 0-00",
prev_area=[0x80747648],
prev_area=(0x80747648,),
current_area=0x80417F50,
area_load_state=TODO,
player_x=[],
player_y=[],
player_z=[],
player_x=(),
player_y=(),
player_z=(),
item_swap=0x804C7734,
shaman_shop_struct=TODO,
),
"E": Addresses(
version_string="GC US 0-00",
prev_area=[0x8072B648],
prev_area=(0x8072B648,),
current_area=0x8041BEB4,
area_load_state=0x8041BEC8,
player_x=[0x8041BE4C, 0x338],
player_y=[0x8041BE4C, 0x33C],
player_z=[0x8041BE4C, 0x340],
player_x=(0x8041BE4C, 0x338),
player_y=(0x8041BE4C, 0x33C),
player_z=(0x8041BE4C, 0x340),
item_swap=0x804CB694,
shaman_shop_struct=0x7E00955C,
),
"F": Addresses(
version_string="GC FR 0-00",
prev_area=[0x80747648],
prev_area=(0x80747648,),
current_area=0x80417F30,
area_load_state=TODO,
player_x=[],
player_y=[],
player_z=[],
player_x=(),
player_y=(),
player_z=(),
item_swap=0x804C7714,
shaman_shop_struct=TODO,
),
"P": Addresses(
version_string="GC EU 0-00",
prev_area=[0x80747648],
prev_area=(0x80747648,),
current_area=0x80417F10,
area_load_state=TODO,
player_x=[],
player_y=[],
player_z=[],
player_x=(),
player_y=(),
player_z=(),
item_swap=0x804C76F4,
shaman_shop_struct=TODO,
),
},
"RPF": {
"E": Addresses(
version_string="Wii US 0-00",
prev_area=[0x804542DC, 0x8],
prev_area=(0x804542DC, 0x8),
current_area=0x80448D04,
area_load_state=TODO,
player_x=[],
player_y=[],
player_z=[],
player_x=(),
player_y=(),
player_z=(),
item_swap=0x80446608,
shaman_shop_struct=TODO,
),
"P": Addresses(
version_string="Wii EU 0-00",
prev_area=[0x804546DC, 0x18],
prev_area=(0x804546DC, 0x18),
current_area=0x80449104,
area_load_state=TODO,
player_x=[],
player_y=[],
player_z=[],
player_x=(),
player_y=(),
player_z=(),
item_swap=0x80446A08,
shaman_shop_struct=TODO,
),
Expand Down
26 changes: 13 additions & 13 deletions Dolphin scripts/Entrance Randomizer/lib/transition_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,48 @@ class AreaJSON(TypedDict):
TransitionInfosJSON = None


@dataclass
@dataclass(frozen=True)
class Exit:
area_id: int
area_name: str
requires: None | list[list[str]]


@dataclass
@dataclass(frozen=True)
class Area:
area_id: int
name: str
default_entrance: int
exits: list[Exit]
exits: tuple[Exit, ...]


class MajorAreas(NamedTuple):
jungle: list[Area]
native_territory: list[Area]
lost_caverns: list[Area]
snowy_mountains: list[Area]
jungle: tuple[Area, ...]
native_territory: tuple[Area, ...]
lost_caverns: tuple[Area, ...]
snowy_mountains: tuple[Area, ...]


def major_areas_from_JSON(transition_infos_json: TransitionInfosJSON): # noqa: N802
major_areas = [
[
major_areas = (
tuple(
Area(
int(area["area_id"], 16),
area["area_name"],
int(area["default_entrance"] or "0x0", 16),
[
tuple(
Exit(
int(exit_["area_id"] or "0x0", 16),
exit_["area_name"],
exit_["requires"],
)
for exit_ in area["exits"]
],
),
)
for area in major_area
]
)
for major_area in transition_infos_json.values()
]
)
return MajorAreas(*major_areas)


Expand Down

0 comments on commit 3383a65

Please sign in to comment.