diff --git a/src/js/controller/settings/exportimage/PngExportController.js b/src/js/controller/settings/exportimage/PngExportController.js index a3d97e0c..8c9158cd 100644 --- a/src/js/controller/settings/exportimage/PngExportController.js +++ b/src/js/controller/settings/exportimage/PngExportController.js @@ -32,34 +32,10 @@ ns.PngExportController.prototype.onZipButtonClick_ = function () { var zip = new window.JSZip(); - function splittedExport() { - var layers = this.piskelController.getLayers(); - for (var j = 0; this.piskelController.hasLayerAt(j); j++) { - var layer = this.piskelController.getLayerAt(j); - for (var i = 0; i < this.piskelController.getFrameCount(); i++) { - var frame = layer.getFrameAt(i); - var canvas = this.getFrameAsCanvas_(frame); - var basename = this.pngFilePrefixInput.value; - var filename = 'l' + j + '_' + basename + (i + 1) + '.png'; - 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); + this.splittedExport_(zip); } else { - mergedExport.call(this); + this.mergedExport_(zip); } var fileName = this.getPiskelName_() + '.zip'; @@ -71,6 +47,30 @@ 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(); + for (var j = 0; this.piskelController.hasLayerAt(j); j++) { + var layer = this.piskelController.getLayerAt(j); + for (var i = 0; i < this.piskelController.getFrameCount(); i++) { + var frame = layer.getFrameAt(i); + var canvas = this.getFrameAsCanvas_(frame); + var basename = this.pngFilePrefixInput.value; + var filename = 'l' + j + '_' + basename + (i + 1) + '.png'; + zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true}); + } + } + }; + ns.PngExportController.prototype.getFrameAsCanvas_ = function (frame) { var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, 1); canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);