From dbfae2f74ea81408a595ccd5e081abb89139fe65 Mon Sep 17 00:00:00 2001 From: lustlion Date: Thu, 10 Mar 2022 18:23:47 +0100 Subject: [PATCH] you can now edit archetype and args of spawns in editor with "t" and "d" when selected, respectively --- code/editor.lua | 6 ++++ code/game.lua | 18 +++++++----- code/spawn.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++ code/ui/prompt.lua | 7 ++--- 4 files changed, 89 insertions(+), 11 deletions(-) diff --git a/code/editor.lua b/code/editor.lua index 44804e1..3bd3ddf 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -117,6 +117,7 @@ function stepEditor() editor_mode = not editor_mode deselectSpawns() createTileObjects() + restartGame() end end @@ -223,6 +224,11 @@ function doEditorEdit() if Keybind:checkDown(Keybind.generic.rclick) then moveSpawns(mouse_x,mouse_y) end + if Keybind:checkDown({keys={"t"}}) then + promptSpawnArchetype() + elseif Keybind:checkDown({keys={"d"}}) then + promptSpawnArgs() + end end elseif Keybind:checkPressed(Keybind.generic.lshift) then expandLevelCanvas(math.sign(expand_h),math.sign(expand_v)) diff --git a/code/game.lua b/code/game.lua index 34b0114..23c54fe 100644 --- a/code/game.lua +++ b/code/game.lua @@ -1,3 +1,14 @@ +function restartGame() + for _, entity in ipairs(LoadedObjects.Entities) do + if entity.light ~= nil then entity.light:kill() end + entity = nil + end + LoadedObjects.Entities = {} + LoadedObjects.Particles = {} + main_player = Player:new(75,50) + activateSpawns() +end + function stepGame() setCollisionFlags() if menu_type == "no" then @@ -33,13 +44,6 @@ function stepGame() end if Keybind:checkPressed(Keybind.debug.reposition) then - if not editor_mode then - main_player.pos.x, main_player.pos.y = 75,50 - end - for _, entity in pairs(LoadedObjects.Entities) do - if entity.id ~= main_player.id then entity:kill() end - end - activateSpawns() end if Keybind:checkPressed(Keybind.debug.reload) then diff --git a/code/spawn.lua b/code/spawn.lua index 7ac65a7..eb42fcf 100644 --- a/code/spawn.lua +++ b/code/spawn.lua @@ -22,6 +22,7 @@ end function selectSpawns(x,y) for _, spawn in pairs(LoadedObjects.Spawns) do + 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 @@ -54,6 +55,73 @@ function moveSpawns(x,y) end end +function promptSpawnArchetype() + if Prompt.active_prompt then + Prompt.active_prompt.canceled = true + end + for _, spawn in pairs(LoadedObjects.Spawns) do + if spawn.selected then + local offset_x, offset_y = spawn.archetype.display:getCenteredOffset() + local text = "" + for i=1, #spawn.args do + if i > 1 then text = text .. ", " end + text = text .. tostring(spawn.args[i]) + end + local prompt = Prompt:new({ + name = "archetype", + input = spawn.archetype.type, + spawn = spawn, + func = function(prompt) + local arch = spawn.archetype + print("return "..prompt.input) + local f = loadstring("return "..prompt.input) + if f == nil then + spawn.archetype = arch + else + spawn.archetype = f() + end + end, + }) + prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x + prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y + prompt:activate() + end + end +end + +function promptSpawnArgs() + if Prompt.active_prompt then + Prompt.active_prompt.canceled = true + end + for _, spawn in pairs(LoadedObjects.Spawns) do + if spawn.selected then + local offset_x, offset_y = spawn.archetype.display:getCenteredOffset() + local text = "" + for i=1, #spawn.args do + if i > 1 then text = text .. ", " end + text = text .. tostring(spawn.args[i]) + end + local prompt = Prompt:new({ + name = "args", + input = text, + func = function(prompt) + + local f = loadstring("return {"..prompt.input.."}") + + if f == nil then + spawn.args = arch + else + spawn.args = f() + end + end, + }) + prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x + prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y + prompt:activate() + end + end +end + function drawSpawns() for _, spawn in pairs(LoadedObjects.Spawns) do local offset_x, offset_y = spawn.archetype.display:getCenteredOffset() @@ -63,6 +131,7 @@ function drawSpawns() spawn.args[2] - Camera.pos.y - offset_y ) + if spawn.selected then love.graphics.setColor(0,1,1,1) else diff --git a/code/ui/prompt.lua b/code/ui/prompt.lua index e612752..6b0b2a9 100644 --- a/code/ui/prompt.lua +++ b/code/ui/prompt.lua @@ -9,7 +9,7 @@ local function backspace(text) -- so we couldn't do string.sub(text, 1, -2). return string.sub(text, 1, byteoffset - 1) end - + return "" end @@ -20,7 +20,7 @@ Prompt = { name = "input", canceled = false, closing = false, - + active_prompt = nil, } @@ -44,7 +44,7 @@ function Prompt:keypressed(key, scancode, isrepeat) end function Prompt:update() - + end function Prompt:textinput(text) @@ -65,4 +65,3 @@ local test_prompt = Prompt:new() assert(test_prompt.name == "input") test_prompt.name = "foobar" assert(Prompt.name == "input") -