diff --git a/src/app/cli/cli_processor.cpp b/src/app/cli/cli_processor.cpp index ffa25ae15..f4de2bc7e 100644 --- a/src/app/cli/cli_processor.cpp +++ b/src/app/cli/cli_processor.cpp @@ -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) diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp index 62d6f3326..334ba69d1 100644 --- a/src/app/commands/cmd_export_sprite_sheet.cpp +++ b/src/app/commands/cmd_export_sprite_sheet.cpp @@ -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(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)); + 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; } } diff --git a/src/app/util/layer_utils.cpp b/src/app/util/layer_utils.cpp index 003f65625..2a3d9ab42 100644 --- a/src/app/util/layer_utils.cpp +++ b/src/app/util/layer_utils.cpp @@ -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 diff --git a/src/app/util/layer_utils.h b/src/app/util/layer_utils.h index a281b87cf..996b25804 100644 --- a/src/app/util/layer_utils.h +++ b/src/app/util/layer_utils.h @@ -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 + 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 diff --git a/tests/scripts/app_command.lua b/tests/scripts/app_command.lua index 7e87f2e38..4f70e5d1e 100644 --- a/tests/scripts/app_command.lua +++ b/tests/scripts/app_command.lua @@ -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