ability to move spawns in editor

This commit is contained in:
lustlion 2022-03-10 10:48:10 +01:00
parent 39b65571a0
commit 93bfe0bda4
2 changed files with 26 additions and 11 deletions

View File

@ -115,6 +115,7 @@ function stepEditor()
if Keybind:checkPressed(Keybind.debug.editor) then
editor_mode = not editor_mode
deselectSpawns()
createTileObjects()
end
end
@ -216,8 +217,12 @@ function doEditorEdit()
reloadLevelTiles()
else
if Keybind:checkDown(Keybind.generic.lclick) then
deselectSpawns()
selectSpawns(mouse_x,mouse_y)
end
if Keybind:checkDown(Keybind.generic.rclick) then
moveSpawns(mouse_x,mouse_y)
end
end
elseif Keybind:checkPressed(Keybind.generic.lshift) then
expandLevelCanvas(math.sign(expand_h),math.sign(expand_v))

View File

@ -10,13 +10,18 @@ end
function activateSpawns()
for _, spawn in pairs(LoadedObjects.Spawns) do
spawn.archetype:new(unpack(spawn.args))
spawn.archetype:new(unpack(spawn.args))
end
end
function deselectSpawns()
for _, spawn in pairs(LoadedObjects.Spawns) do
spawn.selected = nil
end
end
function selectSpawns(x,y)
for _, spawn in pairs(LoadedObjects.Spawns) do
spawn.selected = nil
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
local left = spawn.args[1] - Camera.pos.x - offset_x
local top = spawn.args[2] - Camera.pos.y - offset_y
@ -40,6 +45,15 @@ function selectSpawns(x,y)
end
end
function moveSpawns(x,y)
for _, spawn in pairs(LoadedObjects.Spawns) do
if spawn.selected then
spawn.args[1] = math.floor(x/game.scale)+Camera.pos.x
spawn.args[2] = math.floor(y/game.scale)+Camera.pos.y
end
end
end
function drawSpawns()
for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
@ -64,19 +78,15 @@ function drawSpawns()
)
if spawn.selected then
local text = ""
for i=1, #spawn.args do
text = text .. tostring(spawn.args[i])..", "
local text = spawn.archetype.type.."\n["..spawn.args[1]..","..spawn.args[2].."]\n"
for i=3, #spawn.args do
if i > 3 then text = text .. ", " end
text = text .. tostring(spawn.args[i])
end
love.graphics.print(
spawn.archetype.type,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y
)
love.graphics.print(
text,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y + 20
spawn.args[2] - Camera.pos.y
)
end
end