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";
33 props: ["games", "showBoth"],
37 deleted: {}, //mark deleted games
38 showCadence: window.innerWidth >= 425 //TODO: arbitrary value
42 // timeout to avoid calling too many time the adjust method
43 let timeoutLaunched = false;
44 window.addEventListener("resize", () => {
45 if (!timeoutLaunched) {
46 timeoutLaunched = true;
48 this.showCadence = window.innerWidth >= 425;
49 timeoutLaunched = false;
55 sortedGames: function() {
56 // Show in order: games where it's my turn, my running games, my games, other games
57 let minCreated = Number.MAX_SAFE_INTEGER;
59 const isMyTurn = (g, myColor) => {
60 const rem = g.movesCount % 2;
62 (rem == 0 && myColor == "w") ||
63 (rem == 1 && myColor == "b")
66 let augmentedGames = this.games
67 .filter(g => !this.deleted[g.id])
70 let myColor = undefined;
73 p => p.uid == this.st.user.id || p.sid == this.st.user.sid
78 g.players[0].uid == this.st.user.id ||
79 g.players[0].sid == this.st.user.sid
84 if (isMyTurn(g, myColor)) priority++;
87 if (g.created < minCreated) minCreated = g.created;
88 if (g.created > maxCreated) maxCreated = g.created;
89 return Object.assign({}, g, {
91 myTurn: priority == 3,
95 const deltaCreated = maxCreated - minCreated;
96 return augmentedGames.sort((g1, g2) => {
98 g2.priority - g1.priority + (g2.created - g1.created) / deltaCreated
104 player_s: function(g) {
107 (g.players[0].name || "@nonymous") +
109 (g.players[1].name || "@nonymous")
112 this.st.user.sid == g.players[0].sid ||
113 this.st.user.id == g.players[0].uid
115 return g.players[1].name || "@nonymous";
116 return g.players[0].name || "@nonymous";
118 scoreClass: function(g) {
119 if (g.score == "*" || !g.myColor) return {};
120 // Ok it's my finished game: determine if I won, drew or lost.
124 res[g.myColor == "w" ? "won" : "lost"] = true;
127 res[g.myColor == "b" ? "won" : "lost"] = true;
132 // default case: "?" for unknown finished
134 res["unknown"] = true;
138 deleteGame: function(game, e) {
141 game.players.some(p =>
142 p.sid == this.st.user.sid ||
143 p.uid == this.st.user.id
146 if (confirm(this.st.tr["Remove game?"])) {
150 this.$set(this.deleted, game.id, true);
161 <style lang="sass" scoped>
166 // NOTE: the style applied to <tr> element doesn't work
168 background-color: #fcd785
172 background-color: #f5b7b1
174 background-color: lightgreen
176 background-color: lightblue
178 background-color: lightgrey