From 93bfe0bda45a1aa926120e9e2c227de72c49b9f3 Mon Sep 17 00:00:00 2001 From: lustlion Date: Thu, 10 Mar 2022 10:48:10 +0100 Subject: [PATCH] ability to move spawns in editor --- code/editor.lua | 5 +++++ code/spawn.lua | 32 +++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/code/editor.lua b/code/editor.lua index 6de1452..44804e1 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -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)) diff --git a/code/spawn.lua b/code/spawn.lua index 196f4be..7ac65a7 100644 --- a/code/spawn.lua +++ b/code/spawn.lua @@ -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