[aseprite] 144/308: Export user data in JSON data

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:45:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit b5dd02eb46459a2d1ddf92bb27e5aae8474d2a6e
Author: David Capello <davidcapello at gmail.com>
Date:   Tue Dec 22 16:53:06 2015 -0300

    Export user data in JSON data
---
 src/app/document_exporter.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp
index 2c4ee61..11b3165 100644
--- a/src/app/document_exporter.cpp
+++ b/src/app/document_exporter.cpp
@@ -39,6 +39,7 @@
 
 #include <cstdio>
 #include <fstream>
+#include <iomanip>
 #include <iostream>
 #include <list>
 
@@ -54,6 +55,24 @@ std::string escape_for_json(const std::string& path)
   return res;
 }
 
+std::ostream& operator<<(std::ostream& os, const doc::UserData& data)
+{
+  doc::color_t color = data.color();
+  if (doc::rgba_geta(color)) {
+    os << ", \"color\": \"#"
+       << std::hex << std::setfill('0')
+       << std::setw(2) << (int)doc::rgba_getr(color)
+       << std::setw(2) << (int)doc::rgba_getg(color)
+       << std::setw(2) << (int)doc::rgba_getb(color)
+       << std::setw(2) << (int)doc::rgba_geta(color)
+       << std::dec
+       << "\"";
+  }
+  if (!data.text().empty())
+    os << ", \"data\": \"" << escape_for_json(data.text()) << "\"";
+  return os;
+}
+
 } // anonymous namespace
 
 namespace app {
@@ -734,6 +753,38 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
           os << ", \"opacity\": " << layerImg->opacity()
              << ", \"blendMode\": \"" << blend_mode_to_string(layerImg->blendMode()) << "\"";
         }
+        os << layer->userData();
+
+        // Cels
+        CelList cels;
+        layer->getCels(cels);
+        bool someCelWithData = false;
+        for (const Cel* cel : cels) {
+          if (!cel->data()->userData().isEmpty()) {
+            someCelWithData = true;
+            break;
+          }
+        }
+
+        if (someCelWithData) {
+          bool firstCel = true;
+
+          os << ", \"cels\": [";
+          for (const Cel* cel : cels) {
+            if (!cel->data()->userData().isEmpty()) {
+              if (firstCel)
+                firstCel = false;
+              else
+                os << ", ";
+
+              os << "{ \"frame\": " << cel->frame()
+                 << cel->data()->userData()
+                 << " }";
+            }
+          }
+          os << "]";
+        }
+
         os << " }";
       }
     }

-- 
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