Unify editor input with room preview transform

This commit is contained in:
Your Name 2026-08-12 02:58:01 -04:00
parent 3c5e6daf06
commit 8fae34b803
5 changed files with 82 additions and 29 deletions

View file

@ -908,13 +908,12 @@ function World:drawOverlaps(room, color)
end
end
-- Render the active room at a small zoom-out, together with the eight world
-- neighbours around it. This is display-only: individual rooms still own
-- their data, collision, and authored boundary walls.
function World:drawRoomNeighborhood(room)
if self.drawingRoomNeighborhood then return end
-- The neighbourhood renderer and editor pointer mapping share this exact
-- transform. Keeping it in one place prevents a visual zoom adjustment from
-- silently shifting placement/deletion by a tile.
function World:roomNeighborhoodTransform(room)
local location = self:roomLocation(room.name)
if not location then return end
if not location then return nil end
-- Leave enough margin to read several cells of each neighbour, not merely
-- its boundary wall. This keeps a nearby separated player discoverable.
@ -932,16 +931,47 @@ function World:drawRoomNeighborhood(room)
cameraY = transition.dy * (1 - eased)
if progress >= 1 then self.roomTransition = nil end
end
return {location = location, zoom = zoom, originX = originX, originY = originY,
cameraX = cameraX, cameraY = cameraY}
end
-- Convert a gameplay-screen coordinate to a cell in the centered room. The
-- surrounding rooms are preview-only while editing; browse to one with WASD
-- before changing it. Returns nil for the preview margin or any other room.
function World:screenCellInRoom(room, mouseX, mouseY)
local transform = self:roomNeighborhoodTransform(room)
if not transform then return nil end
local roomOffsetX = (mouseX - transform.originX) / (width * transform.zoom) - transform.cameraX
local roomOffsetY = (mouseY - transform.originY) / (height * transform.zoom) - transform.cameraY
local offsetX, offsetY = math.floor(roomOffsetX), math.floor(roomOffsetY)
if offsetX ~= 0 or offsetY ~= 0 then return nil end
local localX = (roomOffsetX - offsetX) * width
local localY = (roomOffsetY - offsetY) * height
local cell = {
x = math.floor(localX * gridWidth / width) + 1,
y = math.floor(localY * gridHeight / height) + 1,
}
if cell.x < 1 or cell.x > gridWidth or cell.y < 1 or cell.y > gridHeight then return nil end
return cell
end
-- Render the active room at a small zoom-out, together with the eight world
-- neighbours around it. This is display-only: individual rooms still own
-- their data, collision, and authored boundary walls.
function World:drawRoomNeighborhood(room)
if self.drawingRoomNeighborhood then return end
local transform = self:roomNeighborhoodTransform(room)
if not transform then return end
self.drawingRoomNeighborhood = true
for roomY = -1, 1 do
for roomX = -1, 1 do
local name = self:roomAt(location.x + roomX, location.y + roomY)
local name = self:roomAt(transform.location.x + roomX, transform.location.y + roomY)
local adjacent = name and self.levels[name]
if adjacent then
love.graphics.push()
love.graphics.translate(originX + (roomX + cameraX) * width * zoom,
originY + (roomY + cameraY) * height * zoom)
love.graphics.scale(zoom, zoom)
love.graphics.translate(transform.originX + (roomX + transform.cameraX) * width * transform.zoom,
transform.originY + (roomY + transform.cameraY) * height * transform.zoom)
love.graphics.scale(transform.zoom, transform.zoom)
adjacent:draw()
love.graphics.pop()
end