commit 1327848b05e9b3b478ce6f455990b3975191dfa2 Author: annabunches Date: Mon Jul 22 19:01:26 2024 -0400 Initial commit. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ab0583 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + zip -f ./aseprite-advanced-spritesheets *.lua LICENSE diff --git a/advanced-spritesheet-export.lua b/advanced-spritesheet-export.lua new file mode 100644 index 0000000..947d33d --- /dev/null +++ b/advanced-spritesheet-export.lua @@ -0,0 +1,99 @@ +local extKey = "annabunches/AtlasExporter" + +function init(plugin) + plugin:newCommand{ + id="AnnabunchesASEExportSpritesheetAdvanced", + title="Export Spritesheet (Advanced)", + group="file_export", + onclick=exportSpritesheetAdvanced + } + + plugin:newCommand{ + id="AnnabunchesASEToggleIgnoreLayer", + title="Ignore on Export", + group="layer_popup_menu", + onclick=toggleIgnore + } + + plugin:newCommand{ + id="AnnabunchesASEToggleExportAsSprite", + title="Export as Sprite", + group="layer_popup_menu", + onclick=toggleExportAsSprite + } +end + +local function revealLayers(layers) + for i, layer in ipairs(layers) do + if layer.isGroup then + revealLayers(layer.layers) + end + + if not layer.isVisible then + layer.isVisible = true + layer.properties(extKey).revealed = true + end + end +end + +local function restoreLayers(layers) + for i, layer in ipairs(layers) do + if layer.isGroup then + restoreLayers(layer.layers) + end + + if layer.properties(extKey).revealed then + layer.isVisible = false +-- layer.properties(extKey).revealed = nil + end + end +end + +local function deleteLayers(sprite, layers) + for i, layer in ipairs(layers) do + if layer.name:find("%+i") then + sprite:deleteLayer(layer) + elseif layer.isGroup then + deleteLayers(sprite, layer.layers) + end + end +end + +local function flattenLayers(layers) + for i, layer in ipairs(layers) do + if not layer.isGroup then + goto continue + end + + -- Layers "tagged" with +f get flattened + if layer.name:find("%+f") then + app.range.layers = { layer } + app.command.FlattenLayers(false) + else + -- recurse + flattenLayers(layer.layers) + end + + ::continue:: + end +end + +local function exportSpritesheetAdvanced() + local sprite = app.activeSprite + if not sprite then + return app.alert "Must have a sprite open to export." + end + + app.transaction(function() + deleteLayers(sprite, sprite.layers) + flattenLayers(sprite.layers) + revealLayers(sprite.layers) + end) + app.command.ExportSpriteSheet { + splitLayers=true, + } + restoreLayers(sprite.layers) + app.undo() +end + +main() diff --git a/package.json b/package.json new file mode 100644 index 0000000..45f4f4a --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "advanced-spritesheets", + "displayName": "Advanced Spritesheets" + "description": "Improved spritesheet export functionality for Aseprite.", + "version": "0.1", + "author": { "name": "Anna Wiggins", + "email": "annabunches@gmail.com", + "url": "https://annabunches.net" }, + "contributors": [ ], + "publisher": "annabunches", + "license": "CC BY-SA 4.0", + "categories": [ "Scripts" ], + "contributes": { + "scripts": [ + { "path": "./advanced-spritesheet-export.lua" } + ] + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..3e4a31f --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +# Advanced spritesheet functionality for Aseprite + +This extension adds a more sophisticated spritesheet export command to Aseprite. + +## Installation + +To install, go to Aseprite's Settings -> Extensions -> Add Extension, and select advanced-spritesheet-export.aseprite-extension + +## Features + +* Choose which layers to export, regardless of visibility. +* Export groups as a single sprite. + +## Usage + +* All layers are exported by default. To ignore a layer, tk. +* To export a group as a single sprite, tk +* Invoke the tool via File -> Export -> Export Sprite Sheet (Advanced). +* Use the Sprite Sheet Export dialog as normal, but make sure Layers is set to "Visible Layers."