local pluginKey = "bts/p8-font-metrics" local sprite = app.sprite local name = app.fs.fileTitle(sprite.filename) local previousExportFilename = sprite.properties(pluginKey).previousExportFilename if previousExportFilename == nil then local defaultPath = app.fs.filePath(sprite.filename) local defaultFilename = name..".lua" previousExportFilename = app.fs.joinPath(defaultPath, defaultFilename) end local dlg = Dialog() dlg:file{ id="metrics_filename", label="Metrics output:", filename=previousExportFilename, filetypes=".lua", save=true } dlg:button{ id="confirm", text="Confirm" } dlg:button{ id="cancel", text="Cancel" } dlg:show() local data = dlg.data if data.confirm then name = app.fs.fileTitle(data.metrics_filename) local basePath = app.fs.filePath(data.metrics_filename) local imagePath = app.fs.joinPath(basePath, name) local characterDetails = {} for cy=0,15 do for cx=0,15 do local x,y=cx*8,cy*8 local width = 8 for i, slice in ipairs(sprite.slices) do if slice.bounds.x == x and slice.bounds.y == y then width = slice.bounds.width+1 break end end table.insert(characterDetails, width) end end if true then --local metricsFilename = app.fs.joinPath(metricsPath, data.metrics_filename) local metricsFile = io.open(data.metrics_filename, "w") metricsFile:write(name.."Widths = split[[") for k,v in ipairs(characterDetails) do metricsFile:write(v .. ",") end metricsFile:write("]]\n") metricsFile:write("\n") io.close(metricsFile) end sprite.properties(pluginKey).previousExportFilename = data.metrics_filename end