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)};
181 if (position > 0x1F) {
187 int tile = (position & 0x1F) * 2;
209 if (tile_y < threshold) {
221 if (tile_x < threshold) {
237 bool& out_is_inner) {
243 constexpr int kMiddleSeam = 32;
244 constexpr int kSeamThreshold = 6;
249 if (tile_y < threshold) {
251 out_is_inner =
false;
258 out_is_inner =
false;
263 if (tile_x < threshold) {
265 out_is_inner =
false;
272 out_is_inner =
false;
278 if (std::abs(tile_y - kMiddleSeam) < kSeamThreshold) {
280 if (tile_y < kMiddleSeam) {
290 if (std::abs(tile_x - kMiddleSeam) < kSeamThreshold) {
292 if (tile_x < kMiddleSeam) {
314 return is_inner ? 6 : 0;
319 return is_inner ? 0 : 6;
330 ((position & 0x0F) << 4) | (
static_cast<uint8_t
>(direction) & 0x03);
333 uint8_t byte2 =
static_cast<uint8_t
>(type);
335 return {byte1, byte2};
343 return {pixel_x, pixel_y, dims.width_pixels(), dims.height_pixels()};
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 > 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 > 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 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 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)