mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
86cd1cdeaa
+ 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 ...)
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
|
|
});
|
|
}
|
|
};
|
|
})();
|