X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=ee151f3d282e500e0bea61befba4ba5fac4879dc;hb=8c5f5390efed4753d6ac1b7bf84dc9922dd0df7e;hp=a7096e5259615ff2ea56288584e3ece97ee00365;hpb=77c5096644d83aaae8ab1dd42a5cde524507cf9d;p=vchess.git diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index a7096e52..ee151f3d 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -5,18 +5,16 @@ main #chat.card label.modal-close(for="modalChat") #participants - span {{ Object.keys(people).length }} st.tr["participant(s):"] + span {{ Object.keys(people).length + " " + st.tr["participant(s):"] }} span(v-for="p in Object.values(people)" v-if="!!p.name") | {{ p.name }} span.anonymous(v-if="Object.values(people).some(p => !p.name)") | + @nonymous Chat(:players="game.players" :pastChats="game.chats" - @newchat-sent="finishSendChat" @newchat-received="processChat") + :newChat="newChat" @mychat="processChat") .row #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2 - span.variant-info - | {{ st.tr["Variant:"] + " " }} - span.vname {{ game.vname }} + span.variant-info {{ game.vname }} button#chatBtn(onClick="doClick('modalChat')") Chat #actions(v-if="game.score=='*'") button(@click="clickDraw" :class="{['draw-' + drawOffer]: true}") @@ -68,6 +66,7 @@ export default { people: {}, //players + observers lastate: undefined, //used if opponent send lastate before game is ready repeat: {}, //detect position repetition + newChat: "", }; }, watch: { @@ -223,25 +222,34 @@ export default { break; } case "askgame": - // Send current (live) game if not asked by opponent (!) - if (this.game.players.some(p => p.sid == data.from)) - return; - const myGame = + // Send current (live) game if I play in (not an observer), + // and not asked by opponent (!) + if (this.game.type == "live" + && this.game.players.some(p => p.sid == this.st.user.sid) + && this.game.players.every(p => p.sid != data.from)) { - // Minimal game informations: - id: this.game.id, - players: this.game.players, - vid: this.game.vid, - timeControl: this.game.timeControl, - }; - this.st.conn.send(JSON.stringify({code:"game", - game:myGame, target:data.from})); + const myGame = + { + // Minimal game informations: + id: this.game.id, + players: this.game.players, + vid: this.game.vid, + timeControl: this.game.timeControl, + }; + this.st.conn.send(JSON.stringify({code:"game", + game:myGame, target:data.from})); + } break; case "newmove": if (!!data.move.cancelDrawOffer) //opponent refuses draw this.drawOffer = ""; this.$set(this.game, "moveToPlay", data.move); break; + case "newchat": + this.newChat = data.chat; + if (!document.getElementById("modalChat").checked) + document.getElementById("chatBtn").style.backgroundColor = "#c5fefe"; + break; case "lastate": //got opponent infos about last move { this.lastate = data; @@ -612,15 +620,12 @@ export default { // TODO: this is called twice, once on opening an once on closing document.getElementById("chatBtn").style.backgroundColor = "#e2e2e2"; }, - finishSendChat: function(chat) { + processChat: function(chat) { + this.st.conn.send(JSON.stringify({code:"newchat", chat:chat})); // NOTE: anonymous chats in corr games are not stored on server (TODO?) if (this.game.type == "corr" && this.st.user.id > 0) GameStorage.update(this.gameRef.id, {chat: chat}); }, - processChat: function() { - if (!document.getElementById("modalChat").checked) - document.getElementById("chatBtn").style.backgroundColor = "#c5fefe"; - }, gameOver: function(score, scoreMsg) { this.game.score = score; this.game.scoreMsg = this.st.tr[(!!scoreMsg @@ -662,7 +667,6 @@ export default { margin-top: 10px button display: inline-block - width: 33% margin: 0 @media screen and (max-width: 767px) @@ -673,9 +677,8 @@ export default { margin-left: 30% .variant-info + font-weight: bold padding-right: 10px - .vname - font-weight: bold .name font-size: 1.5rem