[aseprite] 234/250: Export frame tags/layers to JSON data when --list-tags/layers is used
Tobias Hansen
thansen at moszumanska.debian.org
Sun Dec 20 15:27:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit d05dc56503995d14a628afe8a90208ecd697238d
Author: David Capello <davidcapello at gmail.com>
Date: Wed Nov 4 19:34:23 2015 -0300
Export frame tags/layers to JSON data when --list-tags/layers is used
---
src/app/app.cpp | 4 +++
src/app/app_options.cpp | 4 +--
src/app/document_exporter.cpp | 69 ++++++++++++++++++++++++++++++++++++++-----
src/app/document_exporter.h | 4 +++
4 files changed, 72 insertions(+), 9 deletions(-)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index c703434..e51eed0 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -448,10 +448,14 @@ void App::initialize(const AppOptions& options)
// --list-layers
else if (opt == &options.listLayers()) {
listLayers = true;
+ if (m_exporter)
+ m_exporter->setListLayers(true);
}
// --list-tags
else if (opt == &options.listTags()) {
listTags = true;
+ if (m_exporter)
+ m_exporter->setListFrameTags(true);
}
}
// File names aren't associated to any option
diff --git a/src/app/app_options.cpp b/src/app/app_options.cpp
index 6e376b9..3b4979a 100644
--- a/src/app/app_options.cpp
+++ b/src/app/app_options.cpp
@@ -47,8 +47,8 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_crop(m_po.add("crop").requiresValue("x,y,width,height").description("Crop all the images to the given rectangle"))
, m_filenameFormat(m_po.add("filename-format").requiresValue("<fmt>").description("Special format to generate filenames"))
, m_script(m_po.add("script").requiresValue("<filename>").description("Execute a specific script"))
- , m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite"))
- , m_listTags(m_po.add("list-tags").description("List tags of the next given sprite"))
+ , m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data"))
+ , m_listTags(m_po.add("list-tags").description("List tags of the next given sprite sprite\nor include frame tags in JSON data"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
, m_help(m_po.add("help").mnemonic('?').description("Display this help and exits"))
, m_version(m_po.add("version").description("Output version information and exit"))
diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp
index fd38aec..8627297 100644
--- a/src/app/document_exporter.cpp
+++ b/src/app/document_exporter.cpp
@@ -46,10 +46,11 @@ using namespace doc;
namespace {
-std::string escape_path_for_json(const std::string& path)
+std::string escape_for_json(const std::string& path)
{
std::string res = path;
base::replace_string(res, "\\", "\\\\");
+ base::replace_string(res, "\"", "\\\"");
return res;
}
@@ -297,6 +298,8 @@ DocumentExporter::DocumentExporter()
, m_shapePadding(0)
, m_innerPadding(0)
, m_trimCels(false)
+ , m_listFrameTags(false)
+ , m_listLayers(false)
{
}
@@ -593,10 +596,10 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
gfx::Rect frameBounds = sample.inTextureBounds();
if (filename_as_key)
- os << " \"" << escape_path_for_json(sample.filename()) << "\": {\n";
+ os << " \"" << escape_for_json(sample.filename()) << "\": {\n";
else if (filename_as_attr)
os << " {\n"
- << " \"filename\": \"" << escape_path_for_json(sample.filename()) << "\",\n";
+ << " \"filename\": \"" << escape_for_json(sample.filename()) << "\",\n";
os << " \"frame\": { "
<< "\"x\": " << frameBounds.x << ", "
@@ -621,19 +624,71 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
else
os << "\n";
}
+ os << " " << frames_end;
- os << " " << frames_end << ",\n"
+ // "meta" property
+ os << ",\n"
<< " \"meta\": {\n"
<< " \"app\": \"" << WEBSITE << "\",\n"
<< " \"version\": \"" << VERSION << "\",\n";
+
if (!m_textureFilename.empty())
- os << " \"image\": \"" << escape_path_for_json(m_textureFilename).c_str() << "\",\n";
+ os << " \"image\": \"" << escape_for_json(m_textureFilename).c_str() << "\",\n";
+
os << " \"format\": \"" << (textureImage->pixelFormat() == IMAGE_RGB ? "RGBA8888": "I8") << "\",\n"
<< " \"size\": { "
<< "\"w\": " << textureImage->width() << ", "
<< "\"h\": " << textureImage->height() << " },\n"
- << " \"scale\": \"" << m_scale << "\"\n"
- << " }\n"
+ << " \"scale\": \"" << m_scale << "\"";
+
+ // meta.frameTags
+ if (m_listFrameTags) {
+ os << ",\n"
+ << " \"frameTags\": [";
+
+ bool firstTag = true;
+ for (auto& item : m_documents) {
+ Document* doc = item.doc;
+ Sprite* sprite = doc->sprite();
+
+ for (FrameTag* tag : sprite->frameTags()) {
+ if (firstTag)
+ firstTag = false;
+ else
+ os << ",";
+ os << "\n { \"name\": \"" << escape_for_json(tag->name()) << "\","
+ << " \"from\": " << tag->fromFrame() << ","
+ << " \"to\": " << tag->toFrame() << " }";
+ }
+ }
+ os << "\n ]";
+ }
+
+ // meta.layers
+ if (m_listLayers) {
+ os << ",\n"
+ << " \"layers\": [";
+
+ bool firstLayer = true;
+ for (auto& item : m_documents) {
+ Document* doc = item.doc;
+ Sprite* sprite = doc->sprite();
+
+ std::vector<Layer*> layers;
+ sprite->getLayersList(layers);
+
+ for (Layer* layer : layers) {
+ if (firstLayer)
+ firstLayer = false;
+ else
+ os << ",";
+ os << "\n { \"name\": \"" << escape_for_json(layer->name()) << "\" }";
+ }
+ }
+ os << "\n ]";
+ }
+
+ os << "\n }\n"
<< "}\n";
}
diff --git a/src/app/document_exporter.h b/src/app/document_exporter.h
index 47205a8..692e1e2 100644
--- a/src/app/document_exporter.h
+++ b/src/app/document_exporter.h
@@ -60,6 +60,8 @@ namespace app {
void setInnerPadding(int padding) { m_innerPadding = padding; }
void setTrimCels(bool trim) { m_trimCels = trim; }
void setFilenameFormat(const std::string& format) { m_filenameFormat = format; }
+ void setListFrameTags(bool value) { m_listFrameTags = value; }
+ void setListLayers(bool value) { m_listLayers = value; }
void addDocument(Document* document,
doc::Layer* layer = nullptr,
@@ -121,6 +123,8 @@ namespace app {
Items m_documents;
std::string m_filenameFormat;
doc::ImageBufferPtr m_sampleRenderBuf;
+ bool m_listFrameTags;
+ bool m_listLayers;
DISABLE_COPYING(DocumentExporter);
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list