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

@ -841,14 +841,18 @@ function Room:registerNpc(entity)
end
function Room:getCellFromMousePos(mouseX, mouseY)
local cell = {}
cell.x = math.ceil(mouseX * gridWidth / width)
cell.y = math.ceil(mouseY * gridHeight / height)
return cell
if gameWorld and gameWorld.levels and gameWorld.levels[self.name] == self and
not gameWorld.drawingRoomNeighborhood then
return gameWorld:screenCellInRoom(self, mouseX, mouseY)
end
return {
x = math.floor(mouseX * gridWidth / width) + 1,
y = math.floor(mouseY * gridHeight / height) + 1,
}
end
function Room:attemptDelete(mouseX, mouseY, color)
local cell = self:getCellFromMousePos(mouseX, mouseY)
function Room:attemptDeleteAtCell(cell, color)
if not cell then return end
-- "white" (or nil) deletes every channel; otherwise just the picked one
local colors
@ -915,9 +919,13 @@ function Room:attemptDelete(mouseX, mouseY, color)
self:tick()
end
function Room:attemptPlace(name, props, mouseX, mouseY, color)
function Room:attemptDelete(mouseX, mouseY, color)
return self:attemptDeleteAtCell(self:getCellFromMousePos(mouseX, mouseY), color)
end
function Room:attemptPlaceAtCell(name, props, cell, color)
if not props or not props.sprites then return end
local cell = self:getCellFromMousePos(mouseX, mouseY)
if not cell then return end
-- Jorge is one dialogable NPC with three display channels, not three
-- independently placeable color-layer entities.
if name == "jorge" then
@ -944,6 +952,10 @@ function Room:attemptPlace(name, props, mouseX, mouseY, color)
self:tick()
end
function Room:attemptPlace(name, props, mouseX, mouseY, color)
return self:attemptPlaceAtCell(name, props, self:getCellFromMousePos(mouseX, mouseY), color)
end
function Room:load(name, preferRuntime)
-- Editor/startup loads must use the project source level. Runtime saves are
-- only consulted for an in-progress room-to-room game transition, otherwise