Moved subfunctions to prototype

This commit is contained in:
Max Eden 2015-04-30 13:17:56 +06:00
parent 016316518d
commit 034057dcd2

View file

@ -32,7 +32,32 @@
ns.PngExportController.prototype.onZipButtonClick_ = function () { ns.PngExportController.prototype.onZipButtonClick_ = function () {
var zip = new window.JSZip(); var zip = new window.JSZip();
function splittedExport() { if (this.splitByLayersCheckbox.checked) {
this.splittedExport_(zip);
} else {
this.mergedExport_(zip);
}
var fileName = this.getPiskelName_() + '.zip';
var blob = zip.generate({
type : 'blob'
});
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
};
ns.PngExportController.prototype.mergedExport_ = function (zip) {
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
var frame = this.piskelController.getFrameAt(i);
var canvas = this.getFrameAsCanvas_(frame);
var basename = this.pngFilePrefixInput.value;
var filename = basename + (i + 1) + '.png';
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
}
};
ns.PngExportController.prototype.splittedExport_ = function (zip) {
var layers = this.piskelController.getLayers(); var layers = this.piskelController.getLayers();
for (var j = 0; this.piskelController.hasLayerAt(j); j++) { for (var j = 0; this.piskelController.hasLayerAt(j); j++) {
var layer = this.piskelController.getLayerAt(j); var layer = this.piskelController.getLayerAt(j);
@ -44,31 +69,6 @@
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true}); zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
} }
} }
}
function mergedExport() {
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
var frame = this.piskelController.getFrameAt(i);
var canvas = this.getFrameAsCanvas_(frame);
var basename = this.pngFilePrefixInput.value;
var filename = basename + (i + 1) + '.png';
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
}
}
if (this.splitByLayersCheckbox.checked) {
splittedExport.call(this);
} else {
mergedExport.call(this);
}
var fileName = this.getPiskelName_() + '.zip';
var blob = zip.generate({
type : 'blob'
});
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
}; };
ns.PngExportController.prototype.getFrameAsCanvas_ = function (frame) { ns.PngExportController.prototype.getFrameAsCanvas_ = function (frame) {