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 { ImportgameStorage } from "@/utils/importgameStorage";
32 import { ajax } from "@/utils/ajax";
35 props: ["games", "showBoth"],
39 deleted: {}, //mark deleted games
40 showCadence: window.innerWidth >= 425 //TODO: arbitrary value
44 // timeout to avoid calling too many time the adjust method
45 let timeoutLaunched = false;
46 window.addEventListener("resize", () => {
47 if (!timeoutLaunched) {
48 timeoutLaunched = true;
50 this.showCadence = window.innerWidth >= 425;
51 timeoutLaunched = false;
57 player_s: function(g) {
60 (g.players[0].name || "@nonymous") +
62 (g.players[1].name || "@nonymous")
65 this.st.user.sid == g.players[0].sid ||
66 this.st.user.id == g.players[0].id
68 return g.players[1].name || "@nonymous";
70 return g.players[0].name || "@nonymous";
72 sortedGames: function() {
73 // Show in order: it's my turn, running games, completed games
74 let minCreated = Number.MAX_SAFE_INTEGER;
76 let remGames = this.games.filter(g => !this.deleted[g.id]);
77 remGames.forEach(g => {
78 if (g.created < minCreated) minCreated = g.created;
79 if (g.created > maxCreated) maxCreated = g.created;
83 if (!!g.myColor) g.priority++;
84 if (!!g.myTurn) g.priority++;
87 const deltaCreated = maxCreated - minCreated;
88 return remGames.sort((g1, g2) => {
90 g2.priority - g1.priority +
91 // Modulate with creation time (value in ]0,1[)
92 (g2.created - g1.created) / (deltaCreated + 1)
96 scoreClass: function(g) {
97 if (g.score == "*" || !g.myColor) return {};
98 // Ok it's my finished game: determine if I won, drew or lost.
102 res[g.myColor == "w" ? "won" : "lost"] = true;
105 res[g.myColor == "b" ? "won" : "lost"] = true;
110 // default case: "?" for unknown finished
112 res["unknown"] = true;
116 deleteGame: function(game, e) {
119 game.players.some(p =>
120 p.sid == this.st.user.sid || p.id == this.st.user.id
126 : "Abort and remove game?";
127 if (confirm(this.st.tr[message])) {
128 const afterDelete = () => {
129 if (game.score == "*" && game.type != "import")
130 this.$emit("abortgame", game);
131 this.$set(this.deleted, game.id, true);
133 if (game.type == "live")
134 // Effectively remove game:
135 GameStorage.remove(game.id, afterDelete);
136 else if (game.type == "import")
137 ImportgameStorage.remove(game.id, afterDelete);
140 game.players[0].id == this.st.user.id
143 game["deletedBy" + mySide] = true;
144 // Mark the game for deletion on server
145 // If both people mark it, it is deleted
152 newObj: { removeFlag: true }
166 <style lang="sass" scoped>
171 // NOTE: the style applied to <tr> element doesn't work
173 background-color: #fcd785
177 background-color: #f5b7b1
179 background-color: lightgreen
181 background-color: lightblue
183 background-color: lightgrey