/* * emccpre.js: one of the Javascript components of an Emscripten-based * web/Javascript front end for Puzzles. * * The other parts of this system live in emcc.c and emcclib.js. It * also depends on being run in the context of a web page containing * an appropriate collection of bits and pieces (a canvas, some * buttons and links etc), which is generated for each puzzle by the * script html/jspage.pl. * * This file contains the Javascript code which is prefixed unmodified * to Emscripten's output via the --pre-js option. It declares all our * global variables, and provides the puzzle init function and a * couple of other helper functions. */ // Because this script is run using var envscript, k, v; for (envscript of document.querySelectorAll( "script#environment, script.environment")) for ([k, v] of Object.entries(JSON.parse(envscript.textContent))) ENV[k] = v; }, // Pass argv[1] as the fragment identifier (so that permalinks of // the form puzzle.html#game-id can launch the specified id). 'arguments': [decodeURIComponent(location.hash)], 'noExitRuntime': true }; // Variables used by js_canvas_find_font_midpoint(). var midpoint_test_str = "ABCDEFGHIKLMNOPRSTUVWXYZ0123456789"; var midpoint_cache = []; // Variables used by js_activate_timer() and js_deactivate_timer(). var timer; var timer_reference; // void timer_callback(double tplus); // // Called every frame while timing is active. var timer_callback; // The status bar object, if we have one. var statusbar = document.getElementById("statusbar"); // Currently live blitters. We keep an integer id for each one on the // JS side; the C side, which expects a blitter to look like a struct, // simply defines the struct to contain that integer id. var blittercount = 0; var blitters = []; // State for the dialog-box mechanism. dlg_dimmer and dlg_form are the // page-darkening overlay and the actual dialog box respectively; // dlg_return_funcs is a list of JS functions to be called when the OK // button is pressed, to pass the results back to C. var dlg_dimmer = null, dlg_form = null; var dlg_return_funcs = null; // void dlg_return_sval(int index, const char *val); // void dlg_return_ival(int index, int val); // // C-side entry points called by functions in dlg_return_funcs, to // pass back the final value in each dialog control. var dlg_return_sval, dlg_return_ival; // Callback for reading from a savefile. This will be filled in with // a suitable closure by the JS loading code and called by // js_savefile_read(). This assumes that only one file can be in the // process of loading at a time. var savefile_read_callback; // void prefs_load_callback(midend *me, const char *prefs); // // Callback for passing in preferences data retrieved from localStorage. var prefs_load_callback; // The