From 5a39d6850e38275272dada1068914837fa82f5e7 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sun, 9 Oct 2016 23:29:51 +0200 Subject: [PATCH] fix backward compatibility issue on piskelapp.com --- src/js/utils/PiskelFileUtils.js | 1 - src/js/utils/serialization/Deserializer.js | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/js/utils/PiskelFileUtils.js b/src/js/utils/PiskelFileUtils.js index 247279ca..07bf2ede 100644 --- a/src/js/utils/PiskelFileUtils.js +++ b/src/js/utils/PiskelFileUtils.js @@ -32,6 +32,5 @@ onSuccess(piskel, extra); }); } - }; })(); diff --git a/src/js/utils/serialization/Deserializer.js b/src/js/utils/serialization/Deserializer.js index 65bd7f88..945ba5d4 100644 --- a/src/js/utils/serialization/Deserializer.js +++ b/src/js/utils/serialization/Deserializer.js @@ -13,10 +13,11 @@ if (data instanceof ArrayBuffer || data instanceof Array) { var uint8 = new Uint8Array(data); - // Backward compatibility for JSON (modelVersion < 3) + // Backward compatibility for modelVersion < 3 for LocalStorage, FileImport etc... which + // now always serve the serialized sprites as strings and no longer as objects if (String.fromCharCode(uint8[0]) == '{') { data = ''; - for (var i = 0; i < uint8.length; i++) { + for (var i = 0 ; i < uint8.length ; i++) { data += String.fromCharCode(uint8[i]); } data = JSON.parse(data); @@ -25,6 +26,9 @@ var arr16 = new Uint16Array(uint8.buffer); modelVersion = arr16[0]; } + } else if (typeof data == 'object') { + // Backward Compatibility for sprites served from piskelapp.com with modelVersion < 3 + modelVersion = data.modelVersion; } else { throw 'Invalid data for deserializing: ' + data; }