'update'
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 31 Jan 2020 15:07:14 +0000 (16:07 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 31 Jan 2020 15:07:14 +0000 (16:07 +0100)
client/src/components/BaseGame.vue
client/src/components/Chat.vue
client/src/views/Game.vue

index 324e534..635ca64 100644 (file)
@@ -6,21 +6,22 @@ div#baseGame(tabindex=-1 @click="() => focusBg()" @keydown="handleKeys")
       label.modal-close(for="modalEog")
       h3#eogMessage.section {{ endgameMessage }}
   .row
       label.modal-close(for="modalEog")
       h3#eogMessage.section {{ endgameMessage }}
   .row
-    #boardContainer.col-sm-12.col-md-9
-      Board(:vr="vr" :last-move="lastMove" :analyze="game.mode=='analyze'"
-        :user-color="game.mycolor" :orientation="orientation"
-        :vname="game.vname" @play-move="play")
-      #controls
-        button(@click="gotoBegin") <<
-        button(@click="() => undo()") <
-        button(@click="flip") &#8645;
-        button(@click="() => play()") >
-        button(@click="gotoEnd") >>
-      #pgnDiv
-        a#download(href="#")
-        button(@click="download") {{ st.tr["Download PGN"] }}
-        button(v-if="game.mode!='analyze'" @click="analyzePosition")
-          | {{ st.tr["Analyze"] }}
+    .col-sm-12.col-md-9
+      #boardContainer
+        Board(:vr="vr" :last-move="lastMove" :analyze="game.mode=='analyze'"
+          :user-color="game.mycolor" :orientation="orientation"
+          :vname="game.vname" @play-move="play")
+        #controls
+          button(@click="gotoBegin") <<
+          button(@click="() => undo()") <
+          button(@click="flip") &#8645;
+          button(@click="() => play()") >
+          button(@click="gotoEnd") >>
+        #pgnDiv
+          a#download(href="#")
+          button(@click="download") {{ st.tr["Download PGN"] }}
+          button(v-if="game.mode!='analyze'" @click="analyzePosition")
+            | {{ st.tr["Analyze"] }}
     .col-sm-12.col-md-3
       MoveList(v-if="showMoves" :score="game.score" :message="game.scoreMsg"
         :firstNum="firstMoveNumber" :moves="moves" :cursor="cursor"
     .col-sm-12.col-md-3
       MoveList(v-if="showMoves" :score="game.score" :message="game.scoreMsg"
         :firstNum="firstMoveNumber" :moves="moves" :cursor="cursor"
index 8f1646f..5834cbe 100644 (file)
@@ -1,10 +1,12 @@
 <template lang="pug">
 <template lang="pug">
-.card
+div
   input#inputChat(type="text" :placeholder="st.tr['Type here']"
     @keyup.enter="sendChat")
   button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
   input#inputChat(type="text" :placeholder="st.tr['Type here']"
     @keyup.enter="sendChat")
   button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
-  p(v-for="chat in pastChats" :class="classObject(chat)" v-html="chat.name + ': ' + chat.msg")
-  p(v-for="chat in chats" :class="classObject(chat)" v-html="chat.name + ': ' + chat.msg")
+  p(v-for="chat in pastChats" :class="classObject(chat)"
+    v-html="chat.name + ': ' + chat.msg")
+  p(v-for="chat in chats" :class="classObject(chat)"
+    v-html="chat.name + ': ' + chat.msg")
 </template>
 
 <script>
 </template>
 
 <script>
@@ -29,6 +31,7 @@ export default {
       {
         this.chats.unshift({msg:data.msg,
           name:data.name || "@nonymous", sid:data.from});
       {
         this.chats.unshift({msg:data.msg,
           name:data.name || "@nonymous", sid:data.from});
+        this.$emit("newchat-received"); //data not required here
       }
     };
     const socketCloseListener = () => {
       }
     };
     const socketCloseListener = () => {
@@ -53,7 +56,7 @@ export default {
       chatInput.value = "";
       const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
         sid:this.st.user.sid};
       chatInput.value = "";
       const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
         sid:this.st.user.sid};
-      this.$emit("newchat", chat); //useful for corr games
+      this.$emit("newchat-sent", chat); //useful for corr games
       this.chats.unshift(chat);
       this.st.conn.send(JSON.stringify({
         code:"newchat", msg:chatTxt, name:chat.name}));
       this.chats.unshift(chat);
       this.st.conn.send(JSON.stringify({
         code:"newchat", msg:chatTxt, name:chat.name}));
index 2f33bc5..3c4ac08 100644 (file)
@@ -1,15 +1,18 @@
 <template lang="pug">
 main
 <template lang="pug">
 main
-  .row
-    #chat.col-sm-12.col-md-4.col-md-offset-4
+  input#modalChat.modal(type="checkbox" @change="toggleChat")
+  div(role="dialog" aria-labelledby="inputChat")
+    #chat.card
+      label.modal-close(for="modalChat")
       Chat(:players="game.players" :pastChats="game.chats"
       Chat(:players="game.players" :pastChats="game.chats"
-        @newchat="processChat")
+        @newchat-sent="finishSendChat" @newchat-received="processChat")
   .row
   .row
-    .col-sm-12
+    .col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
       #actions(v-if="game.mode!='analyze' && game.score=='*'")
         button(@click="offerDraw") Draw
         button(@click="abortGame") Abort
         button(@click="resign") Resign
       #actions(v-if="game.mode!='analyze' && game.score=='*'")
         button(@click="offerDraw") Draw
         button(@click="abortGame") Abort
         button(@click="resign") Resign
+      button#chatBtn(onClick="doClick('modalChat')") Chat
       div Names: {{ game.players[0].name }} - {{ game.players[1].name }}
       div(v-if="game.score=='*'") Time: {{ virtualClocks[0] }} - {{ virtualClocks[1] }}
   BaseGame(:game="game" :vr="vr" ref="basegame"
       div Names: {{ game.players[0].name }} - {{ game.players[1].name }}
       div(v-if="game.score=='*'") Time: {{ virtualClocks[0] }} - {{ virtualClocks[1] }}
   BaseGame(:game="game" :vr="vr" ref="basegame"
@@ -257,7 +260,7 @@ export default {
       }
     },
     offerDraw: function() {
       }
     },
     offerDraw: function() {
-      if (this.drawOffer == "received")
+      if (["received","threerep"].includes(this.drawOffer))
       {
         if (!confirm("Accept draw?"))
           return;
       {
         if (!confirm("Accept draw?"))
           return;
@@ -265,7 +268,10 @@ export default {
           if (p.sid != this.st.user.sid)
             this.st.conn.send(JSON.stringify({code:"draw", target:p.sid}));
         });
           if (p.sid != this.st.user.sid)
             this.st.conn.send(JSON.stringify({code:"draw", target:p.sid}));
         });
-        this.gameOver("1/2", "Mutual agreement");
+        const message = (this.drawOffer == "received"
+          ? "Mutual agreement"
+          : "Three repetitions");
+        this.gameOver("1/2", message);
       }
       else if (this.drawOffer == "sent")
       {
       }
       else if (this.drawOffer == "sent")
       {
@@ -422,18 +428,20 @@ export default {
     },
     // Post-process a move (which was just played)
     processMove: function(move) {
     },
     // Post-process a move (which was just played)
     processMove: function(move) {
-      if (!this.game.mycolor)
-        return; //I'm just an observer
-      // Update storage (corr or live)
+      // Update storage (corr or live) if I play in the game
       const colorIdx = ["w","b"].indexOf(move.color);
       // https://stackoverflow.com/a/38750895
       const colorIdx = ["w","b"].indexOf(move.color);
       // https://stackoverflow.com/a/38750895
-      const allowed_fields = ["appear", "vanish", "start", "end"];
-      const filtered_move = Object.keys(move)
-        .filter(key => allowed_fields.includes(key))
-        .reduce((obj, key) => {
-          obj[key] = move[key];
-          return obj;
-        }, {});
+      if (!!this.game.mycolor)
+      {
+        const allowed_fields = ["appear", "vanish", "start", "end"];
+        // NOTE: 'var' to see this variable outside this block
+        var filtered_move = Object.keys(move)
+          .filter(key => allowed_fields.includes(key))
+          .reduce((obj, key) => {
+            obj[key] = move[key];
+            return obj;
+          }, {});
+      }
       // Send move ("newmove" event) to people in the room (if our turn)
       let addTime = 0;
       if (move.color == this.game.mycolor)
       // Send move ("newmove" event) to people in the room (if our turn)
       let addTime = 0;
       if (move.color == this.game.mycolor)
@@ -461,7 +469,8 @@ export default {
       const nextIdx = ["w","b"].indexOf(this.vr.turn);
       // Since corr games are stored at only one location, update should be
       // done only by one player for each move:
       const nextIdx = ["w","b"].indexOf(this.vr.turn);
       // Since corr games are stored at only one location, update should be
       // done only by one player for each move:
-      if (this.game.type == "live" || move.color == this.game.mycolor)
+      if (!!this.game.mycolor &&
+        (this.game.type == "live" || move.color == this.game.mycolor))
       {
         if (this.game.type == "corr")
         {
       {
         if (this.game.type == "corr")
         {
@@ -506,12 +515,19 @@ export default {
         ? this.repeat[repIdx]+1
         : 1);
       if (this.repeat[repIdx] >= 3)
         ? this.repeat[repIdx]+1
         : 1);
       if (this.repeat[repIdx] >= 3)
-        this.drawOffer = "received"; //TODO: will print "mutual agreement"...
+        this.drawOffer = "threerep";
     },
     },
-    processChat: function(chat) {
+    toggleChat: function() {
+      document.getElementById("chatBtn").style.backgroundColor = "#e2e2e2";
+    },
+    finishSendChat: function(chat) {
       if (this.game.type == "corr")
         GameStorage.update(this.gameRef.id, {chat: chat});
     },
       if (this.game.type == "corr")
         GameStorage.update(this.gameRef.id, {chat: chat});
     },
+    processChat: function() {
+      if (!document.getElementById("inputChat").checked)
+        document.getElementById("chatBtn").style.backgroundColor = "#c5fefe";
+    },
     gameOver: function(score, scoreMsg) {
       this.game.mode = "analyze";
       this.game.score = score;
     gameOver: function(score, scoreMsg) {
       this.game.mode = "analyze";
       this.game.score = score;
@@ -547,11 +563,9 @@ export default {
     display: inline-block
     width: 33%
     margin: 0
     display: inline-block
     width: 33%
     margin: 0
+
 #chat
 #chat
-  margin-top: 5px
-  margin-bottom: 5px
-  >.card
-    max-width: 100%
-    margin: 0;
+  padding-top: 20px
+  max-width: 600px
   border: none;
 </style>
   border: none;
 </style>