Skip to content

Commit 7e7ba7d

Browse files
committed
do saving after picking file
1 parent a1c4510 commit 7e7ba7d

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

app/formats/image.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,36 @@ export function exportSpritesheet() {
8989
const { sprites } = environment;
9090
if (!sprites.length) return;
9191

92-
const canvases = sprites.map(({ buffer, mappings }) => exportSprite({ buffer, mappings }));
93-
94-
const canvas = document.createElement('canvas');
95-
canvas.width = 8;
96-
canvas.height = 8;
97-
const ctx = canvas.getContext('2d');
98-
// canvas.className = 'canvas-debug';
99-
// document.body.appendChild(canvas);
100-
101-
let cursor = 8;
102-
103-
canvases.forEach(current => {
104-
const last = ctx.getImageData(0, 0, canvas.width, canvas.height);
105-
const { width, height } = current;
106-
const diff = width + 8;
107-
canvas.width += diff
108-
canvas.height = Math.max(canvas.height, height + 8);
109-
ctx.putImageData(last, 0, 0);
110-
ctx.drawImage(current, cursor, 8);
111-
cursor += diff;
112-
});
113-
11492
dialog.showSaveDialog({
11593
title: 'Export Spritesheet',
11694
defaultPath: `spritesheet.png`,
11795
filters: [{name: 'PNG Image', extensions: ['png']}],
11896
})
11997
.then(({ filePath }) => {
12098
if (filePath) {
99+
100+
const canvases = sprites.map(({ buffer, mappings }) => exportSprite({ buffer, mappings }));
101+
102+
const canvas = document.createElement('canvas');
103+
canvas.width = 8;
104+
canvas.height = 8;
105+
const ctx = canvas.getContext('2d');
106+
// canvas.className = 'canvas-debug';
107+
// document.body.appendChild(canvas);
108+
109+
let cursor = 8;
110+
111+
canvases.forEach(current => {
112+
const last = ctx.getImageData(0, 0, canvas.width, canvas.height);
113+
const { width, height } = current;
114+
const diff = width + 8;
115+
canvas.width += diff
116+
canvas.height = Math.max(canvas.height, height + 8);
117+
ctx.putImageData(last, 0, 0);
118+
ctx.drawImage(current, cursor, 8);
119+
cursor += diff;
120+
});
121+
121122
const base64Data = canvas.toDataURL().replace(/data(.*?),/, '');
122123
writeFile(filePath, Buffer.from(base64Data, 'base64'), (err, success) => {
123124
err && errorMsg('Error exporting spritesheet', String(err));

0 commit comments

Comments
 (0)