piskel/js/utils/serialization/Serializer.js
jdescottes 86cd1cdeaa fix : reduce piskel model size
+ moved Serializer and Deserializer to utils.serialization package
+ put all backward code in utils.serialization.backward
+ added static method on Deserializer to make its usage similar to other
  utils in the package
- still not happy with the names used in Deserializer classes
  (deserializer.deserialize ...)
2013-11-15 00:03:05 +01:00

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
});
}
};
})();