Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions src/mars_patcher/mf/constants/minimap_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,6 @@
0x0C1,
0x0D2,
0x0D3,
0x0D8,
0x0D9,
0x0DA,
0x0DB,
0x0DC,
0x0DD,
0x0DE,
0x0E9,
0x0EE,
0x0F3,
Expand Down
29 changes: 16 additions & 13 deletions src/mars_patcher/mf/door_locks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from collections import defaultdict
from enum import Enum
from typing import Annotated, TypedDict
from typing import Annotated, Literal, TypedDict

from mars_patcher.common_types import AreaId, AreaRoomPair, RoomId
from mars_patcher.common_types import AreaId, AreaRoomPair
from mars_patcher.constants.door_types import DoorType
from mars_patcher.constants.game_data import area_doors_ptrs, minimap_graphics
from mars_patcher.constants.minimap_tiles import ColoredDoor, Content, Edge
Expand Down Expand Up @@ -86,8 +86,8 @@ class HatchLock(Enum):

HatchSlot = Annotated[int, "0 <= value <= 5"]

MinimapLocation = tuple[int, int, RoomId]
"""`(X, Y, RoomId)`"""
MinimapLocation = tuple[int, int]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes me wonder if this should be a namedtuple
but its probably not used often enough? and afaik we're basically always unpacking the tuple anyway.

"""`(X, Y)`"""


class MinimapLockChanges(TypedDict, total=False):
Expand Down Expand Up @@ -117,7 +117,7 @@ def set_door_locks(rom: Rom, data: list[MarsschemamfDoorlocksItem]) -> None:
def factory() -> dict:
return defaultdict(dict)

# AreaID: {(MinimapX, MinimapY, RoomID): {"left" | "right": HatchLock}}
# AreaID: {(MinimapX, MinimapY): {"left" | "right": HatchLock}}
minimap_changes: dict[AreaId, dict[MinimapLocation, MinimapLockChanges]] = defaultdict(factory)

for area in range(7):
Expand Down Expand Up @@ -226,11 +226,15 @@ def factory() -> dict:
if area == 0:
minimap_areas = [0, 9] # Main Deck has two maps
for minimap_area in minimap_areas:
map_tile = minimap_changes[minimap_area][minimap_x, minimap_y, room]
if facing_right:
map_tile["left"] = lock
else:
map_tile["right"] = lock
map_tile = minimap_changes[minimap_area][minimap_x, minimap_y]
side: Literal["left", "right"] = "left" if facing_right else "right"
if side in map_tile and map_tile[side] != lock:
raise ValueError(
f"Minimap tile in area {area} at 0x{minimap_x:X}, 0x{minimap_y} "
f"has already changed {side} hatch to {map_tile[side].name} but is "
f"being set to {lock.name}"
)
map_tile[side] = lock

# Overwrite BG1 and clipdata
if lock is None:
Expand Down Expand Up @@ -314,7 +318,7 @@ def change_minimap_tiles(

for area, area_map in minimap_changes.items():
with Minimap(rom, area) as minimap:
for (x, y, room), tile_changes in area_map.items():
for (x, y), tile_changes in area_map.items():
tile_id, palette, h_flip, v_flip = minimap.get_tile_value(x, y)

try:
Expand Down Expand Up @@ -370,8 +374,7 @@ def tile_exists() -> bool:

if not tile_exists():
logging.debug(
"Could not reuse existing map tile for "
f"area {area} room {room:X}. ({x:X}, {y:X})."
f"Could not reuse existing map tile for area {area} at {x:X}, {y:X}."
)
logging.debug(f" Desired tile: {orig_new_tile_data.as_str}")

Expand Down