Fix tags information when empty frames are removed (fix #1244)

This commit is contained in:
David Capello 2016-09-05 21:46:21 -03:00
parent 6e5d312bdf
commit 1c88af5689
2 changed files with 46 additions and 7 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -170,6 +170,7 @@ public:
void setInTextureBounds(const gfx::Rect& bounds) { m_bounds->setInTextureBounds(bounds); }
bool isDuplicated() const { return m_isDuplicated; }
bool isEmpty() const { return m_bounds->trimmedBounds().isEmpty(); }
SampleBoundsPtr sharedBounds() const { return m_bounds; }
void setSharedBounds(const SampleBoundsPtr& bounds) {
@ -235,6 +236,11 @@ public:
if (sample.isDuplicated())
continue;
if (sample.isEmpty()) {
sample.setInTextureBounds(gfx::Rect(0, 0, 0, 0));
continue;
}
const Sprite* sprite = sample.sprite();
const Layer* layer = sample.layer();
gfx::Size size = sample.requiredSize();
@ -312,7 +318,8 @@ public:
// TODO Add support for shape paddings
for (auto& sample : samples) {
if (sample.isDuplicated())
if (sample.isDuplicated() ||
sample.isEmpty())
continue;
pr.add(sample.requiredSize());
@ -530,7 +537,22 @@ void DocumentExporter::captureSamples(Samples& samples)
if (!algorithm::shrink_bounds(sampleRender, frameBounds, refColor)) {
// If shrink_bounds() returns false, it's because the whole
// image is transparent (equal to the mask color).
continue;
// Should we ignore this empty frame? (i.e. don't include
// the frame in the sprite sheet)
if (m_ignoreEmptyCels) {
for (FrameTag* tag : sprite->frameTags()) {
auto& delta = m_tagDelta[tag->id()];
if (frame < tag->fromFrame()) --delta.first;
if (frame <= tag->toFrame()) --delta.second;
}
continue;
}
// Create an empty entry for this completely trimmed frame
// anyway to get its duration in the list of frames.
sample.setTrimmedBounds(frameBounds = gfx::Rect(0, 0, 0, 0));
}
if (m_trimCels)
@ -552,6 +574,10 @@ Document* DocumentExporter::createEmptyTexture(const Samples& samples)
for (Samples::const_iterator
it = samples.begin(),
end = samples.end(); it != end; ++it) {
if (it->isDuplicated() ||
it->isEmpty())
continue;
// We try to render an indexed image. But if we find a sprite with
// two or more palettes, or two of the sprites have different
// palettes, we've to use RGB format.
@ -608,7 +634,8 @@ void DocumentExporter::renderTexture(const Samples& samples, Image* textureImage
textureImage->clear(0);
for (const auto& sample : samples) {
if (sample.isDuplicated())
if (sample.isDuplicated() ||
sample.isEmpty())
continue;
// Make the sprite compatible with the texture so the render()
@ -720,9 +747,13 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
else
os << ",";
std::pair<int, int> delta(0, 0);
if (!m_tagDelta.empty())
delta = m_tagDelta[tag->id()];
os << "\n { \"name\": \"" << escape_for_json(tag->name()) << "\","
<< " \"from\": " << tag->fromFrame() << ","
<< " \"to\": " << tag->toFrame() << ","
<< " \"from\": " << (tag->fromFrame()+delta.first) << ","
<< " \"to\": " << (tag->toFrame()+delta.second) << ","
<< " \"direction\": \"" << escape_for_json(convert_to_string(tag->aniDir())) << "\" }";
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -11,10 +11,13 @@
#include "app/sprite_sheet_type.h"
#include "base/disable_copying.h"
#include "doc/image_buffer.h"
#include "doc/object_id.h"
#include "gfx/fwd.h"
#include <iosfwd>
#include <map>
#include <string>
#include <utility>
#include <vector>
namespace doc {
@ -126,6 +129,11 @@ namespace app {
bool m_listFrameTags;
bool m_listLayers;
// Displacement for each tag from/to frames in case we export
// them. It's used in case we trim frames outside tags and they
// will not be exported at all in the final result.
std::map<doc::ObjectId, std::pair<int, int> > m_tagDelta;
DISABLE_COPYING(DocumentExporter);
};