mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
32 lines
849 B
JavaScript
32 lines
849 B
JavaScript
(function () {
|
|
var ns = $.namespace('pskl.utils');
|
|
|
|
ns.Serializer = {
|
|
serializePiskel : function (piskel) {
|
|
var serializedLayers = piskel.getLayers().map(function (l) {
|
|
return pskl.utils.Serializer.serializeLayer(l);
|
|
});
|
|
return JSON.stringify({
|
|
modelVersion : Constants.MODEL_VERSION,
|
|
piskel : {
|
|
height : piskel.getHeight(),
|
|
width : piskel.getWidth(),
|
|
layers : serializedLayers
|
|
}
|
|
});
|
|
},
|
|
|
|
serializeLayer : function (layer) {
|
|
var frames = layer.getFrames();
|
|
var renderer = new pskl.rendering.FramesheetRenderer(frames);
|
|
var base64PNG = renderer.renderAsCanvas().toDataURL();
|
|
|
|
return JSON.stringify({
|
|
name : layer.getName(),
|
|
base64PNG : base64PNG,
|
|
frameCount : frames.length
|
|
});
|
|
}
|
|
};
|
|
})();
|