--[[ Version: 1.0 Description: Exports cells in single files ignoring duplicates (linked cells). Scripted by https://community.aseprite.org/u/scovillo --]] local function contains (table, value) for _, item in ipairs(table) do if item == value then return true end end return false end local function count (table) counter = 0 for _, _ in ipairs(table) do counter = counter + 1 end return counter end function getPath(str, sep) sep = sep or '/' return str:match("(.*" .. sep .. ")") end function getFileName(str, sep) str = str:match("^.+" .. sep .. "(.+)$") return str:match("(.+)%..+") end local sprite = app.activeSprite if (sprite == nil) then local dialog = Dialog("Error") dialog:label { id = 0, text = "Open a sprite before you run the script!" } dialog:newrow() dialog:button { id = 1, text = "OK", onclick = function() dialog:close() end } dialog:show() return end local path = sprite.filename local separator if (string.sub(path, 1, 1) == "/") then separator = "/" else separator = "\\" end local outputPath = getPath(path, separator) .. "spriter" .. separator .. "frames" .. separator local function extractCellsFrom (layer, groupName) layerImages = {} if (count(sprite.tags) == 0) then animationIndex = 0 for k, _ in ipairs(sprite.frames) do local cel = layer:cel(k) if (not contains(layerImages, cel.image)) then cel.image:saveAs(outputPath .. layer.name .. groupName .. "_" .. animationIndex .. ".png") animationIndex = animationIndex + 1 table.insert(layerImages, cel.image) end end else frameIndex = 0 for _, tag in ipairs(sprite.tags) do animationIndex = 0 for _ = 1, tag.frames do frameIndex = frameIndex + 1 local cel = layer:cel(frameIndex) if (not contains(layerImages, cel.image)) then cel.image:saveAs(outputPath .. layer.name .. groupName .. "_" .. tag.name .. "_" .. animationIndex .. ".png") animationIndex = animationIndex + 1 table.insert(layerImages, cel.image) end end end end end for _, layer in ipairs(sprite.layers) do if (layer.isGroup) then if (layer.isVisible) then for _, subLayer in ipairs(layer.layers) do if (subLayer.isVisible) then extractCellsFrom(subLayer, "_" .. layer.name) end end end else if (layer.isVisible) then extractCellsFrom(layer, "") end end end