Implement abort logic - add some TODOs (no 3 or 4 players games anymore)
[vchess.git] / client / src / views / Game.vue
index 9271f48..96c711b 100644 (file)
       div(v-show="cursor>=0") {{ moves[cursor].message }}
 </template>
 
+<!--
+// TODO: movelist dans basegame et chat ici
+// se limiter à 2 joueurs pour l'instant au moins tout en restant général
+// ==> après, implémenter/vérifier les passages de challenges + parties en cours
+// observer,
+// + problèmes, habiller et publier. (+ corr...)
+
+// refactor players.forEach(...) into sendTo(opponent, ...)
+-->
+
 <script>
 import BaseGame from "@/components/BaseGame.vue";
 //import Chat from "@/components/Chat.vue";
@@ -66,22 +76,7 @@ export default {
       let countdown = newState[colorIdx] -
         (Date.now() - this.game.initime[colorIdx])/1000;
       const myTurn = (currentTurn == this.game.mycolor);
-
-console.log(this.vr.turn + " " + currentTurn + " " + this.vr.getFen());
-
       let clockUpdate = setInterval(() => {
-
-
-
-
-console.log(countdown);
-        console.log(this.vr.turn +" " + currentTurn + " " + this.vr.getFen());
-
-// TODO: incoherent state because vr is altered in BaseGame to replay game
-        // ==> should use a temporary vr ?
-
-
-
         if (countdown <= 0 || this.vr.turn != currentTurn)
         {
           clearInterval(clockUpdate);
@@ -100,8 +95,11 @@ console.log(countdown);
             });
           }
         }
-        // TODO: with Vue 3, just do this.virtualClocks[colorIdx] = ppt(--countdown)
-        this.$set(this.virtualClocks, colorIdx, ppt(Math.max(0, --countdown)));
+        else
+        {
+          // TODO: with Vue 3, just do this.virtualClocks[colorIdx] = ppt(--countdown)
+          this.$set(this.virtualClocks, colorIdx, ppt(Math.max(0, --countdown)));
+        }
       }, 1000);
     },
   },
@@ -259,19 +257,18 @@ console.log(countdown);
       // if accept: send message "draw"
     },
     abortGame: function(event) {
+      let modalBox = document.getElementById("modalAbort");
       if (!event)
       {
         // First call show options:
-        let modalBox = document.getElementById("modalAbort");
         modalBox.checked = true;
       }
       else
       {
-        console.log(event);
-        return;
-        //const message = event.
+        modalBox.checked = false; //decision made: box disappear
+        const message = event.target.innerText;
         // Next line will trigger a "gameover" event, bubbling up till here
-        this.$refs["basegame"].endGame("?", "Abort: " + event.msg); //TODO
+        this.$refs["basegame"].endGame("?", "Abort: " + message);
         this.game.players.forEach(p => {
           if (!!p.sid && p.sid != this.st.user.sid)
           {
@@ -392,7 +389,9 @@ console.log(countdown);
       // Also update current game object:
       this.game.moves.push(move);
       this.game.fen = move.fen;
-      this.game.clocks[colorIdx] += (!!addTime ? addTime : 0);
+      //TODO: just this.game.clocks[colorIdx] += (!!addTime ? addTime : 0);
+      this.$set(this.game.clocks, colorIdx,
+        this.game.clocks[colorIdx] + (!!addTime ? addTime : 0));
       this.game.initime[nextIdx] = Date.now();
     },
     // TODO: this update function should also work for corr games