|
local spr = app.sprite |
|
if not spr then return print('No active sprite') end |
|
local path, title = spr.filename:match("^(.+[/\\])(.-).([^.]*)$") |
|
|
|
-- PREFERENCES |
|
if not ExportScriptPreferences then |
|
ExportScriptPreferences = {} |
|
end |
|
if not ExportScriptPreferences[spr.filename] then |
|
ExportScriptPreferences[spr.filename] = {} |
|
ExportScriptPreferences[spr.filename].exportPath = "{title}-{tag}.png" |
|
end |
|
|
|
|
|
-- EXPORT |
|
function Export(exportPath, layer) |
|
local p = app.fs.filePath(spr.filename) |
|
for _, tag in ipairs(spr.tags) do |
|
local subpath = exportPath:gsub('{tag}', tag.name):gsub('{title}', title) |
|
app.command.ExportSpriteSheet { |
|
ui = true, |
|
askOverwrite=true, |
|
type = SpriteSheetType.HORIZONTAL, |
|
textureFilename = app.fs.joinPath(p, subpath), |
|
-- dataFilename = tag .. '.json', |
|
-- dataFormat = SpriteSheetDataFormat.JSON_ARRAY, |
|
tag = tag.name, |
|
layer = layer, |
|
} |
|
end |
|
end |
|
|
|
-- UI |
|
local data = Dialog { title="Exporter" } |
|
:entry { id="layer", label="Layer: ", text=app.layer.name } |
|
:entry { id="exportPath", label="Filename: ", text=ExportScriptPreferences[spr.filename].exportPath } |
|
:button { id="confirm", text="Save sheets" } |
|
:button { id="cancel", text="Cancel" } |
|
:show().data |
|
|
|
if data.confirm then |
|
ExportScriptPreferences[spr.filename].exportPath = data.exportPath |
|
Export(data.exportPath, data.layer) |
|
end |