Move string to buffer converting code to utils

This commit is contained in:
Dávid Szabó 2016-09-27 21:24:46 +02:00 committed by Julian Descottes
parent 5fe9081df1
commit e647826095
2 changed files with 12 additions and 5 deletions

View File

@ -38,12 +38,9 @@
var piskelString = this.getPiskel(name);
var key = this.getKey_(name);
var serializedPiskel = new Uint16Array(piskelString.length);
for (var i = 0, length = piskelString.length; i < length; i++) {
serializedPiskel[i] = piskelString.charCodeAt(i);
}
var serializedPiskel = pskl.utils.convertStringToBuffer(piskelString);
pskl.utils.serialization.Deserializer.deserialize(serializedPiskel.buffer, function (piskel, extra) {
pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel, extra) {
pskl.app.piskelController.setPiskel(piskel);
pskl.app.previewController.setFPS(extra.fps);
});

View File

@ -275,4 +275,14 @@ if (!Uint32Array.prototype.fill) {
return string;
};
ns.convertStringToBuffer = function(inputString) {
var uint16 = new Uint16Array(inputString.length);
for (var i = 0, length = inputString.length; i < length; i++) {
uint16[i] = inputString.charCodeAt(i);
}
return uint16.buffer;
};
})();