From: Benjamin Auder Date: Sat, 1 Feb 2020 22:51:25 +0000 (+0100) Subject: TODO: fix draw logic X-Git-Url: https://git.auder.net/images/assets/doc/pieces/current/gitweb.css?a=commitdiff_plain;h=41c80bb63b85b2696d3925c10784c3d7bb5d2aa3;p=vchess.git TODO: fix draw logic --- diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 2bf1fbdb..595f9aa3 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -26,8 +26,7 @@ div#baseGame(tabindex=-1 @click="() => focusBg()" MoveList(v-if="showMoves" :score="game.score" :message="game.scoreMsg" :firstNum="firstMoveNumber" :moves="moves" :cursor="cursor" @goto-move="gotoMove") - // TODO: clearer required ?! - .clearer + .clearer - diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index 25da6f14..1b7fd6bc 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -363,7 +363,7 @@ export default { }; - diff --git a/client/src/components/GameList.vue b/client/src/components/GameList.vue index 4233a01b..5ab61cc3 100644 --- a/client/src/components/GameList.vue +++ b/client/src/components/GameList.vue @@ -50,7 +50,7 @@ export default { priority++; } } - return Object.assign({}, g, {priority: priority, myTurn: priority==2}); + return Object.assign({}, g, {priority: priority, myTurn: priority==3}); }); return augmentedGames.sort((g1,g2) => { return g2.priority - g1.priority; }); }, @@ -58,8 +58,8 @@ export default { }; - diff --git a/client/src/components/Language.vue b/client/src/components/Language.vue index ac4faa79..c701e590 100644 --- a/client/src/components/Language.vue +++ b/client/src/components/Language.vue @@ -29,7 +29,7 @@ export default { }; }, mounted: function() { - // TODO: better style would be in pug directly, but how? + // NOTE: better style would be in pug directly, but how? document.querySelectorAll("#langSelect > option").forEach(opt => { if (opt.value == this.st.lang) opt.selected = true; diff --git a/client/src/components/MoveList.vue b/client/src/components/MoveList.vue index 1209dd99..28d0d009 100644 --- a/client/src/components/MoveList.vue +++ b/client/src/components/MoveList.vue @@ -58,6 +58,14 @@ export default { diff --git a/client/src/components/Settings.vue b/client/src/components/Settings.vue index 6034ab45..92b463ef 100644 --- a/client/src/components/Settings.vue +++ b/client/src/components/Settings.vue @@ -81,7 +81,7 @@ export default { return; //no board on page const k = document.getElementById("myRange").value; const movesWidth = (window.innerWidth >= 768 ? 280 : 0); - const minBoardWidth = 240; //TODO: same + const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary... // Value of 0 is board min size; 100 is window.width [- movesWidth] const boardSize = minBoardWidth + k * (window.innerWidth - (movesWidth+minBoardWidth)) / 100; diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 30fbc39b..e6cb1e70 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -135,6 +135,9 @@ export default { methods: { // O.1] Ask server for room composition: roomInit: function() { + // Notify the room only now that I connected, because + // messages might be lost otherwise (if game loading is slow) + this.st.conn.send(JSON.stringify({code:"connect"})); this.st.conn.send(JSON.stringify({code:"pollclients"})); }, isConnected: function(index) { @@ -182,13 +185,12 @@ export default { } case "identity": { - let player = this.people[data.user.sid]; // NOTE: sometimes player.id fails because player is undefined... // Probably because the event was meant for Hall? - if (!player) + if (!this.people[data.user.sid]) return; - player.id = data.user.id; - player.name = data.user.name; + this.$set(this.people, data.user.sid, + {id: data.user.id, name: data.user.name}); // Sending last state only for live games: corr games are complete if (this.game.type == "live" && this.game.oppsid == data.user.sid) { @@ -225,7 +227,7 @@ export default { game:myGame, target:data.from})); break; case "newmove": - this.$set(this.game, "moveToPlay", data.move); //TODO: Vue3... + this.$set(this.game, "moveToPlay", data.move); break; case "lastate": //got opponent infos about last move { @@ -245,10 +247,12 @@ export default { this.gameOver("1/2", data.message); break; case "drawoffer": - this.drawOffer = "received"; //TODO: observers don't know who offered draw + // NOTE: observers don't know who offered draw + this.drawOffer = "received"; break; case "askfullgame": - this.st.conn.send(JSON.stringify({code:"fullgame", game:this.game, target:data.from})); + this.st.conn.send(JSON.stringify({code:"fullgame", + game:this.game, target:data.from})); break; case "fullgame": // Callback "roomInit" to poll clients only after game is loaded @@ -306,13 +310,7 @@ export default { }); this.gameOver("1/2", message); } - else if (this.drawOffer == "sent") - { - this.drawOffer = ""; - if (this.game.type == "corr") - GameStorage.update(this.gameRef.id, {drawOffer: false}); - } - else + else if (this.drawOffer == "") //no effect if drawOffer == "sent" { if (!confirm("Offer draw?")) return; @@ -321,8 +319,7 @@ export default { if (sid != this.st.user.sid) this.st.conn.send(JSON.stringify({code:"drawoffer", target:sid})); }); - if (this.game.type == "corr") - GameStorage.update(this.gameRef.id, {drawOffer: true}); + GameStorage.update(this.gameRef.id, {drawOffer: true}); } }, abortGame: function() { @@ -578,7 +575,7 @@ export default { }; - diff --git a/client/src/views/MyGames.vue b/client/src/views/MyGames.vue index 60792542..a8d9e127 100644 --- a/client/src/views/MyGames.vue +++ b/client/src/views/MyGames.vue @@ -57,7 +57,3 @@ export default { }, }; - - diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index e1ef8fef..82a4a40f 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -111,7 +111,7 @@ export default { }; -