]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Don't share choices unless both sides are set
authorStephen Seo <seo.disparate@gmail.com>
Thu, 5 Jan 2023 04:36:19 +0000 (13:36 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 5 Jan 2023 04:36:19 +0000 (13:36 +0900)
wasm_build/client.js

index 039bc2444454199591fd96bc0023a0db5c709852..b284d61ba83c411bfb30481d2835992683ebdacb 100644 (file)
@@ -2,22 +2,51 @@ Rune.initClient({
     visualUpdate: ({ newGame, yourPlayerId}) => {
         const { player1, player2, first_choices, second_choices, ready, pos, matchup_idx } = newGame;
 
-        Module.ccall('game_visual_update',
-            'number',
-            ['string', 'string', 'string',
-                'number', 'number', 'number',
-                'number', 'number', 'number',
-                'boolean', 'boolean',
-                'number', 'number'],
-            [player1, player2,
-                yourPlayerId === undefined ? 'undefined' : yourPlayerId,
-                first_choices[0].charCodeAt(0),
-                first_choices[1].charCodeAt(0),
-                first_choices[2].charCodeAt(0),
-                second_choices[0].charCodeAt(0),
-                second_choices[1].charCodeAt(0),
-                second_choices[2].charCodeAt(0),
-                ready[0], ready[1],
-                pos, matchup_idx]);
+        function is_choices_filled(choices) {
+            for (let i = 0; i < 3; ++i) {
+                if (choices[i] === null || choices[i] === '?') {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        if (is_choices_filled(first_choices) && is_choices_filled(second_choices)) {
+            Module.ccall('game_visual_update',
+                'number',
+                ['string', 'string', 'string',
+                    'number', 'number', 'number',
+                    'number', 'number', 'number',
+                    'boolean', 'boolean',
+                    'number', 'number'],
+                [player1, player2,
+                    yourPlayerId === undefined ? 'undefined' : yourPlayerId,
+                    first_choices[0].charCodeAt(0),
+                    first_choices[1].charCodeAt(0),
+                    first_choices[2].charCodeAt(0),
+                    second_choices[0].charCodeAt(0),
+                    second_choices[1].charCodeAt(0),
+                    second_choices[2].charCodeAt(0),
+                    ready[0], ready[1],
+                    pos, matchup_idx]);
+        } else {
+            Module.ccall('game_visual_update',
+                'number',
+                ['string', 'string', 'string',
+                    'number', 'number', 'number',
+                    'number', 'number', 'number',
+                    'boolean', 'boolean',
+                    'number', 'number'],
+                [player1, player2,
+                    yourPlayerId === undefined ? 'undefined' : yourPlayerId,
+                    '?'.charCodeAt(0),
+                    '?'.charCodeAt(0),
+                    '?'.charCodeAt(0),
+                    '?'.charCodeAt(0),
+                    '?'.charCodeAt(0),
+                    '?'.charCodeAt(0),
+                    ready[0], ready[1],
+                    pos, matchup_idx]);
+        }
     },
 });