43 lines
1.0 KiB
Lua
43 lines
1.0 KiB
Lua
local tilesheet = require "lib.tilesheet"
|
|
local utf8 = require "utf8"
|
|
local utility = require "lib.utility"
|
|
|
|
local window_width, window_height = love.graphics.getDimensions()
|
|
|
|
local tiles
|
|
local current_text = ""
|
|
|
|
function love.load()
|
|
love.keyboard.setKeyRepeat(true)
|
|
end
|
|
|
|
function love.draw()
|
|
love.graphics.printf("Prompt:", 0, 0, window_width)
|
|
love.graphics.printf(current_text, 0, 20, window_width) -- lazy magic numbers
|
|
end
|
|
|
|
function love.textinput(character)
|
|
current_text = current_text .. character
|
|
end
|
|
|
|
function love.keypressed(key)
|
|
if key == "escape" then
|
|
love.event.quit()
|
|
elseif key == "backspace" then
|
|
local byteoffset = utf8.offset(current_text, -1)
|
|
if byteoffset then
|
|
current_text = current_text:sub(1, byteoffset - 1)
|
|
end
|
|
elseif key == "enter" then
|
|
-- TODO end of a textinput; what to do depends on what was being asked
|
|
end
|
|
end
|
|
|
|
function love.filedropped(file_path)
|
|
if file_path:sub(-5) == ".json" then
|
|
tiles = tilesheet(utility.load_data(file_path))
|
|
else
|
|
tiles = tilesheet(file_path)
|
|
end
|
|
end
|