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)"
27 import { store } from "@/store";
28 import { GameStorage } from "@/utils/gameStorage";
31 props: ["games", "showBoth"],
35 deleted: {}, //mark deleted games
36 showCadence: window.innerWidth >= 425 //TODO: arbitrary value
40 // timeout to avoid calling too many time the adjust method
41 let timeoutLaunched = false;
42 window.addEventListener("resize", () => {
43 if (!timeoutLaunched) {
44 timeoutLaunched = true;
46 this.showCadence = window.innerWidth >= 425;
47 timeoutLaunched = false;
53 sortedGames: function() {
54 // Show in order: games where it's my turn, my running games, my games, other games
55 let minCreated = Number.MAX_SAFE_INTEGER;
57 const isMyTurn = (g, myColor) => {
58 const rem = g.movesCount % 2;
60 (rem == 0 && myColor == "w") ||
61 (rem == 1 && myColor == "b")
64 let augmentedGames = this.games
65 .filter(g => !this.deleted[g.id])
68 let myColor = undefined;
71 p => p.uid == this.st.user.id || p.sid == this.st.user.sid
76 g.players[0].uid == this.st.user.id ||
77 g.players[0].sid == this.st.user.sid
82 if (isMyTurn(g, myColor)) priority++;
85 if (g.created < minCreated) minCreated = g.created;
86 if (g.created > maxCreated) maxCreated = g.created;
87 return Object.assign({}, g, {
89 myTurn: priority == 3,
93 const deltaCreated = maxCreated - minCreated;
94 return augmentedGames.sort((g1, g2) => {
96 g2.priority - g1.priority + (g2.created - g1.created) / deltaCreated
102 player_s: function(g) {
105 (g.players[0].name || "@nonymous") +
107 (g.players[1].name || "@nonymous")
110 this.st.user.sid == g.players[0].sid ||
111 this.st.user.id == g.players[0].uid
113 return g.players[1].name || "@nonymous";
114 return g.players[0].name || "@nonymous";
116 scoreClass: function(g) {
117 if (g.score == "*" || !g.myColor) return {};
118 // Ok it's my finished game: determine if I won, drew or lost.
122 res[g.myColor == "w" ? "won" : "lost"] = true;
125 res[g.myColor == "b" ? "won" : "lost"] = true;
130 // default case: "?" for unknown finished
132 res["unknown"] = true;
136 deleteGame: function(game, e) {
139 game.players.some(p =>
140 p.sid == this.st.user.sid ||
141 p.uid == this.st.user.id
144 if (confirm(this.st.tr["Remove game?"])) {
148 this.$set(this.deleted, game.id, true);
159 <style lang="sass" scoped>
160 // NOTE: the style applied to <tr> element doesn't work
162 background-color: #fcd785
166 background-color: #f5b7b1
168 background-color: lightgreen
170 background-color: lightblue
172 background-color: lightgrey