Compare commits
No commits in common. "edd064c2fdca2961c6806238d931ec1406c631b6" and "3c4f763ae7a8babb3fa1ee91be6374f8558a743f" have entirely different histories.
edd064c2fd
...
3c4f763ae7
@ -65,21 +65,7 @@ function stepEditor()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:CheckPressed(Keybind.debug.reload) then
|
if Keybind:CheckPressed(Keybind.debug.reload) then
|
||||||
Prompt:new({
|
ExportLevel("test")
|
||||||
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
|
end
|
||||||
|
|
||||||
if Keybind:CheckPressed(Keybind.debug.editor) then
|
if Keybind:CheckPressed(Keybind.debug.editor) then
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
function ExportLevel(levelname, filename)
|
function ExportLevel(levelname, filename)
|
||||||
love.filesystem.createDirectory("export")
|
os.execute( "mkdir \"./export\"" )
|
||||||
filename = filename or "output.lua"
|
filename = filename or "output.lua"
|
||||||
if string.sub(filename, 1, 1) ~= "/" then
|
filename = "export/"..filename
|
||||||
filename = "export/"..filename
|
|
||||||
end
|
|
||||||
exportFile = io.open(filename, "w+")
|
exportFile = io.open(filename, "w+")
|
||||||
|
|
||||||
if exportFile then
|
if exportFile then
|
||||||
|
@ -44,7 +44,6 @@ function Keybind:CheckDown(action)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- relies on being called exactly once per frame to be accurate.
|
|
||||||
function Keybind:CheckPressed(action)
|
function Keybind:CheckPressed(action)
|
||||||
if Keybind:CheckDown(action) then
|
if Keybind:CheckDown(action) then
|
||||||
if not action.pressed then
|
if not action.pressed then
|
||||||
@ -78,17 +77,6 @@ function Keybind:RemoveKeys(action)
|
|||||||
action.keys = {}
|
action.keys = {}
|
||||||
end
|
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
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function Keybind:Default()
|
function Keybind:Default()
|
||||||
--Menu
|
--Menu
|
||||||
Keybind.menu.pause.keys = {"escape"}
|
Keybind.menu.pause.keys = {"escape"}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
-- data
|
-- data
|
||||||
require "data/animations"
|
require "data/animations"
|
||||||
require "data/shaders"
|
require "data/shaders"
|
||||||
|
@ -7,4 +7,3 @@ end
|
|||||||
|
|
||||||
require "code/ui/button"
|
require "code/ui/button"
|
||||||
require "code/ui/dialog"
|
require "code/ui/dialog"
|
||||||
require "code/ui/prompt"
|
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
local utf8 = require("utf8")
|
|
||||||
|
|
||||||
local function backspace(text)
|
|
||||||
local byteoffset = utf8.offset(text, -1)
|
|
||||||
|
|
||||||
if byteoffset then
|
|
||||||
-- remove the last UTF-8 character.
|
|
||||||
-- string.sub operates on bytes rather than UTF-8 characters,
|
|
||||||
-- so we couldn't do string.sub(text, 1, -2).
|
|
||||||
return string.sub(text, 1, byteoffset - 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
Prompt = {
|
|
||||||
-- defaults for instance variables
|
|
||||||
pos = { x = 10, y = 10 },
|
|
||||||
input = "",
|
|
||||||
name = "input",
|
|
||||||
canceled = false,
|
|
||||||
closing = false,
|
|
||||||
|
|
||||||
active_prompt = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
function Prompt:new(o)
|
|
||||||
o = o or {}
|
|
||||||
setmetatable(o, self)
|
|
||||||
self.__index = self
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Prompt:keypressed(key, scancode, isrepeat)
|
|
||||||
if key == "backspace" then
|
|
||||||
self.input = backspace(self.input)
|
|
||||||
elseif key == "return" or key == "kpenter" or key == "escape" then
|
|
||||||
if key == "escape" then
|
|
||||||
self.canceled = true
|
|
||||||
end
|
|
||||||
self.closing = true
|
|
||||||
self:func()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Prompt:update()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function Prompt:textinput(text)
|
|
||||||
self.input = self.input .. text
|
|
||||||
end
|
|
||||||
|
|
||||||
function Prompt:draw()
|
|
||||||
love.graphics.print(self.name .. ": " .. self.input, self.pos.x, self.pos.y)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Prompt:activate()
|
|
||||||
Prompt.active_prompt = self
|
|
||||||
love.keyboard.setTextInput(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- demonstration of how default values work
|
|
||||||
local test_prompt = Prompt:new()
|
|
||||||
assert(test_prompt.name == "input")
|
|
||||||
test_prompt.name = "foobar"
|
|
||||||
assert(Prompt.name == "input")
|
|
||||||
|
|
41
main.lua
41
main.lua
@ -62,18 +62,6 @@ function love.load()
|
|||||||
--love.audio.play(music.placeholder)
|
--love.audio.play(music.placeholder)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.textinput(text)
|
|
||||||
if Prompt.active_prompt then
|
|
||||||
Prompt.active_prompt:textinput(text)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keypressed(...)
|
|
||||||
if Prompt.active_prompt then
|
|
||||||
Prompt.active_prompt:keypressed(...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
-- audio update
|
-- audio update
|
||||||
love.audio.update()
|
love.audio.update()
|
||||||
@ -97,36 +85,15 @@ function love.update(dt)
|
|||||||
logWrite("Second "..secs..": "..memoryUsage.." kB")
|
logWrite("Second "..secs..": "..memoryUsage.." kB")
|
||||||
end
|
end
|
||||||
|
|
||||||
if Prompt.active_prompt then
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
if love.keyboard.isDown("f7") then
|
|
||||||
local test_prompt = Prompt:new({
|
|
||||||
name = "test prompt",
|
|
||||||
func = function(prompt)
|
|
||||||
print("test prompt got input: "..prompt.input)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
test_prompt:activate()
|
|
||||||
end
|
|
||||||
|
|
||||||
--keypressed
|
--keypressed
|
||||||
if Keybind:CheckPressed(Keybind.menu.pause) then
|
if Keybind:CheckPressed(Keybind.menu.pause) then
|
||||||
if do_pause then
|
if do_pause then
|
||||||
do_pause = false
|
do_pause = false
|
||||||
else
|
else
|
||||||
menu_type = "pause"
|
menu_type = "pause"
|
||||||
MenuInit(menu_type)
|
MenuInit(menu_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--MenuStep
|
--MenuStep
|
||||||
if menu_type ~= nil then MenuStep(menu_type) end
|
if menu_type ~= nil then MenuStep(menu_type) end
|
||||||
@ -167,9 +134,5 @@ function love.draw()
|
|||||||
|
|
||||||
if DemoRecording or DemoPlayback then Demo:draw() end
|
if DemoRecording or DemoPlayback then Demo:draw() end
|
||||||
|
|
||||||
if Prompt.active_prompt then
|
|
||||||
Prompt.active_prompt:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
frameDebugFlush()
|
frameDebugFlush()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user