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