Fix exporting a Sprite Sheet with Group name has different functionality between CLI and Scripting (fix #4456) (#4475)

Before this fix, the lua command:
app.command.ExportSpriteSheet
could not process a layer within a group when the layer name
was expressed using the layer hierarchy path, for example:
layer = "Group1/Layer1"
This commit is contained in:
Gaspar Capello 2024-09-03 20:20:36 -03:00 committed by GitHub
parent 9429d915ae
commit c8f018f2f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 53 additions and 18 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -23,6 +23,7 @@
#include "app/filename_formatter.h"
#include "app/restore_visible_layers.h"
#include "app/ui_context.h"
#include "app/util/layer_utils.h"
#include "base/convert_to.h"
#include "base/fs.h"
#include "base/split_string.h"
@ -43,17 +44,6 @@ namespace app {
namespace {
std::string get_layer_path(const Layer* layer)
{
std::string path;
for (; layer != layer->sprite()->root(); layer=layer->parent()) {
if (!path.empty())
path.insert(0, "/");
path.insert(0, layer->name());
}
return path;
}
bool match_path(const std::string& filter,
const std::string& layer_path,
const bool exclude)

View File

@ -32,6 +32,7 @@
#include "app/ui/optional_alert.h"
#include "app/ui/status_bar.h"
#include "app/ui/timeline/timeline.h"
#include "app/util/layer_utils.h"
#include "base/convert_to.h"
#include "base/fs.h"
#include "base/string.h"
@ -148,6 +149,17 @@ void destroy_doc(Context* ctx, Doc* doc)
}
}
void insert_layers_to_selected_layers(Layer* layer, SelectedLayers& selectedLayers)
{
if (layer->isGroup()) {
auto children = static_cast<LayerGroup*>(layer)->layers();
for (auto child : children)
insert_layers_to_selected_layers(child, selectedLayers);
}
else
selectedLayers.insert(layer);
}
Doc* generate_sprite_sheet_from_params(
DocExporter& exporter,
Context* ctx,
@ -206,11 +218,14 @@ Doc* generate_sprite_sheet_from_params(
if (layerName != kSelectedLayers) {
// TODO add a getLayerByName
int i = sprite->allLayersCount();
for (const Layer* layer : sprite->allLayers()) {
for (Layer* layer : sprite->allLayers()) {
i--;
if (layer->name() == layerName && (layerIndex == -1 ||
layerIndex == i)) {
selLayers.insert(const_cast<Layer*>(layer));
if (get_layer_path(layer) == layerName &&
(layerIndex == -1 || layerIndex == i)) {
if (layer->isGroup())
insert_layers_to_selected_layers(layer, selLayers);
else
selLayers.insert(layer);
break;
}
}

View File

@ -69,4 +69,15 @@ bool layer_is_locked(Editor* editor)
return false;
}
std::string get_layer_path(const Layer* layer)
{
std::string path;
for (; layer != layer->sprite()->root(); layer=layer->parent()) {
if (!path.empty())
path.insert(0, "/");
path.insert(0, layer->name());
}
return path;
}
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -8,6 +8,8 @@
#define APP_LAYER_UTILS_H_INCLUDED
#pragma once
#include <string>
namespace doc {
class Layer;
}
@ -27,6 +29,8 @@ namespace app {
// also, it sends a tip to the user 'Layer ... is locked'
bool layer_is_locked(Editor* editor);
std::string get_layer_path(const doc::Layer* layer);
} // namespace app
#endif

View File

@ -1,4 +1,4 @@
-- Copyright (C) 2019-2023 Igara Studio S.A.
-- Copyright (C) 2019-2024 Igara Studio S.A.
-- Copyright (C) 2018 David Capello
--
-- This file is released under the terms of the MIT license.
@ -99,6 +99,21 @@ do -- ExportSpriteSheet
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
})
local s = Sprite{ fromFile="sprites/groups3abc.aseprite" }
local c = app.pixelColor.rgba(75, 105, 47)
app.command.ExportSpriteSheet {
type=SpriteSheetType.ROWS,
textureFilename="_test_export_spritesheet4.png",
layer="b/b",
trim=true,
}
local i = Image{ fromFile="_test_export_spritesheet4.png" }
expect_img(i, {
c,c,0,
c,c,0,
c,c,c,
})
end
do -- NewLayer/RemoveLayer