Issue with observer in live games: moveToPlay repeated, no online indics ?!
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Feb 2020 09:39:00 +0000 (10:39 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Feb 2020 09:39:00 +0000 (10:39 +0100)
client/src/components/BaseGame.vue
client/src/views/Game.vue
client/src/views/Hall.vue
client/src/views/Rules.vue

index 07343c5..6faa1b6 100644 (file)
@@ -71,6 +71,9 @@ export default {
     },
     // Received a new move to play:
     "game.moveToPlay": function(newMove) {
     },
     // Received a new move to play:
     "game.moveToPlay": function(newMove) {
+
+console.log(newMove);
+
       if (!!newMove) //if stop + launch new game, get undefined move
         this.play(newMove, "receive");
     },
       if (!!newMove) //if stop + launch new game, get undefined move
         this.play(newMove, "receive");
     },
index c0c5031..edaca5c 100644 (file)
@@ -16,10 +16,12 @@ main
         button(@click="resign") Resign
       #playersInfo
         p
         button(@click="resign") Resign
       #playersInfo
         p
-          span.name(:class="{connected: isConnected(0)}") {{ game.players[0].name }}
+          span.name(:class="{connected: isConnected(0)}")
+            | {{ game.players[0].name || "@nonymous" }}
           span.time(v-if="game.score=='*'") {{ virtualClocks[0] }}
           span.split-names -
           span.time(v-if="game.score=='*'") {{ virtualClocks[0] }}
           span.split-names -
-          span.name(:class="{connected: isConnected(1)}") {{ game.players[1].name }}
+          span.name(:class="{connected: isConnected(1)}")
+            | {{ game.players[1].name || "@nonymous" }}
           span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
   BaseGame(:game="game" :vr="vr" ref="basegame"
     @newmove="processMove" @gameover="gameOver")
           span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
   BaseGame(:game="game" :vr="vr" ref="basegame"
     @newmove="processMove" @gameover="gameOver")
@@ -214,7 +216,9 @@ export default {
           break;
         }
         case "askgame":
           break;
         }
         case "askgame":
-          // Send current (live) game
+          // Send current (live) game if not asked by opponent (!)
+          if (this.game.players.some(p => p.sid == data.from))
+            return;
           const myGame =
           {
             // Minimal game informations:
           const myGame =
           {
             // Minimal game informations:
index 0bc037a..f165b0a 100644 (file)
@@ -34,16 +34,20 @@ main
       .collapse
         div
           .button-group
       .collapse
         div
           .button-group
-            button(@click="cdisplay='live'") Live Challenges
-            button(@click="cdisplay='corr'") Correspondance challenges
+            button(@click="(e) => setDisplay('c','live',e)" class="active")
+              | Live Challenges
+            button(@click="(e) => setDisplay('c','corr',e)")
+              | Correspondance challenges
           ChallengeList(v-show="cdisplay=='live'"
             :challenges="filterChallenges('live')" @click-challenge="clickChallenge")
           ChallengeList(v-show="cdisplay=='corr'"
             :challenges="filterChallenges('corr')" @click-challenge="clickChallenge")
         div
           .button-group
           ChallengeList(v-show="cdisplay=='live'"
             :challenges="filterChallenges('live')" @click-challenge="clickChallenge")
           ChallengeList(v-show="cdisplay=='corr'"
             :challenges="filterChallenges('corr')" @click-challenge="clickChallenge")
         div
           .button-group
-            button(@click="pdisplay='players'") Players
-            button(@click="pdisplay='chat'") Chat
+            button(@click="(e) => setDisplay('p','players',e)" class="active")
+              | Players
+            button(@click="(e) => setDisplay('p','chat',e)")
+              | Chat
           #players(v-show="pdisplay=='players'")
             p(v-for="p in uniquePlayers")
               span(:class="{anonymous: !!p.count}")
           #players(v-show="pdisplay=='players'")
             p(v-for="p in uniquePlayers")
               span(:class="{anonymous: !!p.count}")
@@ -55,8 +59,10 @@ main
             Chat(:players="[]")
         div
           .button-group
             Chat(:players="[]")
         div
           .button-group
-            button(@click="gdisplay='live'") Live games
-            button(@click="gdisplay='corr'") Correspondance games
+            button(@click="(e) => setDisplay('g','live',e)" class="active")
+              | Live games
+            button(@click="(e) => setDisplay('g','corr',e)")
+              | Correspondance games
           GameList(v-show="gdisplay=='live'" :games="filterGames('live')"
             @show-game="showGame")
           GameList(v-show="gdisplay=='corr'" :games="filterGames('corr')"
           GameList(v-show="gdisplay=='live'" :games="filterGames('live')"
             @show-game="showGame")
           GameList(v-show="gdisplay=='corr'" :games="filterGames('corr')"
@@ -222,6 +228,14 @@ export default {
         url += "?rid=" + g.rid;
       this.$router.push(url);
     },
         url += "?rid=" + g.rid;
       this.$router.push(url);
     },
+    setDisplay: function(letter, type, e) {
+      this[letter + "display"] = type;
+      e.target.classList.add("active");
+      if (!!e.target.previousElementSibling)
+        e.target.previousElementSibling.classList.remove("active");
+      else
+        e.target.nextElementSibling.classList.remove("active");
+    },
     getVname: function(vid) {
       const variant = this.st.variants.find(v => v.id == vid);
       // this.st.variants might be uninitialized (variant == null)
     getVname: function(vid) {
       const variant = this.st.variants.find(v => v.id == vid);
       // this.st.variants might be uninitialized (variant == null)
@@ -347,7 +361,7 @@ export default {
         {
           // Receive game from some player (+sid)
           // NOTE: it may be correspondance (if newgame while we are connected)
         {
           // Receive game from some player (+sid)
           // NOTE: it may be correspondance (if newgame while we are connected)
-          if (!this.games.some(g => g.id == data.game.id)) //ignore duplicates
+          if (this.games.every(g => g.id != data.game.id)) //ignore duplicates
           {
             let newGame = data.game;
             newGame.type = this.classifyObject(data.game);
           {
             let newGame = data.game;
             newGame.type = this.classifyObject(data.game);
@@ -619,6 +633,8 @@ export default {
 </script>
 
 <style lang="sass" scoped>
 </script>
 
 <style lang="sass" scoped>
+.active
+  color: #42a983
 #newGame
   display: block
   margin: 10px auto 5px auto
 #newGame
   display: block
   margin: 10px auto 5px auto
index a3331d7..b0abd8d 100644 (file)
@@ -112,7 +112,8 @@ export default {
 };
 </script>
 
 };
 </script>
 
-<style lang="sass" scoped>
+<!-- NOTE: not scoped here, because HTML is injected (TODO) -->
+<style lang="sass">
 //.section-content
 //  *
 //    margin-left: auto
 //.section-content
 //  *
 //    margin-left: auto