From 85a81878cc42646d73ef02301f96b2e0e8de0f84 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Sun, 13 Dec 2020 16:23:45 -0700 Subject: [PATCH] Add a button to download a level from the editor --- js/main-editor.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/main-editor.js b/js/main-editor.js index 4518c02..4e326ab 100644 --- a/js/main-editor.js +++ b/js/main-editor.js @@ -1623,6 +1623,25 @@ export class Editor extends PrimaryView { if (this.stored_level) { this.save_button.disabled = ! this.conductor.stored_game.editor_metadata; } + _make_button("Download", ev => { + // TODO also allow download as CCL + // TODO support getting warnings + errors out of synthesis + let buf = c2g.synthesize_level(this.stored_level); + let blob = new Blob([buf]); + let url = URL.createObjectURL(blob); + // To download a file, um, make an and click it. Not kidding + let a = mk('a', { + href: url, + download: (this.stored_level.title || 'untitled') + '.c2m', + }); + document.body.append(a); + a.click(); + // Absolutely no idea when I'm allowed to revoke this, but surely a minute is safe + window.setTimeout(() => { + a.remove(); + URL.revokeObjectURL(url); + }, 60 * 1000); + }); _make_button("Share", ev => { let buf = c2g.synthesize_level(this.stored_level); // FIXME Not ideal, but btoa() wants a string rather than any of the myriad binary types