Compare commits

..

No commits in common. "edd064c2fdca2961c6806238d931ec1406c631b6" and "3c4f763ae7a8babb3fa1ee91be6374f8558a743f" have entirely different histories.

7 changed files with 5 additions and 141 deletions

View File

@ -65,21 +65,7 @@ function stepEditor()
end
if Keybind:CheckPressed(Keybind.debug.reload) then
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()
ExportLevel("test")
end
if Keybind:CheckPressed(Keybind.debug.editor) then

View File

@ -1,9 +1,7 @@
function ExportLevel(levelname, filename)
love.filesystem.createDirectory("export")
os.execute( "mkdir \"./export\"" )
filename = filename or "output.lua"
if string.sub(filename, 1, 1) ~= "/" then
filename = "export/"..filename
end
exportFile = io.open(filename, "w+")
if exportFile then

View File

@ -44,7 +44,6 @@ 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
@ -78,17 +77,6 @@ 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
return true
end
end
return false
end
function Keybind:Default()
--Menu
Keybind.menu.pause.keys = {"escape"}

View File

@ -1,5 +1,3 @@
-- data
require "data/animations"
require "data/shaders"

View File

@ -7,4 +7,3 @@ end
require "code/ui/button"
require "code/ui/dialog"
require "code/ui/prompt"

View File

@ -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")

View File

@ -62,18 +62,6 @@ function love.load()
--love.audio.play(music.placeholder)
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)
-- audio update
love.audio.update()
@ -97,27 +85,6 @@ function love.update(dt)
logWrite("Second "..secs..": "..memoryUsage.." kB")
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
if Keybind:CheckPressed(Keybind.menu.pause) then
if do_pause then
@ -167,9 +134,5 @@ function love.draw()
if DemoRecording or DemoPlayback then Demo:draw() end
if Prompt.active_prompt then
Prompt.active_prompt:draw()
end
frameDebugFlush()
end