From: Benjamin Auder Date: Mon, 16 Mar 2020 02:40:33 +0000 (+0100) Subject: Refactor models (merge Players in Games), add cursor to correspondance games. Finishe... X-Git-Url: https://git.auder.net/variants/Apocalypse/scripts/current/doc/html/mini-custom.min.css?a=commitdiff_plain;h=0234201fb338fc239d6f613c677fa932c7c3697c;p=vchess.git Refactor models (merge Players in Games), add cursor to correspondance games. Finished but not working yet --- diff --git a/client/src/components/GameList.vue b/client/src/components/GameList.vue index 1a50e956..549e2a1d 100644 --- a/client/src/components/GameList.vue +++ b/client/src/components/GameList.vue @@ -62,7 +62,7 @@ export default { ); if ( this.st.user.sid == g.players[0].sid || - this.st.user.id == g.players[0].uid + this.st.user.id == g.players[0].id ) return g.players[1].name || "@nonymous"; return g.players[0].name || "@nonymous"; @@ -113,8 +113,7 @@ export default { if ( // My game ? game.players.some(p => - p.sid == this.st.user.sid || - p.uid == this.st.user.id + p.sid == this.st.user.sid || p.id == this.st.user.id ) ) { const message = @@ -131,7 +130,7 @@ export default { GameStorage.remove(game.id, afterDelete); else { const mySide = - game.players[0].uid == this.st.user.id + game.players[0].id == this.st.user.id ? "White" : "Black"; game["deletedBy" + mySide] = true; diff --git a/client/src/views/Analyse.vue b/client/src/views/Analyse.vue index f662d614..becc4de0 100644 --- a/client/src/views/Analyse.vue +++ b/client/src/views/Analyse.vue @@ -80,10 +80,10 @@ export default { .catch((err) => { this.alertAndQuit("Mispelled variant name", true); }); }, loadGame: function(orientation) { - // NOTE: no need to set score (~unused) this.game.vname = this.gameRef.vname; this.game.fenStart = this.gameRef.fen; this.game.fen = this.gameRef.fen; + this.game.score = "*"; //never change this.curFen = this.game.fen; this.adjustFenSize(); this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn; diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index e7db9729..a401e464 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -352,7 +352,7 @@ export default { isConnected: function(index) { const player = this.game.players[index]; // Is it me ? In this case no need to bother with focus - if (this.st.user.sid == player.sid || this.st.user.id == player.uid) + if (this.st.user.sid == player.sid || this.st.user.id == player.id) // Still have to check for name (because of potential multi-accounts // on same browser, although this should be rare...) return (!this.st.user.name || this.st.user.name == player.name); @@ -365,9 +365,9 @@ export default { ) || ( - player.uid && + player.id && Object.values(this.people).some(p => - p.id == player.uid && p.focus) + p.id == player.id && p.focus) ) ); }, @@ -415,7 +415,7 @@ export default { { data: data, targets: this.game.players.map(p => { - return { sid: p.sid, uid: p.uid }; + return { sid: p.sid, id: p.id }; }) } ); @@ -693,7 +693,7 @@ export default { this.addAndGotoLiveGame(gameInfo); } else if ( gameType == "corr" && - gameInfo.players.some(p => p.uid == this.st.user.id) + gameInfo.players.some(p => p.id == this.st.user.id) ) { this.$router.push("/game/" + gameInfo.id); } else { @@ -918,7 +918,7 @@ export default { const gtype = this.getGameType(game); const tc = extractTime(game.cadence); const myIdx = game.players.findIndex(p => { - return p.sid == this.st.user.sid || p.uid == this.st.user.id; + return p.sid == this.st.user.sid || p.id == this.st.user.id; }); const mycolor = [undefined, "w", "b"][myIdx + 1]; //undefined for observers if (!game.chats) game.chats = []; //live games don't have chat history @@ -1031,7 +1031,7 @@ export default { // opponent sid not strictly required (or available), but easier // at least oppsid or oppid is available anyway: oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid, - oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].uid + oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].id }, game, ); @@ -1085,6 +1085,9 @@ export default { g.moves.forEach(m => { m.squares = JSON.parse(m.squares); }); + g.players = [{ id: g.white }, { id: g.black }]; + delete g["white"]; + delete g["black"]; afterRetrieval(g); } } @@ -1366,7 +1369,7 @@ export default { this.game.scoreMsg = scoreMsg; this.$set(this.game, "scoreMsg", scoreMsg); const myIdx = this.game.players.findIndex(p => { - return p.sid == this.st.user.sid || p.uid == this.st.user.id; + return p.sid == this.st.user.sid || p.id == this.st.user.id; }); if (myIdx >= 0) { // OK, I play in this game diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index f9519fe2..b9262d12 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -185,12 +185,17 @@ main :showBoth="true" @show-game="showGame" ) - GameList( - v-show="gdisplay=='corr'" - :games="filterGames('corr')" - :showBoth="true" - @show-game="showGame" - ) + div(v-show="gdisplay=='corr'") + GameList( + :games="filterGames('corr')" + :showBoth="true" + @show-game="showGame" + ) + button#loadMoreBtn( + v-if="hasMore" + @click="loadMore()" + ) + | {{ st.tr["Load more"] }}