]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Re-fix first load bug (hopefully)
authorStephen Seo <seo.disparate@gmail.com>
Wed, 18 Jan 2023 07:24:36 +0000 (16:24 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 18 Jan 2023 07:24:36 +0000 (16:24 +0900)
wasm_build/client.js

index b08359829ae89e4d320c04d00d48b94010d2e43d..04d319610143952d1f2c9a2331272151505cd649 100644 (file)
@@ -1,5 +1,4 @@
-// Use setTimeout to give the .wasm binary time to load first.
-setTimeout(() => {
+function do_rune_init() {
 Rune.initClient({
     visualUpdate: ({ newGame, yourPlayerId}) => {
         const { player1, player2, first_choices, second_choices, ready, matchup_done, pos, prev_pos, gameover, gameover_called, matchup_started } = newGame;
@@ -56,4 +55,14 @@ Rune.initClient({
         }
     },
 });
-}, 500);
+}
+
+let em_checking_interval_id = setInterval(
+    () => {
+        if (Module !== undefined && Module.ccall !== undefined) {
+            do_rune_init();
+            clearInterval(em_checking_interval_id);
+            console.log("Rune initialized!");
+        }
+    }, 500
+);