mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Moved subfunctions to prototype
This commit is contained in:
parent
016316518d
commit
034057dcd2
@ -32,34 +32,10 @@
|
|||||||
ns.PngExportController.prototype.onZipButtonClick_ = function () {
|
ns.PngExportController.prototype.onZipButtonClick_ = function () {
|
||||||
var zip = new window.JSZip();
|
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) {
|
if (this.splitByLayersCheckbox.checked) {
|
||||||
splittedExport.call(this);
|
this.splittedExport_(zip);
|
||||||
} else {
|
} else {
|
||||||
mergedExport.call(this);
|
this.mergedExport_(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileName = this.getPiskelName_() + '.zip';
|
var fileName = this.getPiskelName_() + '.zip';
|
||||||
@ -71,6 +47,30 @@
|
|||||||
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
|
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) {
|
ns.PngExportController.prototype.getFrameAsCanvas_ = function (frame) {
|
||||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, 1);
|
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, 1);
|
||||||
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
|
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
|
||||||
|
Loading…
Reference in New Issue
Block a user