From f160b27aa598e3a5a6e92d6f1ae61274a088151f Mon Sep 17 00:00:00 2001 From: Christian Kaiser Date: Sat, 17 May 2025 06:46:38 -0300 Subject: [PATCH] Do not export every tag to JSON when we have a tag selected (#5085) --- src/app/commands/cmd_export_sprite_sheet.cpp | 1 + src/app/doc_exporter.cpp | 18 ++++++++++++++++-- src/app/doc_exporter.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp index b24dc314e..c57b7b4cb 100644 --- a/src/app/commands/cmd_export_sprite_sheet.cpp +++ b/src/app/commands/cmd_export_sprite_sheet.cpp @@ -273,6 +273,7 @@ Doc* generate_sprite_sheet_from_params(DocExporter& exporter, exporter.setSplitTags(splitTags); exporter.setIgnoreEmptyCels(ignoreEmpty); exporter.setMergeDuplicates(mergeDuplicates); + exporter.setSelectedTag(tagName); if (listLayers) exporter.setListLayers(true); if (listTags) diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index e9d58a123..d7dc7a470 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -1529,6 +1529,10 @@ void DocExporter::createDataFile(const Samples& samples, std::ostream& os, doc:: includedSprites.insert(sprite->id()); for (Tag* tag : sprite->tags()) { + // Ignore unselected tags if we picked a specific one. + if (!m_selectedTagName.empty() && m_selectedTagName != tag->name()) + continue; + if (firstTag) firstTag = false; else @@ -1539,12 +1543,22 @@ void DocExporter::createDataFile(const Samples& samples, std::ostream& os, doc:: format = "{tag}"; } + frame_t fromFrame = tag->fromFrame(); + frame_t toFrame = tag->toFrame(); + + // Reset the frame offset when we're only exporting one frame tag so they're consistent + // with the exported frame list. + if (!m_selectedTagName.empty()) { + toFrame = toFrame - fromFrame; + fromFrame = 0; + } + FilenameInfo fnInfo; fnInfo.filename(doc->filename()).innerTagName(tag->name()); std::string tagname = filename_formatter(format, fnInfo); os << "\n { \"name\": \"" << escape_for_json(tagname) << "\"," - << " \"from\": " << (tag->fromFrame()) << "," - << " \"to\": " << (tag->toFrame()) + << " \"from\": " << fromFrame << "," + << " \"to\": " << toFrame << "," " \"direction\": \"" << escape_for_json(convert_anidir_to_string(tag->aniDir())) << "\""; diff --git a/src/app/doc_exporter.h b/src/app/doc_exporter.h index 6500b2738..4990687f6 100644 --- a/src/app/doc_exporter.h +++ b/src/app/doc_exporter.h @@ -79,6 +79,7 @@ public: void setListLayers(bool value) { m_listLayers = value; } void setListLayerHierarchy(bool value) { m_listLayerHierarchy = value; } void setListSlices(bool value) { m_listSlices = value; } + void setSelectedTag(const std::string& tagName) { m_selectedTagName = tagName; } void addImage(Doc* doc, const doc::ImageRef& image); @@ -153,6 +154,7 @@ private: std::string m_textureFilename; std::string m_filenameFormat; std::string m_tagnameFormat; + std::string m_selectedTagName; int m_textureWidth; int m_textureHeight; int m_textureColumns;