3 table.game-list(v-if="games.length > 0")
6 th {{ st.tr["Variant"] }}
7 th {{ st.tr[showBoth ? "Players" : "Versus"] }}
8 th(v-if="showCadence") {{ st.tr["Cadence"] }}
9 th {{ st.tr["Result"] }}
12 v-for="g in sortedGames"
13 @click="$emit('show-game',g)"
14 :class="{'my-turn': g.myTurn}"
18 td(v-if="showCadence") {{ g.cadence }}
20 :class="scoreClass(g)"
21 @click="deleteGame(g,$event)"
25 | {{ st.tr["No games found :( Send a challenge!"] }}
29 import { store } from "@/store";
30 import { GameStorage } from "@/utils/gameStorage";
31 import { ajax } from "@/utils/ajax";
34 props: ["games", "showBoth"],
38 deleted: {}, //mark deleted games
39 showCadence: window.innerWidth >= 425 //TODO: arbitrary value
43 // timeout to avoid calling too many time the adjust method
44 let timeoutLaunched = false;
45 window.addEventListener("resize", () => {
46 if (!timeoutLaunched) {
47 timeoutLaunched = true;
49 this.showCadence = window.innerWidth >= 425;
50 timeoutLaunched = false;
56 sortedGames: function() {
57 // Show in order: games where it's my turn, my running games, my games, other games
58 let minCreated = Number.MAX_SAFE_INTEGER;
60 const isMyTurn = (g, myColor) => {
61 const rem = g.movesCount % 2;
63 (rem == 0 && myColor == "w") ||
64 (rem == 1 && myColor == "b")
67 let augmentedGames = this.games
68 .filter(g => !this.deleted[g.id])
71 let myColor = undefined;
74 p => p.uid == this.st.user.id || p.sid == this.st.user.sid
79 g.players[0].uid == this.st.user.id ||
80 g.players[0].sid == this.st.user.sid
85 if (g.turn == myColor || isMyTurn(g, myColor)) priority++;
88 if (g.created < minCreated) minCreated = g.created;
89 if (g.created > maxCreated) maxCreated = g.created;
90 return Object.assign({}, g, {
92 myTurn: priority == 3,
96 const deltaCreated = maxCreated - minCreated;
97 return augmentedGames.sort((g1, g2) => {
99 g2.priority - g1.priority + (g2.created - g1.created) / deltaCreated
105 player_s: function(g) {
108 (g.players[0].name || "@nonymous") +
110 (g.players[1].name || "@nonymous")
113 this.st.user.sid == g.players[0].sid ||
114 this.st.user.id == g.players[0].uid
116 return g.players[1].name || "@nonymous";
117 return g.players[0].name || "@nonymous";
119 scoreClass: function(g) {
120 if (g.score == "*" || !g.myColor) return {};
121 // Ok it's my finished game: determine if I won, drew or lost.
125 res[g.myColor == "w" ? "won" : "lost"] = true;
128 res[g.myColor == "b" ? "won" : "lost"] = true;
133 // default case: "?" for unknown finished
135 res["unknown"] = true;
139 deleteGame: function(game, e) {
142 game.players.some(p =>
143 p.sid == this.st.user.sid ||
144 p.uid == this.st.user.id
150 : "Abort and remove game?";
151 if (confirm(this.st.tr[message])) {
152 const afterDelete = () => {
153 if (game.score == "*") this.$emit("abortgame", game);
154 this.$set(this.deleted, game.id, true);
156 if (game.type == "live")
157 // Effectively remove game:
158 GameStorage.remove(game.id, afterDelete);
161 game.players[0].uid == this.st.user.id
164 game["deletedBy" + mySide] = true;
165 // Mark the game for deletion on server
166 // If both people mark it, it is deleted
173 newObj: { removeFlag: true }
187 <style lang="sass" scoped>
192 // NOTE: the style applied to <tr> element doesn't work
194 background-color: #fcd785
198 background-color: #f5b7b1
200 background-color: lightgreen
202 background-color: lightblue
204 background-color: lightgrey