From 85336f9b9a2419e7986ac68635409d35cc3aac22 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Mon, 10 Oct 2016 01:47:26 +0200 Subject: [PATCH] fix loading of v2 models --- src/js/app.js | 13 ++++++++++--- src/js/utils/serialization/Deserializer.js | 2 +- .../utils/serialization/backward/Deserializer_v2.js | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index 0dd207f6..d5b45943 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -160,7 +160,7 @@ var piskelData = this.getPiskelInitData_(); if (piskelData && piskelData.piskel) { - this.loadPiskel_(piskelData.piskel, piskelData.descriptor, piskelData.fps); + this.loadPiskel_(piskelData); } if (pskl.devtools) { @@ -175,10 +175,17 @@ } }, - loadPiskel_ : function (serializedPiskel) { + loadPiskel_ : function (piskelData) { + var serializedPiskel = piskelData.piskel; pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel, extra) { + var fps = extra.fps; + if (piskelData.descriptor) { + // Backward compatibility for v2 or older + piskel.setDescriptor(piskelData.descriptor); + fps = piskelData.fps; + } pskl.app.piskelController.setPiskel(piskel); - pskl.app.previewController.setFPS(extra.fps); + pskl.app.previewController.setFPS(fps); }); }, diff --git a/src/js/utils/serialization/Deserializer.js b/src/js/utils/serialization/Deserializer.js index 945ba5d4..0335e4f4 100644 --- a/src/js/utils/serialization/Deserializer.js +++ b/src/js/utils/serialization/Deserializer.js @@ -46,7 +46,7 @@ deserializer.deserialize(); }; - ns.Deserializer.prototype.deserialize = function (name) { + ns.Deserializer.prototype.deserialize = function () { var i; var j; var buffer = this.data_; diff --git a/src/js/utils/serialization/backward/Deserializer_v2.js b/src/js/utils/serialization/backward/Deserializer_v2.js index 708d3505..70064e2c 100644 --- a/src/js/utils/serialization/backward/Deserializer_v2.js +++ b/src/js/utils/serialization/backward/Deserializer_v2.js @@ -9,10 +9,10 @@ this.layers_ = []; }; - ns.Deserializer_v2.prototype.deserialize = function (name) { + ns.Deserializer_v2.prototype.deserialize = function () { var data = this.data_; var piskelData = data.piskel; - name = piskelData.name || 'Deserialized piskel'; + var name = piskelData.name || 'Deserialized piskel'; var description = piskelData.description || ''; var descriptor = new pskl.model.piskel.Descriptor(name, description);