fix : reduce piskel model size

+ piskel deserialization is now clearly asynchronous
+ added utils.Deserializer (not a singleton though, more a builder/loader)
+ utils.Deserializer constructor expects a callback
+ when all layers are loaded and piskel is ready, the callback provided by
  the client is called with piskel as the first argument
- Deserializer doesn't fit in the utils package, which should be reserved
  to singletons : can move it to service as a PiskelLoaderService, and
  Deserializer could remain with only the purely static methods
- ImportController is realying on the Deserializer to build a Piskel but
  it shouldn't. Find a way to mutualize the code necessary to create a
  Piskel from an array of pskl.model.Frame
- still cleanup to do in app.js
- comments to add as well
This commit is contained in:
jdescottes
2013-11-13 23:39:43 +01:00
parent 781abb735b
commit df4978f6af
6 changed files with 95 additions and 43 deletions

View File

@@ -93,9 +93,11 @@
finishInitAppEngine_ : function () {
if (pskl.framesheetData_ && pskl.framesheetData_.content) {
var piskel = pskl.utils.Serializer.createPiskel(pskl.framesheetData_.content);
pskl.app.piskelController.setPiskel(piskel);
pskl.app.animationController.setFPS(pskl.framesheetData_.fps);
var deserializer = new pskl.utils.Deserializer(pskl.framesheetData_.content, function (piskel) {
pskl.app.piskelController.setPiskel(piskel);
pskl.app.animationController.setFPS(pskl.framesheetData_.fps);
});
deserializer.deserialize();
}
},
@@ -156,10 +158,12 @@
xhr.responseType = 'text';
xhr.onload = function (e) {
var res = JSON.parse(this.responseText);
var piskel = pskl.utils.Serializer.createPiskel(res.framesheet);
pskl.app.piskelController.setPiskel(piskel);
pskl.app.animationController.setFPS(res.fps);
$.publish(Events.HIDE_NOTIFICATION);
var deserializer = new pskl.utils.Deserializer(res.framesheet, function (piskel) {
pskl.app.piskelController.setPiskel(piskel);
pskl.app.animationController.setFPS(res.fps);
$.publish(Events.HIDE_NOTIFICATION);
});
deserializer.deserialize();
};
xhr.onerror = function () {