mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 05:22:23 +00:00
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:
parent
9429d915ae
commit
c8f018f2f1
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -23,6 +23,7 @@
|
|||||||
#include "app/filename_formatter.h"
|
#include "app/filename_formatter.h"
|
||||||
#include "app/restore_visible_layers.h"
|
#include "app/restore_visible_layers.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
|
#include "app/util/layer_utils.h"
|
||||||
#include "base/convert_to.h"
|
#include "base/convert_to.h"
|
||||||
#include "base/fs.h"
|
#include "base/fs.h"
|
||||||
#include "base/split_string.h"
|
#include "base/split_string.h"
|
||||||
@ -43,17 +44,6 @@ namespace app {
|
|||||||
|
|
||||||
namespace {
|
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,
|
bool match_path(const std::string& filter,
|
||||||
const std::string& layer_path,
|
const std::string& layer_path,
|
||||||
const bool exclude)
|
const bool exclude)
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "app/ui/optional_alert.h"
|
#include "app/ui/optional_alert.h"
|
||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
#include "app/ui/timeline/timeline.h"
|
#include "app/ui/timeline/timeline.h"
|
||||||
|
#include "app/util/layer_utils.h"
|
||||||
#include "base/convert_to.h"
|
#include "base/convert_to.h"
|
||||||
#include "base/fs.h"
|
#include "base/fs.h"
|
||||||
#include "base/string.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(
|
Doc* generate_sprite_sheet_from_params(
|
||||||
DocExporter& exporter,
|
DocExporter& exporter,
|
||||||
Context* ctx,
|
Context* ctx,
|
||||||
@ -206,11 +218,14 @@ Doc* generate_sprite_sheet_from_params(
|
|||||||
if (layerName != kSelectedLayers) {
|
if (layerName != kSelectedLayers) {
|
||||||
// TODO add a getLayerByName
|
// TODO add a getLayerByName
|
||||||
int i = sprite->allLayersCount();
|
int i = sprite->allLayersCount();
|
||||||
for (const Layer* layer : sprite->allLayers()) {
|
for (Layer* layer : sprite->allLayers()) {
|
||||||
i--;
|
i--;
|
||||||
if (layer->name() == layerName && (layerIndex == -1 ||
|
if (get_layer_path(layer) == layerName &&
|
||||||
layerIndex == i)) {
|
(layerIndex == -1 || layerIndex == i)) {
|
||||||
selLayers.insert(const_cast<Layer*>(layer));
|
if (layer->isGroup())
|
||||||
|
insert_layers_to_selected_layers(layer, selLayers);
|
||||||
|
else
|
||||||
|
selLayers.insert(layer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,4 +69,15 @@ bool layer_is_locked(Editor* editor)
|
|||||||
return false;
|
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
|
} // namespace app
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2020 Igara Studio S.A.
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
@ -8,6 +8,8 @@
|
|||||||
#define APP_LAYER_UTILS_H_INCLUDED
|
#define APP_LAYER_UTILS_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Layer;
|
class Layer;
|
||||||
}
|
}
|
||||||
@ -27,6 +29,8 @@ namespace app {
|
|||||||
// also, it sends a tip to the user 'Layer ... is locked'
|
// also, it sends a tip to the user 'Layer ... is locked'
|
||||||
bool layer_is_locked(Editor* editor);
|
bool layer_is_locked(Editor* editor);
|
||||||
|
|
||||||
|
std::string get_layer_path(const doc::Layer* layer);
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
-- Copyright (C) 2018 David Capello
|
||||||
--
|
--
|
||||||
-- This file is released under the terms of the MIT license.
|
-- 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,
|
||||||
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
|
end
|
||||||
|
|
||||||
do -- NewLayer/RemoveLayer
|
do -- NewLayer/RemoveLayer
|
||||||
|
Loading…
Reference in New Issue
Block a user