13 return static_cast<int>((offset % 0x80) / 2);
17 return static_cast<int>(offset / 0x80);
21 0x021C, 0x023C, 0x025C, 0x039C, 0x03BC, 0x03DC,
22 0x121C, 0x123C, 0x125C, 0x139C, 0x13BC, 0x13DC};
25 0x0D1C, 0x0D3C, 0x0D5C, 0x0B9C, 0x0BBC, 0x0BDC,
26 0x1D1C, 0x1D3C, 0x1D5C, 0x1B9C, 0x1BBC, 0x1BDC};
29 0x0784, 0x0F84, 0x1784, 0x078A, 0x0F8A, 0x178A,
30 0x07C4, 0x0FC4, 0x17C4, 0x07CA, 0x0FCA, 0x17CA};
33 0x07B4, 0x0FB4, 0x17B4, 0x07AE, 0x0FAE, 0x17AE,
34 0x07F4, 0x0FF4, 0x17F4, 0x07EE, 0x0FEE, 0x17EE};
103 bool is_inner =
false;
126 if (valid_positions.empty()) {
132 int min_dist = std::abs(coord - valid_positions[0]);
133 for (
size_t i = 1; i < valid_positions.size(); ++i) {
134 int dist = std::abs(coord - valid_positions[i]);
135 if (dist < min_dist) {
137 nearest_idx =
static_cast<int>(i);
144 return static_cast<uint8_t
>(start_pos + nearest_idx);
149 int pos_idx = position & 0x0F;
154 const uint16_t offset = DoorTilemapOffsets(direction)[pos_idx];
155 return {TilemapOffsetToTileX(offset), TilemapOffsetToTileY(offset)};
170 return {tile_x, tile_y};
203 if (position >= DoorTilemapOffsets(direction).size()) {
210 return tile_x >= 0 && tile_y >= 0 &&
225 if (tile_y < threshold) {
237 if (tile_x < threshold) {
253 bool& out_is_inner) {
259 constexpr int kMiddleSeam = 32;
260 constexpr int kSeamThreshold = 6;
265 if (tile_y < threshold) {
267 out_is_inner =
false;
274 out_is_inner =
false;
279 if (tile_x < threshold) {
281 out_is_inner =
false;
288 out_is_inner =
false;
294 if (std::abs(tile_y - kMiddleSeam) < kSeamThreshold) {
296 if (tile_y < kMiddleSeam) {
306 if (std::abs(tile_x - kMiddleSeam) < kSeamThreshold) {
308 if (tile_x < kMiddleSeam) {
330 return is_inner ? 6 : 0;
335 return is_inner ? 0 : 6;
346 ((position & 0x0F) << 4) | (
static_cast<uint8_t
>(direction) & 0x03);
349 uint8_t byte2 =
static_cast<uint8_t
>(type);
351 return {byte1, byte2};
359 return {pixel_x, pixel_y, dims.width_pixels(), dims.height_pixels()};
366 tile_x += footprint.offset_x_tiles;
367 tile_y += footprint.offset_y_tiles;
static uint8_t GetSectionStartPosition(DoorDirection direction, bool is_inner)
Get the starting position index for outer/inner section.
static constexpr int kRoomHeightTiles
static std::pair< uint8_t, uint8_t > EncodeDoorBytes(uint8_t position, DoorType type, DoorDirection direction)
Encode door data for ROM storage.
static std::pair< int, int > PositionToPixelCoords(uint8_t position, DoorDirection direction)
Convert encoded position to pixel coordinates.
static std::tuple< int, int, int, int > GetDoorEditorBounds(uint8_t position, DoorDirection direction, DoorType type)
Get the editor interaction bounds for a typed door.
static std::tuple< int, int, int, int > GetDoorBounds(uint8_t position, DoorDirection direction)
Get the bounding rectangle for a door.
static bool DetectWallFromPosition(int canvas_x, int canvas_y, DoorDirection &out_direction)
Detect which wall the cursor is near.
static bool IsValidPosition(uint8_t position, DoorDirection direction)
Check if a position is valid for door placement.
static constexpr int kWallDetectionThreshold
static std::pair< int, int > PositionToRenderTileCoords(uint8_t position, DoorDirection direction)
Convert encoded position to the top-left tile of the visible door.
static std::pair< int, int > PositionToTileCoords(uint8_t position, DoorDirection direction)
Convert encoded position to tile coordinates.
static bool DetectWallSection(int canvas_x, int canvas_y, DoorDirection &out_direction, bool &out_is_inner)
Detect wall with inner/outer section information.
static std::pair< int, int > PositionToRenderPixelCoords(uint8_t position, DoorDirection direction)
Convert encoded position to visible render pixel coordinates.
static uint8_t SnapToNearestPosition(int canvas_x, int canvas_y, DoorDirection direction)
Convert canvas coordinates to nearest valid door position.
static int GetWallEdge(DoorDirection direction)
Get the wall edge coordinate for a direction.
static constexpr int kTileSize
static constexpr int kRoomWidthTiles
static std::vector< int > GetSnapPositions(DoorDirection direction)
Get all valid snap positions for a given direction.
const std::array< uint16_t, 12 > & DoorTilemapOffsets(DoorDirection direction)
constexpr int TilemapOffsetToTileY(uint16_t offset)
constexpr std::array< uint16_t, 12 > kEastDoorTilemapOffsets
constexpr std::array< uint16_t, 12 > kSouthDoorTilemapOffsets
constexpr std::array< uint16_t, 12 > kWestDoorTilemapOffsets
constexpr std::array< uint16_t, 12 > kNorthDoorTilemapOffsets
constexpr int TilemapOffsetToTileX(uint16_t offset)
constexpr DoorDimensions GetDoorDimensions(DoorDirection dir)
Get door dimensions based on direction.
DoorType
Door types from ALTTP.
constexpr int kDoorPosSouthAddr
constexpr DoorFootprint GetEditorDoorFootprint(DoorDirection dir, DoorType type)
Get the visible editor footprint for a door.
constexpr int kDoorPosEastAddr
constexpr int kDoorPosNorthAddr
constexpr int kDoorPosWestAddr
DoorDirection
Door direction on room walls.
@ South
Bottom wall (horizontal door, 4x3 tiles)
@ North
Top wall (horizontal door, 4x3 tiles)
@ East
Right wall (vertical door, 3x4 tiles)
@ West
Left wall (vertical door, 3x4 tiles)