Files
love-tilesheet-tool/main.lua
T
2026-10-29 18:58:34 -06:00

64 lines
1.6 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, tiles_json, tile_image
local current_text = ""
local get_tile_usage = function(tiles_json, tile_image)
local image_width, image_height = tile_image:getDimensions()
local tile_usage = {}
for x = 1, image_width / tiles_json.tile_size do
tile_usage[x] = {}
for y = 1, image_height / tiles_json.tile_size do
tile_usage[x][y] = false
end
end
for name, tile_data in pairs(tiles_json.tiles) do
tile_usage[tile_data.x][tile_data.y] = true
end
return tile_usage
end
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_json = utility.load_data(file_path)
tiles, tile_image = tilesheet(tiles_json)
else
tiles_json = {
image_path = file_path,
}
tiles, tile_image = tilesheet(file_path)
end
end