diff --git a/code/editor.lua b/code/editor.lua index af15977..5fd301e 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -65,7 +65,21 @@ function stepEditor() end if Keybind:CheckPressed(Keybind.debug.reload) then - ExportLevel("test") + Prompt:new({ + name = "level name", + input = "unnamed", + func = function(name_prompt) + if name_prompt.canceled then return end + Prompt:new({ + name = "filename", + input = "level.lua", + func = function(file_prompt) + if file_prompt.canceled then return end + ExportLevel(name_prompt.input, file_prompt.input) + end, + }):activate() + end, + }):activate() end if Keybind:CheckPressed(Keybind.debug.editor) then diff --git a/code/keybind.lua b/code/keybind.lua index 083b5d4..b69a441 100644 --- a/code/keybind.lua +++ b/code/keybind.lua @@ -44,6 +44,7 @@ function Keybind:CheckDown(action) end end +-- relies on being called exactly once per frame to be accurate. function Keybind:CheckPressed(action) if Keybind:CheckDown(action) then if not action.pressed then @@ -77,6 +78,7 @@ function Keybind:RemoveKeys(action) action.keys = {} end +-- this prolly should be used by Prompt:keypressed() function Keybind:hasKey(action, key) for _, v in pairs(action.keys) do if v == key then diff --git a/code/ui/prompt.lua b/code/ui/prompt.lua index 18eb60d..e612752 100644 --- a/code/ui/prompt.lua +++ b/code/ui/prompt.lua @@ -18,6 +18,8 @@ Prompt = { pos = { x = 10, y = 10 }, input = "", name = "input", + canceled = false, + closing = false, active_prompt = nil, } @@ -32,9 +34,12 @@ end function Prompt:keypressed(key, scancode, isrepeat) if key == "backspace" then self.input = backspace(self.input) - elseif key == "return" or key == "kpenter" then + elseif key == "return" or key == "kpenter" or key == "escape" then + if key == "escape" then + self.canceled = true + end + self.closing = true self:func() - Prompt.active_prompt = nil end end diff --git a/main.lua b/main.lua index be8b2c0..51e8a22 100644 --- a/main.lua +++ b/main.lua @@ -98,7 +98,13 @@ function love.update(dt) end if Prompt.active_prompt then - Prompt.active_prompt:update() + -- try to stop the keypress that closed the menu from spilling into the rest of the game + Keybind:CheckPressed(Keybind.menu.pause) + if Prompt.active_prompt.closing then + Prompt.active_prompt = nil + else + Prompt.active_prompt:update() + end return end