From f75af4d76848e948c2cea738ea3f3dc124966173 Mon Sep 17 00:00:00 2001 From: Johnathon Selstad Date: Thu, 8 May 2025 13:49:56 -0700 Subject: [PATCH 1/3] Improve Binary Serialization in the Code Generator I'm a big fan of the Code Generator tool, but I noticed the all-in-one pages serialize the game as a JSON array, which can get kind of chunky. This PR swaps the JSON for a base64 string, bringing a `53.35mb` .html down to `21.85mb`. This should help with storage and load-times. Zipping the .html afterwards brings the whole thing down to within 10% of the original game size. bytes <-> base64 conversions adopted from examples on this page: https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa --- public/js/main.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index e2fa263..072b1f1 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -158,9 +158,9 @@ function editorMain() { } fileData += ' \n \n \n \n'; } else if (document.getElementById('offlinePack').checked) { data['EJS_gameUrl'] = 'new Blob([Uint8Array.from(atob(window.gameData), (m) => m.codePointAt(0))])'; var b = bytesToBase64(new Uint8Array(await (new Blob([file])).arrayBuffer())); @@ -169,7 +169,7 @@ function editorMain() { fileData += (spaces + k + ' = "' + data[k] + '";\n'); } } - fileData += ' \n \n \n \n'; zipOut = false; } else { data['EJS_gameUrl'] = 'new Blob([Uint8Array.from(atob(window.gameData), (m) => m.codePointAt(0))])'; @@ -182,7 +182,7 @@ function editorMain() { fileData += (spaces + k + ' = \'' + data[k] + '\';\n'); } } - fileData += ' \n \n \n \n'; } if (zipOut === false) { document.getElementById('select2').style = 'display:none;'; From 8f6142ad25f9468f6f59936075a1846773bb280c Mon Sep 17 00:00:00 2001 From: Johnathon Selstad Date: Thu, 8 May 2025 15:27:31 -0700 Subject: [PATCH 3/3] Add Compression to Code Generator This PR adds compression to the generated .html files using the browser's built-in gzip compression/decompression routines. This brings what would have been a `53.35mb` .html on master (or a `21.85mb` .html with #58 ) down to `16.32mb`. This further compresses down to `12mb` if zipped. Due to the async call needed for this, I made this a separate PR since the structure of the generated .html has changed to only load the emulator after the game data has been decompressed. This is incompatible with the non-single-file-packing code, so it has been removed. --- pages/editor.vue | 6 ------ public/js/main.js | 42 ++++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/pages/editor.vue b/pages/editor.vue index 376dbaf..8e2edcc 100644 --- a/pages/editor.vue +++ b/pages/editor.vue @@ -58,12 +58,6 @@ definePageMeta({ -