diff --git a/abase-commands.lua b/abase-commands.lua index 02a6ac1..9556281 100644 --- a/abase-commands.lua +++ b/abase-commands.lua @@ -20,8 +20,7 @@ local function ExportSpritesheetAdvanced() spr:close() end -local function ToggleIgnore() - local layer = app.layer +local function toggleIgnoreLayer(layer) if (layer.properties(extKey).ignored) then layer.properties(extKey).ignored = false else @@ -30,8 +29,17 @@ local function ToggleIgnore() colorUtils.SetColorFromRoot(layer) end -local function ToggleExportAsSprite() - local layer = app.layer +-- Toggle ignore for all selected layers +-- TODO: should this behavior change when selected layers start with mixed state? +local function ToggleIgnore() + for _, layer in ipairs(app.range.layers) do + toggleIgnoreLayer(layer) + end +end + +local function toggleExportAsSpriteLayer(layer) + if not layer.isGroup then return end + if (layer.properties(extKey).exportedAsSprite) then layer.properties(extKey).exportedAsSprite = false else @@ -40,6 +48,14 @@ local function ToggleExportAsSprite() colorUtils.SetColorFromRoot(layer) end +-- Toggle Merge on Export for all selected group layers +-- TODO: should this behavior change when selected layers start with mixed state? +local function ToggleExportAsSprite() + for _, layer in ipairs(app.range.layers) do + toggleExportAsSpriteLayer(layer) + end +end + local export = { ExportSpritesheetAdvanced = ExportSpritesheetAdvanced, ToggleIgnore = ToggleIgnore, diff --git a/abase-layer.lua b/abase-layer.lua index 3fe94e4..de89fa2 100644 --- a/abase-layer.lua +++ b/abase-layer.lua @@ -1,4 +1,4 @@ --- Functions for modifying a sprite +-- Functions for modifying a sprite's layers based on configuration flags -- Deletes any layers with the 'ignored' property. local function DeleteLayers(spr, layers) diff --git a/advanced-spritesheet-export.lua b/advanced-spritesheet-export.lua index 3cc93fa..086c087 100644 --- a/advanced-spritesheet-export.lua +++ b/advanced-spritesheet-export.lua @@ -3,91 +3,85 @@ extKey = "annabunches/abase" -- this must come before we require 'abase-commands local cmd = require "abase-commands" local listeners = require "abase-listeners" +function IsLayerSelectionMergable() + for _, layer in ipairs(app.range.layers) do + if layer.isGroup then return true end + end + return false +end + function init(plugin) - plugin:newCommand{ - id="ABASEExportSpritesheetAdvanced", - title="Export Spritesheet (Advanced)", - group="file_export_1", - onclick=function() - cmd.ExportSpritesheetAdvanced() - end, - onenabled=function() - return app.activeSprite ~= nil - end - } + -- New menu UI elements + plugin:newMenuSeparator{ + group="layer_popup_merge" + } - plugin:newMenuSeparator{ - group="layer_popup_merge" - } + plugin:newMenuSeparator{ + group="layer_merge" + } - plugin:newMenuSeparator{ - group="layer_merge" - } + plugin:newMenuGroup{ + id="abase_layer_settings", + title="Advanced Export", + group="layer_merge", + } - plugin:newMenuGroup{ - id="abase_layer_settings", - title="Advanced Export", - group="layer_merge", - } + plugin:newMenuGroup{ + id="abase_layer_settings_popup", + title="Advanced Export", + group="layer_popup_merge", + } - plugin:newMenuGroup{ - id="abase_layer_settings_popup", - title="Advanced Export", - group="layer_popup_merge", - } + -- Menu plumbing for export command + plugin:newCommand{ + id="ABASEExportSpritesheetAdvanced", + title="Export Spritesheet (Advanced)", + group="file_export_1", + onclick=cmd.ExportSpritesheetAdvanced, + onenabled=function() + return app.activeSprite ~= nil + end, + } - plugin:newCommand{ - id="ABASEToggleIgnoreLayer", - title="Toggle Ignore", - group="abase_layer_settings", - onclick=function() - cmd.ToggleIgnore() - end - } + -- Menu plumbing for ToggleIgnore + plugin:newCommand{ + id="ABASEToggleIgnoreLayer", + title="Toggle Ignore", + group="abase_layer_settings", + onclick=cmd.ToggleIgnore, + } - plugin:newCommand{ - id="ABASEToggleIgnoreLayerPopup", - title="Toggle Ignore", - group="abase_layer_settings_popup", - onclick=function() - cmd.ToggleIgnore() - end - } + plugin:newCommand{ + id="ABASEToggleIgnoreLayerPopup", + title="Toggle Ignore", + group="abase_layer_settings_popup", + onclick=cmd.ToggleIgnore, + } - plugin:newCommand{ - id="ABASEToggleExportAsSprite", - title="Toggle Merge Group", - group="abase_layer_settings", - onclick=function() - if app.layer.isGroup then - cmd.ToggleExportAsSprite() - end - end, - onenabled=function() - return app.layer.isGroup - end - } + -- Menu plumbing for ToggleExportAsSprite + plugin:newCommand{ + id="ABASEToggleExportAsSprite", + title="Toggle Merge Group", + group="abase_layer_settings", + onclick=cmd.ToggleExportAsSprite, + onenabled=IsLayerSelectionMergable, + } - plugin:newCommand{ - id="ABASEToggleExportAsSpritePopup", - title="Toggle Merge Group", - group="abase_layer_settings_popup", - onclick=function() - if app.layer.isGroup then - cmd.ToggleExportAsSprite() - end - end, - onenabled=function() - return app.layer.isGroup - end - } + plugin:newCommand{ + id="ABASEToggleExportAsSpritePopup", + title="Toggle Merge Group", + group="abase_layer_settings_popup", + onclick=cmd.ToggleExportAsSprite, + onenabled=IsLayerSelectionMergable, + } - app.events:on( - "aftercommand", - function(ev) - if (ev.name == "NewLayer") then - listeners.RecolorLayers() - end - end - ) + -- Event hooks + app.events:on( + "aftercommand", + function(ev) + if (ev.name == "NewLayer") then + listeners.RecolorLayers() + end + end + ) end \ No newline at end of file diff --git a/package.json b/package.json index 8b7177d..49ac20c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "advanced-spritesheets", "displayName": "Advanced Spritesheets", "description": "Improved spritesheet export functionality for Aseprite.", - "version": "0.0.6", + "version": "0.0.11", "author": { "name": "Anna Wiggins", "email": "annabunches@gmail.com", "url": "https://annabunches.net" }, diff --git a/readme.md b/readme.md index 80488d6..63f061d 100644 --- a/readme.md +++ b/readme.md @@ -10,6 +10,7 @@ To install, go to Aseprite's Settings -> Extensions -> Add Extension, and select * Choose which layers to export, regardless of visibility. * Export groups as a single sprite. +* Configure layer settings via Layer menu, right click menu, or keyboard shortcut. ## Usage