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 player_s: function(g) {
59 (g.players[0].name || "@nonymous") +
61 (g.players[1].name || "@nonymous")
64 this.st.user.sid == g.players[0].sid ||
65 this.st.user.id == g.players[0].id
67 return g.players[1].name || "@nonymous";
68 return g.players[0].name || "@nonymous";
70 sortedGames: function() {
71 // Show in order: it's my turn, running games, completed games
72 let minCreated = Number.MAX_SAFE_INTEGER;
74 let remGames = this.games.filter(g => !this.deleted[g.id]);
75 remGames.forEach(g => {
76 if (g.created < minCreated) minCreated = g.created;
77 if (g.created > maxCreated) maxCreated = g.created;
81 if (!!g.myColor) g.priority++;
82 if (!!g.myTurn) g.priority++;
85 const deltaCreated = maxCreated - minCreated;
86 return remGames.sort((g1, g2) => {
88 g2.priority - g1.priority +
89 // Modulate with creation time (value in ]0,1[)
90 (g2.created - g1.created) / (deltaCreated + 1)
94 scoreClass: function(g) {
95 if (g.score == "*" || !g.myColor) return {};
96 // Ok it's my finished game: determine if I won, drew or lost.
100 res[g.myColor == "w" ? "won" : "lost"] = true;
103 res[g.myColor == "b" ? "won" : "lost"] = true;
108 // default case: "?" for unknown finished
110 res["unknown"] = true;
114 deleteGame: function(game, e) {
117 game.players.some(p =>
118 p.sid == this.st.user.sid || p.id == this.st.user.id
124 : "Abort and remove game?";
125 if (confirm(this.st.tr[message])) {
126 const afterDelete = () => {
127 if (game.score == "*") this.$emit("abortgame", game);
128 this.$set(this.deleted, game.id, true);
130 if (game.type == "live")
131 // Effectively remove game:
132 GameStorage.remove(game.id, afterDelete);
135 game.players[0].id == this.st.user.id
138 game["deletedBy" + mySide] = true;
139 // Mark the game for deletion on server
140 // If both people mark it, it is deleted
147 newObj: { removeFlag: 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