From ae9a8128becec2fbc31e79fc60e7cf3f43a9a378 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 24 Oct 2019 19:55:42 -0300 Subject: [PATCH] Don't duplicate meta data (tags/slices) when -split-layers is used (fix #1582) --- src/app/doc_exporter.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index d02def591..81993a8ec 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #define DX_TRACE(...) // TRACEARGS @@ -1336,11 +1337,21 @@ void DocExporter::createDataFile(const Samples& samples, os << ",\n" << " \"frameTags\": ["; // TODO rename this someday in the future + std::set includedSprites; + bool firstTag = true; for (auto& item : m_documents) { Doc* doc = item.doc; Sprite* sprite = doc->sprite(); + // Avoid including tags two or more times in the list (e.g. when + // -split-layers is specified, several calls of addDocument() + // are used for each layer, so we have to avoid iterating the + // same sprite several times) + if (includedSprites.find(sprite->id()) != includedSprites.end()) + continue; + includedSprites.insert(sprite->id()); + for (Tag* tag : sprite->tags()) { if (firstTag) firstTag = false; @@ -1433,11 +1444,21 @@ void DocExporter::createDataFile(const Samples& samples, os << ",\n" << " \"slices\": ["; + std::set includedSprites; + bool firstSlice = true; for (auto& item : m_documents) { Doc* doc = item.doc; Sprite* sprite = doc->sprite(); + // Avoid including slices two or more times in the list + // (e.g. when -split-layers is specified, several calls of + // addDocument() are used for each layer, so we have to avoid + // iterating the same sprite several times) + if (includedSprites.find(sprite->id()) != includedSprites.end()) + continue; + includedSprites.insert(sprite->id()); + // TODO add possibility to export some slices for (Slice* slice : sprite->slices()) {