mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
fix: Remove grid alignment for multiple connections to fix door alignment
The previous fix attempted to position rooms based on door positions, but grid alignment (alignToGrid) was rounding positions to 160px boundaries, breaking the precise positioning needed for door alignment. Issue: When test_mixed_room_sizes.json loaded, the closet room was positioned at (-160, -256) but its door was at (48, -96). The door was 48px to the right of the room's bounds, completely outside the room tiles. Root cause: Grid alignment was rounding x=-32 to x=-160, shifting the room 160px to the left. Solution: Remove alignToGrid calls for multiple room connections and use exact positioning: - North/South: roomX = doorX - edgeInset (positions room so door is at edgeInset from left) - East/West: roomY = doorY - (TILE_SIZE * 2) (positions room so door is 2 tiles from top) This ensures doors are positioned within room bounds and align properly between different-sized rooms (e.g., 1×1 GU closet, 2×1 GU hall, 2×2 GU CEO office).
This commit is contained in:
@@ -1054,8 +1054,8 @@ function positionNorthMultiple(currentRoom, connectedRooms, currentPos, dimensio
|
||||
const currentDim = dimensions[currentRoom];
|
||||
const positions = {};
|
||||
|
||||
// CRITICAL: Position rooms based on where doors will be, not just centering widths
|
||||
// This ensures doors align properly between different-sized rooms
|
||||
// CRITICAL: Position rooms based on where doors will be, ensuring door alignment
|
||||
// DO NOT use grid alignment here - it breaks door positioning
|
||||
|
||||
// Calculate where doors will be placed on current room's north wall
|
||||
// (uses same logic as placeNorthDoorsMultiple in doors.js)
|
||||
@@ -1070,14 +1070,17 @@ function positionNorthMultiple(currentRoom, connectedRooms, currentPos, dimensio
|
||||
// Calculate where the door will be on current room's north wall
|
||||
const doorX = currentPos.x + edgeInset + (doorSpacing * index);
|
||||
|
||||
// Center the connected room on this door position
|
||||
const x = doorX - (connectedDim.widthPx / 2);
|
||||
// Position the room such that its south door will align with this door
|
||||
// The south door will be placed at edgeInset from the room's left edge
|
||||
// (or aligned with parent if parent has multiple connections - handled by door placement)
|
||||
// So: roomX + edgeInset = doorX, therefore roomX = doorX - edgeInset
|
||||
const x = doorX - edgeInset;
|
||||
|
||||
// Y position is based on stacking height
|
||||
const y = currentPos.y - connectedDim.stackingHeightPx;
|
||||
|
||||
// Align to grid
|
||||
positions[roomId] = alignToGrid(x, y);
|
||||
// DO NOT align to grid - use exact positioning for door alignment
|
||||
positions[roomId] = { x, y };
|
||||
});
|
||||
|
||||
return positions;
|
||||
@@ -1105,8 +1108,8 @@ function positionSouthMultiple(currentRoom, connectedRooms, currentPos, dimensio
|
||||
const currentDim = dimensions[currentRoom];
|
||||
const positions = {};
|
||||
|
||||
// CRITICAL: Position rooms based on where doors will be, not just centering widths
|
||||
// This ensures doors align properly between different-sized rooms
|
||||
// CRITICAL: Position rooms based on where doors will be, ensuring door alignment
|
||||
// DO NOT use grid alignment here - it breaks door positioning
|
||||
|
||||
// Calculate where doors will be placed on current room's south wall
|
||||
// (uses same logic as placeSouthDoorsMultiple in doors.js)
|
||||
@@ -1121,14 +1124,16 @@ function positionSouthMultiple(currentRoom, connectedRooms, currentPos, dimensio
|
||||
// Calculate where the door will be on current room's south wall
|
||||
const doorX = currentPos.x + edgeInset + (doorSpacing * index);
|
||||
|
||||
// Center the connected room on this door position
|
||||
const x = doorX - (connectedDim.widthPx / 2);
|
||||
// Position the room such that its north door will align with this door
|
||||
// The north door will be placed at edgeInset from the room's left edge
|
||||
// So: roomX + edgeInset = doorX, therefore roomX = doorX - edgeInset
|
||||
const x = doorX - edgeInset;
|
||||
|
||||
// Y position below current room
|
||||
const y = currentPos.y + currentDim.stackingHeightPx;
|
||||
|
||||
// Align to grid
|
||||
positions[roomId] = alignToGrid(x, y);
|
||||
// DO NOT align to grid - use exact positioning for door alignment
|
||||
positions[roomId] = { x, y };
|
||||
});
|
||||
|
||||
return positions;
|
||||
@@ -1156,8 +1161,8 @@ function positionEastMultiple(currentRoom, connectedRooms, currentPos, dimension
|
||||
const currentDim = dimensions[currentRoom];
|
||||
const positions = {};
|
||||
|
||||
// CRITICAL: Position rooms based on where doors will be, not just stacking vertically
|
||||
// This ensures doors align properly between different-sized rooms
|
||||
// CRITICAL: Position rooms based on where doors will be, ensuring door alignment
|
||||
// DO NOT use grid alignment here - it breaks door positioning
|
||||
|
||||
// Position to the right
|
||||
const x = currentPos.x + currentDim.widthPx;
|
||||
@@ -1174,11 +1179,13 @@ function positionEastMultiple(currentRoom, connectedRooms, currentPos, dimension
|
||||
// Calculate where the door will be on current room's east wall
|
||||
const doorY = topY + (doorSpacing * index);
|
||||
|
||||
// Center the connected room on this door position vertically
|
||||
const y = doorY - (TILE_SIZE * 2); // Align with door at 2 tiles from top
|
||||
// Position the room such that its west door will align with this door
|
||||
// The west door will be at roomY + (TILE_SIZE * 2)
|
||||
// So: roomY + (TILE_SIZE * 2) = doorY, therefore roomY = doorY - (TILE_SIZE * 2)
|
||||
const y = doorY - (TILE_SIZE * 2);
|
||||
|
||||
// Align to grid
|
||||
positions[roomId] = alignToGrid(x, y);
|
||||
// DO NOT align to grid - use exact positioning for door alignment
|
||||
positions[roomId] = { x, y };
|
||||
});
|
||||
|
||||
return positions;
|
||||
@@ -1205,8 +1212,8 @@ function positionWestMultiple(currentRoom, connectedRooms, currentPos, dimension
|
||||
const currentDim = dimensions[currentRoom];
|
||||
const positions = {};
|
||||
|
||||
// CRITICAL: Position rooms based on where doors will be, not just stacking vertically
|
||||
// This ensures doors align properly between different-sized rooms
|
||||
// CRITICAL: Position rooms based on where doors will be, ensuring door alignment
|
||||
// DO NOT use grid alignment here - it breaks door positioning
|
||||
|
||||
// Calculate where doors will be placed on current room's west wall
|
||||
// (uses same logic as placeWestDoorsMultiple in doors.js)
|
||||
@@ -1223,11 +1230,13 @@ function positionWestMultiple(currentRoom, connectedRooms, currentPos, dimension
|
||||
// Calculate where the door will be on current room's west wall
|
||||
const doorY = topY + (doorSpacing * index);
|
||||
|
||||
// Center the connected room on this door position vertically
|
||||
const y = doorY - (TILE_SIZE * 2); // Align with door at 2 tiles from top
|
||||
// Position the room such that its east door will align with this door
|
||||
// The east door will be at roomY + (TILE_SIZE * 2)
|
||||
// So: roomY + (TILE_SIZE * 2) = doorY, therefore roomY = doorY - (TILE_SIZE * 2)
|
||||
const y = doorY - (TILE_SIZE * 2);
|
||||
|
||||
// Align to grid
|
||||
positions[roomId] = alignToGrid(x, y);
|
||||
// DO NOT align to grid - use exact positioning for door alignment
|
||||
positions[roomId] = { x, y };
|
||||
});
|
||||
|
||||
return positions;
|
||||
|
||||
Reference in New Issue
Block a user