Simplify abort, fix time in corr games
[vchess.git] / client / src / views / Game.vue
index 2d085c8..6146e27 100644 (file)
@@ -1,21 +1,13 @@
 <template lang="pug">
 .row
   .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
-    input#modalAbort.modal(type="checkbox")
-    div(role="dialog" aria-labelledby="abortBoxTitle")
-      .card.smallpad.small-modal.text-center
-        label.modal-close(for="modalAbort")
-        h3#abortBoxTitle.section {{ st.tr["Terminate game?"] }}
-        button(@click="abortGame") {{ st.tr["Sorry I have to go"] }}
-        button(@click="abortGame") {{ st.tr["Game seems over"] }}
-        button(@click="abortGame") {{ st.tr["Opponent is gone"] }}
     BaseGame(:game="game" :vr="vr" ref="basegame"
       @newmove="processMove" @gameover="gameOver")
     div Names: {{ game.players[0].name }} - {{ game.players[1].name }}
     div(v-if="game.score=='*'") Time: {{ virtualClocks[0] }} - {{ virtualClocks[1] }}
     .button-group(v-if="game.mode!='analyze' && game.score=='*'")
       button(@click="offerDraw") Draw
-      button(@click="() => abortGame()") Abort
+      button(@click="abortGame") Abort
       button(@click="resign") Resign
     textarea(v-if="game.score=='*'" v-model="corrMsg")
     Chat(:players="game.players")
@@ -102,8 +94,6 @@ export default {
     this.gameRef.rid = this.$route.query["rid"]; //may be undefined
     if (!this.gameRef.rid)
       this.loadGame(); //local or corr: can load from now
-    // TODO: mode analyse (/analyze/Atomic/rn
-    // ... fen = query[], vname=params[] ...
     // 0.1] Ask server for room composition:
     const initialize = () => {
       // Poll clients + load game if stored remotely
@@ -226,7 +216,7 @@ export default {
             this.game.mycolor=="w" ? "1-0" : "0-1", "Resign");
           break;
         case "abort":
-          this.$refs["basegame"].endGame("?", "Abort: " + data.msg);
+          this.$refs["basegame"].endGame("?", "Abort");
           break;
         case "draw":
           this.$refs["basegame"].endGame("1/2", "Mutual agreement");
@@ -283,29 +273,20 @@ export default {
       // TODO: ignore if preventDrawOffer is set; otherwise show modal box with option "prevent future offers"
       // if accept: send message "draw"
     },
-    abortGame: function(event) {
-      let modalBox = document.getElementById("modalAbort");
-      if (!event)
-      {
-        // First call show options:
-        modalBox.checked = true;
-      }
-      else
-      {
-        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: " + message);
-        const oppsid = this.getOppSid();
-        if (!!oppsid)
+    abortGame: function() {
+      if (!confirm(this.st.tr["Terminate game?"]))
+        return;
+      // Next line will trigger a "gameover" event, bubbling up till here
+      this.$refs["basegame"].endGame("?", "Abort");
+      this.people.forEach(p => {
+        if (p.sid != this.st.user.sid)
         {
           this.st.conn.send(JSON.stringify({
             code: "abort",
-            msg: message,
-            target: oppsid,
+            target: p.sid,
           }));
         }
-      }
+      });
     },
     resign: function(e) {
       if (!confirm("Resign the game?"))
@@ -342,6 +323,7 @@ export default {
               [ game.players[1], game.players[0] ];
           }
           // corr game: needs to compute the clocks + initime
+          // NOTE: clocks in seconds, initime in milliseconds
           game.clocks = [tc.mainTime, tc.mainTime];
           game.initime = [0, 0];
           const L = game.moves.length;
@@ -352,7 +334,7 @@ export default {
             for (let i=2; i<L; i++)
             {
               addTime[i%2] += tc.increment -
-                (game.moves[i].played - game.moves[i-1].played);
+                (game.moves[i].played - game.moves[i-1].played) / 1000;
             }
             for (let i=0; i<=1; i++)
               game.clocks[i] += addTime[i];