67 bool is_inner =
false;
90 if (valid_positions.empty()) {
96 int min_dist = std::abs(coord - valid_positions[0]);
97 for (
size_t i = 1; i < valid_positions.size(); ++i) {
98 int dist = std::abs(coord - valid_positions[i]);
99 if (dist < min_dist) {
101 nearest_idx =
static_cast<int>(i);
108 return static_cast<uint8_t
>(start_pos + nearest_idx);
131 int pos_idx = position & 0x0F;
143 static constexpr int kNorthDoorX[] = {14, 30, 46, 14, 30, 46,
144 14, 30, 46, 14, 30, 46};
146 static constexpr int kNorthDoorY[] = {4, 4, 4, 7, 7, 7,
147 36, 36, 36, 39, 39, 39};
159 static constexpr int kSouthDoorX[] = {14, 30, 46, 14, 30, 46,
160 14, 30, 46, 14, 30, 46};
164 static constexpr int kSouthDoorY[] = {26, 26, 26, 23, 23, 23,
165 58, 58, 58, 55, 55, 55};
171 static constexpr int kWestDoorX[] = {2, 2, 2, 5, 5, 5,
172 34, 34, 34, 37, 37, 37};
173 static constexpr int kWestDoorY[] = {15, 31, 47, 15, 31, 47,
174 15, 31, 47, 15, 31, 47};
181 static constexpr int kEastDoorX[] = {26, 26, 26, 23, 23, 23,
182 58, 58, 58, 55, 55, 55};
183 static constexpr int kEastDoorY[] = {15, 31, 47, 15, 31, 47,
184 15, 31, 47, 15, 31, 47};
187 if (pos_idx > 11) pos_idx = 11;
191 return {kNorthDoorX[pos_idx], kNorthDoorY[pos_idx]};
194 return {kSouthDoorX[pos_idx], kSouthDoorY[pos_idx]};
197 return {kWestDoorX[pos_idx], kWestDoorY[pos_idx]};
200 return {kEastDoorX[pos_idx], kEastDoorY[pos_idx]};
229 if (position > 0x1F) {
235 int tile = (position & 0x1F) * 2;
258 if (tile_y < threshold) {
270 if (tile_x < threshold) {
286 bool& out_is_inner) {
292 constexpr int kMiddleSeam = 32;
293 constexpr int kSeamThreshold = 6;
298 if (tile_y < threshold) {
300 out_is_inner =
false;
307 out_is_inner =
false;
312 if (tile_x < threshold) {
314 out_is_inner =
false;
321 out_is_inner =
false;
327 if (std::abs(tile_y - kMiddleSeam) < kSeamThreshold) {
329 if (tile_y < kMiddleSeam) {
339 if (std::abs(tile_x - kMiddleSeam) < kSeamThreshold) {
341 if (tile_x < kMiddleSeam) {
363 return is_inner ? 6 : 0;
368 return is_inner ? 0 : 6;
378 uint8_t byte1 = ((position & 0x0F) << 4) |
379 (
static_cast<uint8_t
>(direction) & 0x03);
382 uint8_t byte2 =
static_cast<uint8_t
>(type);
384 return {byte1, byte2};
392 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.
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)