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 ...)
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
(function () {
|
|
var ns = $.namespace('pskl.utils.serialization.backward');
|
|
|
|
ns.Deserializer_v1 = function (data, callback) {
|
|
this.callback_ = callback;
|
|
this.data_ = data;
|
|
};
|
|
|
|
ns.Deserializer_v1.prototype.deserialize = function () {
|
|
var piskelData = this.data_.piskel;
|
|
var piskel = new pskl.model.Piskel(piskelData.width, piskelData.height);
|
|
|
|
piskelData.layers.forEach(function (serializedLayer) {
|
|
var layer = this.deserializeLayer(serializedLayer);
|
|
piskel.addLayer(layer);
|
|
}.bind(this));
|
|
|
|
this.callback_(piskel);
|
|
};
|
|
|
|
ns.Deserializer_v1.prototype.deserializeLayer = function (layerString) {
|
|
var layerData = JSON.parse(layerString);
|
|
var layer = new pskl.model.Layer(layerData.name);
|
|
layerData.frames.forEach(function (serializedFrame) {
|
|
var frame = this.deserializeFrame(serializedFrame);
|
|
layer.addFrame(frame);
|
|
}.bind(this));
|
|
|
|
return layer;
|
|
};
|
|
|
|
ns.Deserializer_v1.prototype.deserializeFrame = function (frameString) {
|
|
var framePixelGrid = JSON.parse(frameString);
|
|
return pskl.model.Frame.fromPixelGrid(framePixelGrid);
|
|
};
|
|
})(); |