Fix wrong json export with linked, trimmed cels (fix #2600)

Before this fix, the json file associated with the exported sprite sheet had wrong 'spriteSourceSize' coordinates in particular cases like this:
- Linked cels
- Export Sprite Sheet options: TrimmedCels + Merge Duplicates + SplitLayers checked
This commit is contained in:
Gaspar Capello 2022-03-16 16:47:15 -03:00 committed by David Capello
parent d429797359
commit b70a29269d

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2022 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
@ -390,18 +390,13 @@ public:
return; return;
token.set_progress(0.2f + 0.2f * i / samples.size()); token.set_progress(0.2f + 0.2f * i / samples.size());
if (sample.isLinked()) {
++i;
continue;
}
if (sample.isEmpty()) { if (sample.isEmpty()) {
sample.setInTextureBounds(gfx::Rect(0, 0, 0, 0)); sample.setInTextureBounds(gfx::Rect(0, 0, 0, 0));
++i; ++i;
continue; continue;
} }
if (m_mergeDups) { if (m_mergeDups || sample.isLinked()) {
doc::ImageBufferPtr sampleBuf = std::make_shared<doc::ImageBuffer>(); doc::ImageBufferPtr sampleBuf = std::make_shared<doc::ImageBuffer>();
doc::ImageRef sampleRender(sample.createRender(sampleBuf)); doc::ImageRef sampleRender(sample.createRender(sampleBuf));
auto it = duplicates.find(sampleRender); auto it = duplicates.find(sampleRender);
@ -527,8 +522,7 @@ public:
token.set_progress_range(0.2f, 0.3f); token.set_progress_range(0.2f, 0.3f);
token.set_progress(float(i) / samples.size()); token.set_progress(float(i) / samples.size());
if (sample.isLinked() || if (sample.isEmpty()) {
sample.isEmpty()) {
++i; ++i;
continue; continue;
} }
@ -912,6 +906,7 @@ void DocExporter::captureSamples(Samples& samples,
} }
// Re-use linked samples // Re-use linked samples
bool alreadyTrimmed = false;
if (link && m_mergeDuplicates) { if (link && m_mergeDuplicates) {
for (const Sample& other : samples) { for (const Sample& other : samples) {
if (token.canceled()) if (token.canceled())
@ -923,7 +918,9 @@ void DocExporter::captureSamples(Samples& samples,
ASSERT(!other.isLinked()); ASSERT(!other.isLinked());
sample.setLinked(); sample.setLinked();
sample.setTrimmedBounds(other.trimmedBounds());
sample.setSharedBounds(other.sharedBounds()); sample.setSharedBounds(other.sharedBounds());
alreadyTrimmed = true;
done = true; done = true;
break; break;
} }
@ -933,7 +930,6 @@ void DocExporter::captureSamples(Samples& samples,
ASSERT(done || (!done && tag)); ASSERT(done || (!done && tag));
} }
bool alreadyTrimmed = false;
if (!done && (m_ignoreEmptyCels || m_trimCels)) { if (!done && (m_ignoreEmptyCels || m_trimCels)) {
// Ignore empty cels // Ignore empty cels
if (layer && layer->isImage() && !cel && m_ignoreEmptyCels) if (layer && layer->isImage() && !cel && m_ignoreEmptyCels)