Some fixes, draw lines on board, add 7 variants
[vchess.git] / client / src / views / Hall.vue
index fd4bd2d..71d7764 100644 (file)
@@ -186,13 +186,13 @@ main
         GameList(
           v-show="gdisplay=='live'"
           :games="filterGames('live')"
-          :showBoth="true"
+          :show-both="true"
           @show-game="showGame"
         )
         div(v-show="gdisplay=='corr'")
           GameList(
             :games="filterGames('corr')"
-            :showBoth="true"
+            :show-both="true"
             @show-game="showGame"
           )
           button#loadMoreBtn(
@@ -241,7 +241,9 @@ export default {
         vid: parseInt(localStorage.getItem("vid")) || 0,
         to: "", //name of challenged player (if any)
         cadence: localStorage.getItem("cadence") || "",
-        randomness: parseInt(localStorage.getItem("challRandomness")) || 2,
+        randomness:
+          // Warning: randomness can be 0, then !!randomness is false
+          (parseInt(localStorage.getItem("challRandomness"))+1 || 3) - 1,
         // VariantRules object, stored to not interfere with
         // diagrams of targetted challenges:
         V: null,
@@ -570,14 +572,12 @@ export default {
         }
       });
       const gid = gids[Math.floor(Math.random() * gids.length)];
-      const game = this.games.find(g => g.id == gid);
-      if (!!game) this.showGame(game);
-      else this.$router.push("/game/" + gid); //game vs. me
+      window.open("/#/game/" + gid, "_blank");
     },
     showGame: function(g) {
       // NOTE: we are an observer, since only games I don't play are shown here
       // ==> Moves sent by connected remote player(s) if live game
-      this.$router.push("/game/" + g.id);
+      window.open("/#/game/" + g.id, "_blank");
     },
     toggleSocialColor: function(action) {
       if (!action && document.getElementById("modalPeople").checked)
@@ -681,12 +681,19 @@ export default {
             this.$delete(this.people, data.from[0]);
           else this.$forceUpdate(); //TODO: shouldn't be required
           if (data.code == "disconnect") {
-            // Remove the live challenges sent by this player:
-            ArrayFun.remove(
-              this.challenges,
-              c => c.type == "live" && c.from.sid == data.from[0],
-              "all"
-            );
+            // Remove the live challenges sent by this player, if
+            // he isn't connected on another tab:
+            if (
+              !this.people[data.from[0]] ||
+              Object.values(this.people[data.from[0]].tmpIds)
+                .every(v => v.page != "/")
+            ) {
+              ArrayFun.remove(
+                this.challenges,
+                c => c.type == "live" && c.from.sid == data.from[0],
+                "all"
+              );
+            }
           } else {
             // Remove the matching live game if now unreachable
             const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
@@ -813,9 +820,13 @@ export default {
           // Ignore games where I play (will go in MyGames page),
           // and also games that I already received.
           if (
-            game.players.every(p =>
-              p.sid != this.st.user.sid && p.id != this.st.user.id) &&
-            this.games.findIndex(g => g.id == game.id) == -1
+            this.games.findIndex(g => g.id == game.id) == -1 &&
+            game.players.every(p => {
+              return (
+                p.sid != this.st.user.sid &&
+                (p.id == 0 || p.id != this.st.user.id)
+              );
+            })
           ) {
             let newGame = game;
             newGame.type = this.classifyObject(game);
@@ -825,6 +836,7 @@ export default {
               newGame.score = "*";
             this.games.push(newGame);
             if (
+              newGame.score == '*' &&
               (newGame.type == "live" && this.gdisplay == "corr") ||
               (newGame.type == "corr" && this.gdisplay == "live")
             ) {
@@ -876,7 +888,8 @@ export default {
               if (
                 this.cursor == Number.MAX_SAFE_INTEGER &&
                 this.games.length == 0 &&
-                this.gdisplay == "live"
+                this.gdisplay == "live" &&
+                res.games.some(g => g.score == '*')
               ) {
                 // First loading: show indicators
                 document
@@ -1007,7 +1020,11 @@ export default {
       let chall = Object.assign({}, this.newchallenge);
       // Add only if not already issued (not counting target or FEN):
       if (this.challenges.some(c =>
-        (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id) &&
+        (
+          c.from.sid == this.st.user.sid ||
+          (c.from.id > 0 && c.from.id == this.st.user.id)
+        )
+        &&
         c.vid == chall.vid &&
         c.cadence == chall.cadence &&
         c.randomness == chall.randomness
@@ -1029,7 +1046,10 @@ export default {
           const c = this.challenges[i];
           if (
             c.type == ctype &&
-            (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id)
+            (
+              c.from.sid == this.st.user.sid ||
+              (c.from.id > 0 && c.from.id == this.st.user.id)
+            )
           ) {
             countMyChalls++;
             if (c.added < oldestAdded) {
@@ -1182,10 +1202,13 @@ export default {
     // NOTE: when launching game, the challenge is already being deleted
     launchGame: function(c) {
       // White player index 0, black player index 1:
-      const players =
+      let players =
         !!c.mycolor
           ? (c.mycolor == "w" ? [c.seat, c.from] : [c.from, c.seat])
           : shuffle([c.from, c.seat]);
+      players.forEach(p => {
+        if (!!p["tmpIds"]) delete p["tmpIds"];
+      });
       // These game informations will be shared
       let gameInfo = {
         id: getRandString(),
@@ -1277,7 +1300,8 @@ export default {
                 { body: "vs " + game.players[1-myIdx].name || "@nonymous" }
               );
             }
-            this.$router.push("/game/" + gameInfo.id);
+            this.$router.push(
+              "/game/" + gameInfo.id + "/?focus=" + this.focus);
           });
         },
         this.focus ? 500 + 1000 * Math.random() : 0
@@ -1289,7 +1313,7 @@ export default {
 
 <style lang="sass" scoped>
 .active
-  color: #42a983
+  color: #388e3c
 
 #infoDiv > .card
   padding: 15px 0
@@ -1343,7 +1367,7 @@ button.player-action
   margin-left: 32px
 
 .somethingnew
-  background-color: #c5fefe !important
+  background-color: #90C4EC !important
 
 .tabbtn
   background-color: #f9faee