X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=e16fa2f8b7a8fc7991d4cae61bbc0faba01fb264;hb=050ae3b58673dfa1ed41bf78d935fe95ec9e74c5;hp=7b14055f969f595bbb217fb7f7f9d14e82bec646;hpb=63ca2b89cfe577efd168c6b2e26750cb01b66d64;p=vchess.git
diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue
index 7b14055f..e16fa2f8 100644
--- a/client/src/views/Game.vue
+++ b/client/src/views/Game.vue
@@ -1,16 +1,25 @@
main
+ 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"
+ @newchat-sent="finishSendChat" @newchat-received="processChat")
.row
- #chat.col-sm-12.col-md-4.col-md-offset-4
- Chat(:players="game.players" @newchat="processChat")
- .row
- .col-sm-12
+ #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
+ button#chatBtn(onClick="doClick('modalChat')") Chat
#actions(v-if="game.mode!='analyze' && game.score=='*'")
button(@click="offerDraw") Draw
button(@click="abortGame") Abort
button(@click="resign") Resign
- div Names: {{ game.players[0].name }} - {{ game.players[1].name }}
- div(v-if="game.score=='*'") Time: {{ virtualClocks[0] }} - {{ virtualClocks[1] }}
+ #playersInfo
+ p
+ span.name(:class="{connected: isConnected(0)}") {{ game.players[0].name }}
+ span.time(v-if="game.score=='*'") {{ virtualClocks[0] }}
+ span.split-names -
+ span.name(:class="{connected: isConnected(1)}") {{ game.players[1].name }}
+ span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
BaseGame(:game="game" :vr="vr" ref="basegame"
@newmove="processMove" @gameover="gameOver")
@@ -122,6 +131,12 @@ export default {
roomInit: function() {
this.st.conn.send(JSON.stringify({code:"pollclients"}));
},
+ isConnected: function(index) {
+ const name = this.game.players[index].name;
+ if (this.st.user.name == name)
+ return true;
+ return this.people.some(p => p.name == name);
+ },
socketMessageListener: function(msg) {
const data = JSON.parse(msg.data);
switch (data.code)
@@ -256,7 +271,7 @@ export default {
}
},
offerDraw: function() {
- if (this.drawOffer == "received")
+ if (["received","threerep"].includes(this.drawOffer))
{
if (!confirm("Accept draw?"))
return;
@@ -264,7 +279,10 @@ export default {
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")
{
@@ -364,6 +382,8 @@ export default {
end: s.end,
};
});
+ // Also sort chat messages (if any)
+ game.chats.sort( (c1,c2) => { return c2.added - c1.added; });
}
const myIdx = game.players.findIndex(p => {
return p.sid == this.st.user.sid || p.uid == this.st.user.id;
@@ -419,18 +439,20 @@ export default {
},
// 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 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)
@@ -458,7 +480,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:
- 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")
{
@@ -503,12 +526,19 @@ export default {
? 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});
},
+ 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;
@@ -525,9 +555,7 @@ export default {