2014-07-12 17:34:50 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace('pskl.utils');
|
|
|
|
|
|
|
|
ns.PiskelFileUtils = {
|
2014-07-13 03:01:33 +04:00
|
|
|
/**
|
|
|
|
* Load a piskel from a piskel file.
|
|
|
|
* After deserialization is successful, the provided success callback will be called.
|
|
|
|
* Success callback is expected to handle 3 arguments : (piskel:Piskel, descriptor:PiskelDescriptor, fps:Number)
|
|
|
|
* @param {File} file the .piskel file to load
|
|
|
|
* @param {Function} onSuccess Called if the deserialization of the piskel is successful
|
|
|
|
* @param {Function} onError NOT USED YET
|
|
|
|
*/
|
2014-07-12 17:34:50 +04:00
|
|
|
loadFromFile : function (file, onSuccess, onError) {
|
|
|
|
pskl.utils.FileUtils.readFile(file, function (content) {
|
2014-09-07 20:25:17 +04:00
|
|
|
var rawPiskel = pskl.utils.Base64.toText(content);
|
2015-03-17 14:24:03 +03:00
|
|
|
ns.PiskelFileUtils.decodePiskelFile(rawPiskel, onSuccess, onError);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
decodePiskelFile : function (rawPiskel, onSuccess, onError) {
|
|
|
|
var serializedPiskel = JSON.parse(rawPiskel);
|
|
|
|
var fps = serializedPiskel.piskel.fps;
|
|
|
|
var descriptor = new pskl.model.piskel.Descriptor(serializedPiskel.piskel.name, serializedPiskel.piskel.description, true);
|
|
|
|
pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel) {
|
|
|
|
onSuccess(piskel, descriptor, fps);
|
2014-07-12 17:34:50 +04:00
|
|
|
});
|
|
|
|
}
|
2015-03-17 14:24:03 +03:00
|
|
|
|
2014-07-12 17:34:50 +04:00
|
|
|
};
|
|
|
|
})();
|