Fix randomness when >= 2 rematch games
[vchess.git] / client / src / views / Game.vue
index 075919d..6570cb7 100644 (file)
@@ -179,6 +179,15 @@ main
 </template>
 
 <script>
+// TODO: this will be a component instead ?
+// If simultaneous games, no "rematch" button
+
+// simult : open connexion to rooms from list, in all (if I'm the "simultaneer" --> TODO: indicate sid + side [random,white, black] in challenge)
+// if I'm just one of the players (one game), just one game.
+// view "Game_s", with pug list of components Game.
+// generally only one element, unless I'm the simultaneer.
+// Add messages ?
+
 import BaseGame from "@/components/BaseGame.vue";
 import UserBio from "@/components/UserBio.vue";
 import Chat from "@/components/Chat.vue";
@@ -213,6 +222,7 @@ export default {
       game: {}, //passed to BaseGame
       focus: !document.hidden, //will not always work... TODO
       // virtualClocks will be initialized from true game.clocks
+      // TODO: clock update triggers re-rendering. Should be out of Vue
       virtualClocks: [],
       vr: null, //"variant rules" object initialized from FEN
       rulesContent: "",
@@ -256,7 +266,8 @@ export default {
           // In case of incomplete information variant:
           boardDiv.style.visibility = "hidden";
         this.atCreation();
-      } else
+      }
+      else
         // Same game ID
         this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
     }
@@ -520,7 +531,11 @@ export default {
     },
     getGameType: function(game) {
       if (!!game.id.toString().match(/^i/)) return "import";
-      return game.cadence.indexOf("d") >= 0 ? "corr" : "live";
+      return (
+        game.cadence.indexOf("d") >= 0
+          ? "corr"
+          : (game.cadence.indexOf("/") >= 0 ? "simul" : "live")
+      );
     },
     // Notify something after a new move (to opponent and me on MyGames page)
     notifyMyGames: function(thing, data) {
@@ -1041,6 +1056,7 @@ console.log(data.data);
         let gameInfo = {
           id: getRandString(), //ignored if corr
           fen: V.GenRandInitFen(this.game.randomness),
+          randomness: this.game.randomness,
           players: [this.game.players[1], this.game.players[0]],
           vid: this.game.vid,
           cadence: this.game.cadence
@@ -1062,7 +1078,6 @@ console.log(data.data);
             "/games",
             "POST",
             {
-              // cid is useful to delete the challenge:
               data: { gameInfo: gameInfo },
               success: (response) => {
                 gameInfo.id = response.gameId;
@@ -1283,7 +1298,10 @@ console.log(data.data);
     //  - from server (one correspondance game I play[ed] or not)
     //  - from remote peer (one live game I don't play, finished or not)
     fetchGame: function(callback) {
-      if (Number.isInteger(this.gameRef) || !isNaN(parseInt(this.gameRef))) {
+      if (
+        Number.isInteger(this.gameRef) ||
+        !isNaN(parseInt(this.gameRef, 10))
+      ) {
         // corr games identifiers are integers
         ajax(
           "/games",
@@ -1515,7 +1533,6 @@ console.log(data.data);
       };
       if (
         this.game.type == "corr" &&
-        V.CorrConfirm &&
         moveCol == this.game.mycolor &&
         !data.receiveMyMove
       ) {
@@ -1531,6 +1548,10 @@ console.log(data.data);
             if (data.score == "*") this.re_setClocks();
           }
         };
+        if (!V.CorrConfirm) {
+          afterSetScore();
+          return;
+        }
         let el = document.querySelector("#buttonsConfirm > .acceptBtn");
         // We may play several moves in a row: in case of, remove listener:
         let elClone = el.cloneNode(true);