First attempt at re-calculating all colors in a group hierarchy when one color changes, and also protecting user-defined colors.
This commit is contained in:
parent
0ed105d355
commit
4f0f5dc8ad
|
@ -8,9 +8,9 @@ local function ExportSpritesheetAdvanced()
|
||||||
|
|
||||||
local spr = Sprite(app.sprite)
|
local spr = Sprite(app.sprite)
|
||||||
|
|
||||||
sprt.deleteLayers(spr, spr.layers)
|
sprt.DeleteLayers(spr, spr.layers)
|
||||||
sprt.flattenLayers(spr.layers)
|
sprt.FlattenLayers(spr.layers)
|
||||||
sprt.revealLayers(spr.layers)
|
sprt.RevealLayers(spr.layers)
|
||||||
|
|
||||||
app.command.ExportSpriteSheet {
|
app.command.ExportSpriteSheet {
|
||||||
splitLayers = true
|
splitLayers = true
|
||||||
|
@ -26,7 +26,7 @@ local function ToggleIgnore()
|
||||||
else
|
else
|
||||||
layer.properties(extKey).ignored = true
|
layer.properties(extKey).ignored = true
|
||||||
end
|
end
|
||||||
sprt.setColor(layer)
|
sprt.SetColorFromRoot(layer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ToggleExportAsSprite()
|
local function ToggleExportAsSprite()
|
||||||
|
@ -36,7 +36,7 @@ local function ToggleExportAsSprite()
|
||||||
else
|
else
|
||||||
layer.properties(extKey).exportedAsSprite = true
|
layer.properties(extKey).exportedAsSprite = true
|
||||||
end
|
end
|
||||||
sprt.setColor(layer)
|
sprt.SetColorFromRoot(layer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local export = {
|
local export = {
|
||||||
|
|
|
@ -4,40 +4,44 @@ local BASE_COLOR = Color {
|
||||||
r = 0,
|
r = 0,
|
||||||
g = 0,
|
g = 0,
|
||||||
b = 0,
|
b = 0,
|
||||||
a = 0
|
a = 0,
|
||||||
}
|
}
|
||||||
local IGNORE_COLOR = Color {
|
local IGNORE_COLOR = Color {
|
||||||
gray = 100
|
gray = 100,
|
||||||
|
alpha = 254,
|
||||||
}
|
}
|
||||||
local IGNORE_SUBCOLOR = Color {
|
local IGNORE_SUBCOLOR = Color {
|
||||||
gray = 150
|
gray = 150,
|
||||||
|
alpha = 254,
|
||||||
}
|
}
|
||||||
local MERGE_COLOR = Color {
|
local MERGE_COLOR = Color {
|
||||||
r = 200,
|
r = 200,
|
||||||
g = 200,
|
g = 200,
|
||||||
b = 0
|
b = 0,
|
||||||
|
a = 254,
|
||||||
}
|
}
|
||||||
local MERGE_SUBCOLOR = Color {
|
local MERGE_SUBCOLOR = Color {
|
||||||
r = 200,
|
r = 200,
|
||||||
g = 200,
|
g = 200,
|
||||||
b = 128
|
b = 128,
|
||||||
|
a = 254,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 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 i, layer in ipairs(layers) do
|
for _, layer in ipairs(layers) do
|
||||||
if layer.properties(extKey).ignored then
|
if layer.properties(extKey).ignored then
|
||||||
spr:deleteLayer(layer)
|
spr:deleteLayer(layer)
|
||||||
elseif layer.isGroup then
|
elseif layer.isGroup then
|
||||||
deleteLayers(spr, layer.layers)
|
DeleteLayers(spr, layer.layers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Flattens any layers that have the 'exportedAsSprite' property.
|
-- Flattens any layers that have the 'exportedAsSprite' property.
|
||||||
-- Should be called after deleteLayers.
|
-- Should be called after deleteLayers.
|
||||||
local function flattenLayers(layers)
|
local function FlattenLayers(layers)
|
||||||
for i, layer in ipairs(layers) do
|
for _, layer in ipairs(layers) do
|
||||||
if not layer.isGroup then
|
if not layer.isGroup then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
@ -47,7 +51,7 @@ local function flattenLayers(layers)
|
||||||
app.command.FlattenLayers(false)
|
app.command.FlattenLayers(false)
|
||||||
else
|
else
|
||||||
-- recurse
|
-- recurse
|
||||||
flattenLayers(layer.layers)
|
FlattenLayers(layer.layers)
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
::continue::
|
||||||
|
@ -56,10 +60,10 @@ end
|
||||||
|
|
||||||
-- Makes all layers visible.
|
-- Makes all layers visible.
|
||||||
-- This should be called after deleteLayers and flattenLayers
|
-- This should be called after deleteLayers and flattenLayers
|
||||||
local function revealLayers(layers)
|
local function RevealLayers(layers)
|
||||||
for i, layer in ipairs(layers) do
|
for _, layer in ipairs(layers) do
|
||||||
if layer.isGroup then
|
if layer.isGroup then
|
||||||
revealLayers(layer.layers)
|
RevealLayers(layer.layers)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not layer.isVisible then
|
if not layer.isVisible then
|
||||||
|
@ -68,35 +72,60 @@ local function revealLayers(layers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set the color of a layer and its sublayers
|
local function safeSetColor(layer, color)
|
||||||
local function setColor(layer, subColor)
|
pixelValue = layer.color.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
|
||||||
|
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 (layer.properties(extKey).ignored) then
|
||||||
layer.color = IGNORE_COLOR
|
safeSetColor(layer, IGNORE_COLOR)
|
||||||
subColor = IGNORE_SUBCOLOR
|
subColor = IGNORE_SUBCOLOR
|
||||||
elseif subColor == IGNORE_SUBCOLOR then
|
elseif subColor == IGNORE_SUBCOLOR then
|
||||||
layer.color = subColor
|
safeSetColor(layer, subColor)
|
||||||
elseif (layer.properties(extKey).exportedAsSprite) then
|
elseif (layer.properties(extKey).exportedAsSprite) then
|
||||||
layer.color = MERGE_COLOR
|
safeSetColor(layer, MERGE_COLOR)
|
||||||
subColor = MERGE_SUBCOLOR
|
subColor = MERGE_SUBCOLOR
|
||||||
elseif subColor == MERGE_SUBCOLOR then
|
elseif subColor == MERGE_SUBCOLOR then
|
||||||
layer.color = subColor
|
safeSetColor(layer, subColor)
|
||||||
else
|
else
|
||||||
layer.color = BASE_COLOR
|
safeSetColor(layer, BASE_COLOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (layer.isGroup) then
|
if (layer.isGroup) then
|
||||||
for i, sublayer in ipairs(layer.layers) do
|
for i, sublayer in ipairs(layer.layers) do
|
||||||
setColor(sublayer, subColor)
|
SetColor(sublayer, subColor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Find the root of the layer stack, then set colors appropriately
|
||||||
|
-- for all children
|
||||||
|
local function SetColorFromRoot(layer)
|
||||||
|
-- The standard Lua `if table["field"] == nil` throws an error in Aseprite.
|
||||||
|
-- So we just check for the parent Layer being equal to the sprite.
|
||||||
|
if layer.parent == layer.sprite then
|
||||||
|
SetColor(layer)
|
||||||
|
else
|
||||||
|
SetColorFromRoot(layer.parent)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local export = {
|
local export = {
|
||||||
deleteLayers = deleteLayers,
|
DeleteLayers = DeleteLayers,
|
||||||
flattenLayers = flattenLayers,
|
FlattenLayers = FlattenLayers,
|
||||||
revealLayers = revealLayers,
|
RevealLayers = RevealLayers,
|
||||||
setColor = setColor,
|
SetColor = SetColor,
|
||||||
|
SetColorFromRoot = SetColorFromRoot,
|
||||||
}
|
}
|
||||||
return export
|
return export
|
|
@ -19,8 +19,9 @@ To install, go to Aseprite's Settings -> Extensions -> Add Extension, and select
|
||||||
|
|
||||||
## Additional Notes
|
## Additional Notes
|
||||||
|
|
||||||
* Toggling the advanced export settings on a layer will modify the layer colors. If you are using layer colors for other purposes, this extension will not work well for you. (This may be configurable in a future update)
|
|
||||||
* Ignored layers always take precedence over merging; if a sublayer in a group is ignored, it will not be merged into the final sprite.
|
* Ignored layers always take precedence over merging; if a sublayer in a group is ignored, it will not be merged into the final sprite.
|
||||||
|
* Toggling the advanced export settings on a layer will modify the layer colors. The extension will attempt to detect and preserve user-colored layers. If you happen to use one of the exact colors we have chosen, this will fail. We have chosen odd alpha values to reduce the likelihood of a false negative, but if you are using layer colors extensively, this extension may not work well for you.
|
||||||
|
* To force a layer's color to be controlled by the extension, simply reset the layer's color to all 0 values. (red, green, blue, and alpha should all be 0) You may need to toggle the export settings of a parent layer or create a new layer before the changes take effect.
|
||||||
|
|
||||||
|
|
||||||
## Copyright Notice
|
## Copyright Notice
|
||||||
|
|
Loading…
Reference in New Issue
Block a user