Large refactor and code cleanup.
This commit is contained in:
parent
2378c40afd
commit
0772b756fd
|
@ -1,3 +1,7 @@
|
||||||
|
-- functions for modifying a layer's color
|
||||||
|
|
||||||
|
local p = require "abase-properties"
|
||||||
|
|
||||||
local BASE_COLOR = Color {
|
local BASE_COLOR = Color {
|
||||||
r = 0,
|
r = 0,
|
||||||
g = 0,
|
g = 0,
|
||||||
|
@ -27,31 +31,24 @@ local MERGE_SUBCOLOR = Color {
|
||||||
|
|
||||||
local function safeSetColor(layer, color)
|
local function safeSetColor(layer, color)
|
||||||
pixelValue = layer.color.rgbaPixel
|
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
|
if (pixelValue ~= BASE_COLOR.rgbaPixel and
|
||||||
pixelValue ~= IGNORE_COLOR.rgbaPixel and
|
pixelValue ~= IGNORE_COLOR.rgbaPixel and
|
||||||
pixelValue ~= IGNORE_SUBCOLOR.rgbaPixel and
|
pixelValue ~= IGNORE_SUBCOLOR.rgbaPixel and
|
||||||
pixelValue ~= MERGE_COLOR.rgbaPixel and
|
pixelValue ~= MERGE_COLOR.rgbaPixel and
|
||||||
pixelValue ~= MERGE_SUBCOLOR.rgbaPixel) then
|
pixelValue ~= MERGE_SUBCOLOR.rgbaPixel) then
|
||||||
--[[ print("DEBUG: not setting color")
|
return
|
||||||
]] return
|
|
||||||
end
|
end
|
||||||
layer.color = color
|
layer.color = color
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set the color of a layer and its sublayers based on the extension properties
|
-- set the color of a layer and its sublayers based on the extension properties
|
||||||
local function SetColor(layer, subColor)
|
local function SetColor(layer, subColor)
|
||||||
if (layer.properties(extKey).ignored) then
|
if p.IsIgnored(layer) then
|
||||||
safeSetColor(layer, IGNORE_COLOR)
|
safeSetColor(layer, IGNORE_COLOR)
|
||||||
subColor = IGNORE_SUBCOLOR
|
subColor = IGNORE_SUBCOLOR
|
||||||
elseif subColor == IGNORE_SUBCOLOR then
|
elseif subColor == IGNORE_SUBCOLOR then
|
||||||
safeSetColor(layer, subColor)
|
safeSetColor(layer, subColor)
|
||||||
elseif (layer.properties(extKey).exportedAsSprite) then
|
elseif p.IsMerged(layer) then
|
||||||
safeSetColor(layer, MERGE_COLOR)
|
safeSetColor(layer, MERGE_COLOR)
|
||||||
subColor = MERGE_SUBCOLOR
|
subColor = MERGE_SUBCOLOR
|
||||||
elseif subColor == MERGE_SUBCOLOR then
|
elseif subColor == MERGE_SUBCOLOR then
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
-- New commands to be executed via Aseprite menus / keyboard shortcuts
|
-- New commands to be executed via Aseprite menus / keyboard shortcuts
|
||||||
local layerUtils = require "abase-layer"
|
local l = require "abase-layer"
|
||||||
local colorUtils = require "abase-color"
|
local c = require "abase-color"
|
||||||
|
local p = require "abase-properties"
|
||||||
|
|
||||||
local function ExportSpritesheetAdvanced()
|
local function ExportSpritesheetAdvanced()
|
||||||
if not app.sprite then
|
if not app.sprite then
|
||||||
|
@ -9,9 +10,9 @@ local function ExportSpritesheetAdvanced()
|
||||||
|
|
||||||
local spr = Sprite(app.sprite)
|
local spr = Sprite(app.sprite)
|
||||||
|
|
||||||
layerUtils.DeleteLayers(spr, spr.layers)
|
l.DeleteLayers(spr, spr.layers)
|
||||||
layerUtils.FlattenLayers(spr.layers)
|
l.FlattenLayers(spr.layers)
|
||||||
layerUtils.RevealLayers(spr.layers)
|
l.RevealLayers(spr.layers)
|
||||||
|
|
||||||
app.command.ExportSpriteSheet {
|
app.command.ExportSpriteSheet {
|
||||||
splitLayers = true
|
splitLayers = true
|
||||||
|
@ -20,39 +21,35 @@ local function ExportSpritesheetAdvanced()
|
||||||
spr:close()
|
spr:close()
|
||||||
end
|
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
|
-- Toggle ignore for all selected layers
|
||||||
-- TODO: should this behavior change when selected layers start with mixed state?
|
|
||||||
local function ToggleIgnore()
|
local function ToggleIgnore()
|
||||||
|
-- Determine whether we are setting or clearing the flag
|
||||||
|
local ignore = false
|
||||||
for _, layer in ipairs(app.range.layers) do
|
for _, layer in ipairs(app.range.layers) do
|
||||||
toggleIgnoreLayer(layer)
|
if not p.IsIgnored(layer) then
|
||||||
|
ignore = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local function toggleExportAsSpriteLayer(layer)
|
for _, layer in ipairs(app.range.layers) do
|
||||||
if not layer.isGroup then return end
|
p.SetIgnored(layer, ignore)
|
||||||
|
c.SetColorFromRoot(layer)
|
||||||
if (layer.properties(extKey).exportedAsSprite) then
|
|
||||||
layer.properties(extKey).exportedAsSprite = false
|
|
||||||
else
|
|
||||||
layer.properties(extKey).exportedAsSprite = true
|
|
||||||
end
|
end
|
||||||
colorUtils.SetColorFromRoot(layer)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Toggle Merge on Export for all selected group layers
|
-- Toggle Merge on Export for all selected group layers
|
||||||
-- TODO: should this behavior change when selected layers start with mixed state?
|
|
||||||
local function ToggleExportAsSprite()
|
local function ToggleExportAsSprite()
|
||||||
|
-- Determine whether we are setting or clearing the flag
|
||||||
|
local merge = false
|
||||||
for _, layer in ipairs(app.range.layers) do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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.
|
-- Deletes any layers with the 'ignored' property.
|
||||||
local function DeleteLayers(spr, layers)
|
local function DeleteLayers(spr, layers)
|
||||||
for _, layer in ipairs(layers) do
|
for _, layer in ipairs(layers) do
|
||||||
if layer.properties(extKey).ignored then
|
if p.IsIgnored(layer) then
|
||||||
spr:deleteLayer(layer)
|
spr:deleteLayer(layer)
|
||||||
elseif layer.isGroup then
|
elseif layer.isGroup then
|
||||||
DeleteLayers(spr, layer.layers)
|
DeleteLayers(spr, layer.layers)
|
||||||
|
@ -19,7 +21,7 @@ local function FlattenLayers(layers)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
if layer.properties(extKey).exportedAsSprite then
|
if p.IsMerged(layer) then
|
||||||
app.range.layers = {layer}
|
app.range.layers = {layer}
|
||||||
app.command.FlattenLayers(false)
|
app.command.FlattenLayers(false)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
local colorUtils = require "abase-color"
|
local c = require "abase-color"
|
||||||
|
|
||||||
-- recolors all layers in the current sprite
|
-- recolors all layers in the current sprite
|
||||||
local function RecolorLayers()
|
local function RecolorLayers()
|
||||||
for i, layer in ipairs(app.sprite.layers) do
|
for i, layer in ipairs(app.sprite.layers) do
|
||||||
colorUtils.SetColor(layer)
|
c.SetColor(layer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
27
abase-properties.lua
Normal file
27
abase-properties.lua
Normal file
|
@ -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
|
|
@ -1,5 +1,3 @@
|
||||||
extKey = "annabunches/abase" -- this must come before we require 'abase-commands'
|
|
||||||
|
|
||||||
local cmd = require "abase-commands"
|
local cmd = require "abase-commands"
|
||||||
local listeners = require "abase-listeners"
|
local listeners = require "abase-listeners"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "advanced-spritesheets",
|
"name": "advanced-spritesheets",
|
||||||
"displayName": "Advanced Spritesheets",
|
"displayName": "Advanced Spritesheets",
|
||||||
"description": "Improved spritesheet export functionality for Aseprite.",
|
"description": "Improved spritesheet export functionality for Aseprite.",
|
||||||
"version": "0.0.11",
|
"version": "0.0.12",
|
||||||
"author": { "name": "Anna Wiggins",
|
"author": { "name": "Anna Wiggins",
|
||||||
"email": "annabunches@gmail.com",
|
"email": "annabunches@gmail.com",
|
||||||
"url": "https://annabunches.net" },
|
"url": "https://annabunches.net" },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user