mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Zip-Export: Split by layers option
This commit is contained in:
parent
ce8d71f47e
commit
016316518d
@ -13,6 +13,8 @@
|
||||
this.pngFilePrefixInput = document.getElementById('zip-prefix-name');
|
||||
this.pngFilePrefixInput.value = 'sprite_';
|
||||
|
||||
this.splitByLayersCheckbox = document.getElementById('zip-split-by-layers');
|
||||
|
||||
var downloadButton = document.querySelector('.png-download-button');
|
||||
this.addEventListener(downloadButton, 'click', this.onPngDownloadButtonClick_);
|
||||
|
||||
@ -30,6 +32,21 @@
|
||||
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);
|
||||
@ -37,6 +54,13 @@
|
||||
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';
|
||||
|
||||
|
@ -15,6 +15,12 @@
|
||||
<div class="settings-item">
|
||||
<label for="zip-prefix-name">Prefix:</label>
|
||||
<input id="zip-prefix-name" type="text" class="textfield" placeholder="PNG file prefix ...">
|
||||
</div>
|
||||
<div class="settings-item">
|
||||
<label>
|
||||
<input id="zip-split-by-layers" type="checkbox" />
|
||||
Split by layers
|
||||
</label>
|
||||
</div>
|
||||
<button type="button" class="button button-primary zip-generate-button"/>Download ZIP</button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user