diff --git a/abase-color.lua b/abase-color.lua index b6cb133..9e2f697 100644 --- a/abase-color.lua +++ b/abase-color.lua @@ -1,3 +1,7 @@ +-- functions for modifying a layer's color + +local p = require "abase-properties" + local BASE_COLOR = Color { r = 0, g = 0, @@ -27,31 +31,24 @@ local MERGE_SUBCOLOR = Color { local function safeSetColor(layer, color) pixelValue = layer.color.rgbaPixel ---[[ print("safeSetColor: " .. pixelValue) - print(BASE_COLOR.rgbaPixel) - print(IGNORE_COLOR.rgbaPixel) - print(IGNORE_SUBCOLOR.rgbaPixel) - print(MERGE_COLOR.rgbaPixel) - print(MERGE_SUBCOLOR.rgbaPixel) ]] if (pixelValue ~= BASE_COLOR.rgbaPixel and pixelValue ~= IGNORE_COLOR.rgbaPixel and pixelValue ~= IGNORE_SUBCOLOR.rgbaPixel and pixelValue ~= MERGE_COLOR.rgbaPixel and pixelValue ~= MERGE_SUBCOLOR.rgbaPixel) then ---[[ print("DEBUG: not setting color") - ]] return + return end layer.color = color end -- set the color of a layer and its sublayers based on the extension properties local function SetColor(layer, subColor) - if (layer.properties(extKey).ignored) then + if p.IsIgnored(layer) then safeSetColor(layer, IGNORE_COLOR) subColor = IGNORE_SUBCOLOR elseif subColor == IGNORE_SUBCOLOR then safeSetColor(layer, subColor) - elseif (layer.properties(extKey).exportedAsSprite) then + elseif p.IsMerged(layer) then safeSetColor(layer, MERGE_COLOR) subColor = MERGE_SUBCOLOR elseif subColor == MERGE_SUBCOLOR then diff --git a/abase-commands.lua b/abase-commands.lua index 9556281..61236eb 100644 --- a/abase-commands.lua +++ b/abase-commands.lua @@ -1,6 +1,7 @@ -- New commands to be executed via Aseprite menus / keyboard shortcuts -local layerUtils = require "abase-layer" -local colorUtils = require "abase-color" +local l = require "abase-layer" +local c = require "abase-color" +local p = require "abase-properties" local function ExportSpritesheetAdvanced() if not app.sprite then @@ -9,9 +10,9 @@ local function ExportSpritesheetAdvanced() local spr = Sprite(app.sprite) - layerUtils.DeleteLayers(spr, spr.layers) - layerUtils.FlattenLayers(spr.layers) - layerUtils.RevealLayers(spr.layers) + l.DeleteLayers(spr, spr.layers) + l.FlattenLayers(spr.layers) + l.RevealLayers(spr.layers) app.command.ExportSpriteSheet { splitLayers = true @@ -20,39 +21,35 @@ local function ExportSpritesheetAdvanced() spr:close() end -local function toggleIgnoreLayer(layer) - if (layer.properties(extKey).ignored) then - layer.properties(extKey).ignored = false - else - layer.properties(extKey).ignored = true - end - colorUtils.SetColorFromRoot(layer) -end - -- Toggle ignore for all selected layers --- TODO: should this behavior change when selected layers start with mixed state? local function ToggleIgnore() + -- Determine whether we are setting or clearing the flag + local ignore = false for _, layer in ipairs(app.range.layers) do - toggleIgnoreLayer(layer) + if not p.IsIgnored(layer) then + ignore = true + end 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 - layer.properties(extKey).exportedAsSprite = true + for _, layer in ipairs(app.range.layers) do + p.SetIgnored(layer, ignore) + c.SetColorFromRoot(layer) end - 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() + -- Determine whether we are setting or clearing the flag + local merge = false for _, layer in ipairs(app.range.layers) do - toggleExportAsSpriteLayer(layer) + if layer.isGroup and not p.IsMerged(layer) then + merge = true + end + end + + for _, layer in ipairs(app.range.layers) do + p.SetMerged(layer, merge) + c.SetColorFromRoot(layer) end end diff --git a/abase-layer.lua b/abase-layer.lua index de89fa2..09acb12 100644 --- a/abase-layer.lua +++ b/abase-layer.lua @@ -1,9 +1,11 @@ --- Functions for modifying a sprite's layers based on configuration flags +-- Functions for modifying layers recursively based on configuration flags + +local p = require "abase-properties" -- Deletes any layers with the 'ignored' property. local function DeleteLayers(spr, layers) for _, layer in ipairs(layers) do - if layer.properties(extKey).ignored then + if p.IsIgnored(layer) then spr:deleteLayer(layer) elseif layer.isGroup then DeleteLayers(spr, layer.layers) @@ -19,7 +21,7 @@ local function FlattenLayers(layers) goto continue end - if layer.properties(extKey).exportedAsSprite then + if p.IsMerged(layer) then app.range.layers = {layer} app.command.FlattenLayers(false) else diff --git a/abase-listeners.lua b/abase-listeners.lua index 9631676..e4b6733 100644 --- a/abase-listeners.lua +++ b/abase-listeners.lua @@ -1,9 +1,9 @@ -local colorUtils = require "abase-color" +local c = require "abase-color" -- recolors all layers in the current sprite local function RecolorLayers() for i, layer in ipairs(app.sprite.layers) do - colorUtils.SetColor(layer) + c.SetColor(layer) end end diff --git a/abase-properties.lua b/abase-properties.lua new file mode 100644 index 0000000..87d994f --- /dev/null +++ b/abase-properties.lua @@ -0,0 +1,27 @@ +-- functions for retrieving and modifying layer properties +extKey = "annabunches/abase" + +local function IsIgnored(layer) + return layer.properties(extKey).ignored +end + +local function IsMerged(layer) + return layer.isGroup and layer.properties(extKey).merged +end + +local function SetIgnored(layer, ignore) + layer.properties(extKey).ignored = ignore +end + +local function SetMerged(layer, merge) + if not layer.isGroup then return end + layer.properties(extKey).merged = merge +end + +local export = { + IsIgnored = IsIgnored, + IsMerged = IsMerged, + SetIgnored = SetIgnored, + SetMerged = SetMerged, +} +return export \ No newline at end of file diff --git a/advanced-spritesheet-export.lua b/advanced-spritesheet-export.lua index 086c087..1de71bd 100644 --- a/advanced-spritesheet-export.lua +++ b/advanced-spritesheet-export.lua @@ -1,5 +1,3 @@ -extKey = "annabunches/abase" -- this must come before we require 'abase-commands' - local cmd = require "abase-commands" local listeners = require "abase-listeners" diff --git a/package.json b/package.json index 49ac20c..4aa513d 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.11", + "version": "0.0.12", "author": { "name": "Anna Wiggins", "email": "annabunches@gmail.com", "url": "https://annabunches.net" },