mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-09 18:44:46 +00:00
Export user data in JSON data
This commit is contained in:
parent
9c42a7b31b
commit
b5dd02eb46
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -54,6 +55,24 @@ std::string escape_for_json(const std::string& path)
|
|||||||
return res;
|
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
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -734,6 +753,38 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
|
|||||||
os << ", \"opacity\": " << layerImg->opacity()
|
os << ", \"opacity\": " << layerImg->opacity()
|
||||||
<< ", \"blendMode\": \"" << blend_mode_to_string(layerImg->blendMode()) << "\"";
|
<< ", \"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 << " }";
|
os << " }";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user