From dae08107e22c450026b4cfd951c8806eba8b98f3 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 1 Mar 2018 20:08:31 -0500 Subject: [PATCH] Added new checkbox to zip export html template and use layer name as prefix to file names (in ZipExportController) if checkbox is selected. --- .../settings/exportimage/ZipExportController.js | 14 +++++++++++++- src/templates/settings/export/zip.html | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/js/controller/settings/exportimage/ZipExportController.js b/src/js/controller/settings/exportimage/ZipExportController.js index be0ab283f..92eaaa43c 100644 --- a/src/js/controller/settings/exportimage/ZipExportController.js +++ b/src/js/controller/settings/exportimage/ZipExportController.js @@ -12,12 +12,21 @@ this.pngFilePrefixInput = document.querySelector('.zip-prefix-name'); this.pngFilePrefixInput.value = 'sprite_'; - this.splitByLayersCheckbox = document.querySelector('.zip-split-layers-checkbox'); + this.splitByLayersCheckbox = document.querySelector('.zip-split-layers-checkbox'); + this.addEventListener(this.splitByLayersCheckbox, 'change', this.onSplitLayersClick_); + + this.useLayerNamesCheckboxContainer = document.querySelector('.use-layer-names-checkbox-container'); + this.useLayerNamesCheckbox = document.querySelector('.zip-use-layer-names-checkbox'); + this.useLayerNamesCheckboxContainer.hidden = !this.splitByLayersCheckbox.checked; var zipButton = document.querySelector('.zip-generate-button'); this.addEventListener(zipButton, 'click', this.onZipButtonClick_); }; + ns.ZipExportController.prototype.onSplitLayersClick_ = function () { + this.useLayerNamesCheckboxContainer.hidden = !this.splitByLayersCheckbox.checked; + }; + ns.ZipExportController.prototype.onZipButtonClick_ = function () { var zip = new window.JSZip(); @@ -63,6 +72,9 @@ var basename = this.pngFilePrefixInput.value; var frameid = pskl.utils.StringUtils.leftPad(i + 1, framePaddingLength, '0'); var filename = 'l' + layerid + '_' + basename + frameid + '.png'; + if (this.useLayerNamesCheckbox.checked) { + filename = layer.getName() + '_' + basename + frameid + '.png'; + } zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true}); } } diff --git a/src/templates/settings/export/zip.html b/src/templates/settings/export/zip.html index 17dbf5fa2..f18b186fe 100644 --- a/src/templates/settings/export/zip.html +++ b/src/templates/settings/export/zip.html @@ -11,7 +11,11 @@ +
+ + +
- \ No newline at end of file +