aboutsummaryrefslogtreecommitdiff
path: root/emccpre.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-11-12 15:03:40 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-11-12 15:03:40 +0000
commit208e2508d3ba459d32e31661a0fa9d1b4707dd0e (patch)
treed68ec87794eac6b4a1d680d3cd258bd26e81b6de /emccpre.js
parent4e3bb8f257f711c785498644a5c39d6c5d21dc87 (diff)
downloadpuzzles-208e2508d3ba459d32e31661a0fa9d1b4707dd0e.zip
puzzles-208e2508d3ba459d32e31661a0fa9d1b4707dd0e.tar.gz
puzzles-208e2508d3ba459d32e31661a0fa9d1b4707dd0e.tar.bz2
puzzles-208e2508d3ba459d32e31661a0fa9d1b4707dd0e.tar.xz
js: Add a way to have environment variables
They can now be specified by sticking some JSON in a <script> element in the Web page: <script id="environment" type="application/json"> { "LOOPY_DEFAULT": "20x10t11dh" } </script> This isn't brilliantly useful, but it does allow for changing settings without recompiling.
Diffstat (limited to 'emccpre.js')
-rw-r--r--emccpre.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/emccpre.js b/emccpre.js
index f971878..c4165bb 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -548,6 +548,19 @@ function initPuzzle() {
rescale_puzzle();
}
+ Module.preRun = function() {
+ // Merge environment variables from HTML script element.
+ // This means you can add something like this to the HTML:
+ // <script id="environment" type="application/json">
+ // { "LOOPY_DEFAULT": "20x10t11dh" }
+ // </script>
+ var envscript = document.getElementById("environment");
+ if (envscript !== null)
+ for (var [k, v] of
+ Object.entries(JSON.parse(envscript.textContent)))
+ ENV[k] = v;
+ };
+
Module.onRuntimeInitialized = function() {
// Run the C setup function, passing argv[1] as the fragment
// identifier (so that permalinks of the form puzzle.html#game-id