Fix games rendering
[vchess.git] / client / src / views / Game.vue
1 <template lang="pug">
2 main
3 input#modalInfo.modal(type="checkbox")
4 div#infoDiv(
5 role="dialog"
6 data-checkbox="modalInfo"
7 )
8 .card.text-center
9 label.modal-close(for="modalInfo")
10 p(v-html="infoMessage")
11 input#modalChat.modal(
12 type="checkbox"
13 @click="resetChatColor()"
14 )
15 div#chatWrap(
16 role="dialog"
17 data-checkbox="modalChat"
18 )
19 .card
20 label.modal-close(for="modalChat")
21 #participants
22 span {{ st.tr["Participant(s):"] }}
23 span(
24 v-for="p in Object.values(people)"
25 v-if="p.focus && !!p.name"
26 )
27 | {{ p.name }}
28 span.anonymous(
29 v-if="Object.values(people).some(p => p.focus && !p.name)"
30 )
31 | + @nonymous
32 Chat(
33 ref="chatcomp"
34 :players="game.players"
35 :pastChats="game.chats"
36 :newChat="newChat"
37 @mychat="processChat"
38 @chatcleared="clearChat"
39 )
40 input#modalConfirm.modal(type="checkbox")
41 div#confirmDiv(role="dialog")
42 .card
43 .diagram(
44 v-if="!!vr && ['all','byrow'].includes(vr.showMoves)"
45 v-html="curDiag"
46 )
47 p.text-center(v-else)
48 span {{ st.tr["Move played:"] + " " }}
49 span.bold {{ moveNotation }}
50 br
51 span {{ st.tr["Are you sure?"] }}
52 .button-group#buttonsConfirm
53 // onClick for acceptBtn: set dynamically
54 button.acceptBtn
55 span {{ st.tr["Validate"] }}
56 button.refuseBtn(@click="cancelMove()")
57 span {{ st.tr["Cancel"] }}
58 .row
59 #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
60 span.variant-cadence {{ game.cadence }}
61 span.variant-name {{ game.vname }}
62 span#nextGame(
63 v-if="nextIds.length > 0"
64 @click="showNextGame()"
65 )
66 | {{ st.tr["Next_g"] }}
67 button#chatBtn.tooltip(
68 onClick="window.doClick('modalChat')"
69 aria-label="Chat"
70 )
71 img(src="/images/icons/chat.svg")
72 #actions(v-if="game.score=='*'")
73 button.tooltip(
74 @click="clickDraw()"
75 :class="{['draw-' + drawOffer]: true}"
76 :aria-label="st.tr['Draw']"
77 )
78 img(src="/images/icons/draw.svg")
79 button.tooltip(
80 v-if="!!game.mycolor"
81 @click="abortGame()"
82 :aria-label="st.tr['Abort']"
83 )
84 img(src="/images/icons/abort.svg")
85 button.tooltip(
86 v-if="!!game.mycolor"
87 @click="resign()"
88 :aria-label="st.tr['Resign']"
89 )
90 img(src="/images/icons/resign.svg")
91 button.tooltip(
92 v-else
93 @click="clickRematch()"
94 :class="{['rematch-' + rematchOffer]: true}"
95 :aria-label="st.tr['Rematch']"
96 )
97 img(src="/images/icons/rematch.svg")
98 #playersInfo
99 p
100 span.name(:class="{connected: isConnected(0)}")
101 | {{ game.players[0].name || "@nonymous" }}
102 span.time(
103 v-if="game.score=='*'"
104 :class="{yourturn: !!vr && vr.turn == 'w'}"
105 )
106 span.time-left {{ virtualClocks[0][0] }}
107 span.time-separator(v-if="!!virtualClocks[0][1]") :
108 span.time-right(v-if="!!virtualClocks[0][1]")
109 | {{ virtualClocks[0][1] }}
110 span.split-names -
111 span.name(:class="{connected: isConnected(1)}")
112 | {{ game.players[1].name || "@nonymous" }}
113 span.time(
114 v-if="game.score=='*'"
115 :class="{yourturn: !!vr && vr.turn == 'b'}"
116 )
117 span.time-left {{ virtualClocks[1][0] }}
118 span.time-separator(v-if="!!virtualClocks[1][1]") :
119 span.time-right(v-if="!!virtualClocks[1][1]")
120 | {{ virtualClocks[1][1] }}
121 BaseGame(
122 ref="basegame"
123 :game="game"
124 @newmove="processMove"
125 )
126 </template>
127
128 <script>
129 import BaseGame from "@/components/BaseGame.vue";
130 import Chat from "@/components/Chat.vue";
131 import { store } from "@/store";
132 import { GameStorage } from "@/utils/gameStorage";
133 import { ppt } from "@/utils/datetime";
134 import { ajax } from "@/utils/ajax";
135 import { extractTime } from "@/utils/timeControl";
136 import { getRandString } from "@/utils/alea";
137 import { getScoreMessage } from "@/utils/scoring";
138 import { getFullNotation } from "@/utils/notation";
139 import { getDiagram } from "@/utils/printDiagram";
140 import { processModalClick } from "@/utils/modalClick";
141 import { playMove, getFilteredMove } from "@/utils/playUndo";
142 import { ArrayFun } from "@/utils/array";
143 import params from "@/parameters";
144 export default {
145 name: "my-game",
146 components: {
147 BaseGame,
148 Chat
149 },
150 data: function() {
151 return {
152 st: store.state,
153 gameRef: {
154 // rid = remote (socket) ID
155 id: "",
156 rid: ""
157 },
158 nextIds: [],
159 game: {}, //passed to BaseGame
160 // virtualClocks will be initialized from true game.clocks
161 virtualClocks: [],
162 vr: null, //"variant rules" object initialized from FEN
163 drawOffer: "",
164 infoMessage: "",
165 rematchOffer: "",
166 lastateAsked: false,
167 people: {}, //players + observers
168 lastate: undefined, //used if opponent send lastate before game is ready
169 repeat: {}, //detect position repetition
170 curDiag: "", //for corr moves confirmation
171 newChat: "",
172 conn: null,
173 roomInitialized: false,
174 // If newmove has wrong index: ask fullgame again:
175 askGameTime: 0,
176 gameIsLoading: false,
177 // If asklastate got no reply, ask again:
178 gotLastate: false,
179 gotMoveIdx: -1, //last move index received
180 // If newmove got no pingback, send again:
181 opponentGotMove: false,
182 connexionString: "",
183 // Incomplete info games: show move played
184 moveNotation: "",
185 // Intervals from setInterval():
186 askLastate: null,
187 retrySendmove: null,
188 clockUpdate: null,
189 // Related to (killing of) self multi-connects:
190 newConnect: {},
191 killed: {}
192 };
193 },
194 watch: {
195 $route: function(to, from) {
196 if (from.params["id"] != to.params["id"]) {
197 // Change everything:
198 this.cleanBeforeDestroy();
199 let boardDiv = document.querySelector(".game");
200 if (!!boardDiv)
201 // In case of incomplete information variant:
202 boardDiv.style.visibility = "hidden";
203 this.atCreation();
204 } else {
205 // Same game ID
206 this.gameRef.id = to.params["id"];
207 this.gameRef.rid = to.query["rid"];
208 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
209 this.loadGame();
210 }
211 }
212 },
213 // NOTE: some redundant code with Hall.vue (mostly related to people array)
214 created: function() {
215 this.atCreation();
216 },
217 mounted: function() {
218 document.addEventListener('visibilitychange', this.visibilityChange);
219 ["chatWrap", "infoDiv"].forEach(eltName => {
220 document.getElementById(eltName)
221 .addEventListener("click", processModalClick);
222 });
223 if ("ontouchstart" in window) {
224 // Disable tooltips on smartphones:
225 document.querySelectorAll("#aboveBoard .tooltip").forEach(elt => {
226 elt.classList.remove("tooltip");
227 });
228 }
229 },
230 beforeDestroy: function() {
231 document.removeEventListener('visibilitychange', this.visibilityChange);
232 this.cleanBeforeDestroy();
233 },
234 methods: {
235 visibilityChange: function() {
236 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
237 this.send(
238 document.visibilityState == "visible"
239 ? "getfocus"
240 : "losefocus"
241 );
242 },
243 atCreation: function() {
244 // 0] (Re)Set variables
245 this.gameRef.id = this.$route.params["id"];
246 // rid = remote ID to find an observed live game,
247 // next = next corr games IDs to navigate faster
248 // (Both might be undefined)
249 this.gameRef.rid = this.$route.query["rid"];
250 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
251 // Always add myself to players' list
252 const my = this.st.user;
253 this.$set(
254 this.people,
255 my.sid,
256 {
257 id: my.id,
258 name: my.name,
259 focus: true
260 }
261 );
262 this.game = {
263 players: [{ name: "" }, { name: "" }],
264 chats: [],
265 rendered: false
266 };
267 let chatComp = this.$refs["chatcomp"];
268 if (!!chatComp) chatComp.chats = [];
269 this.virtualClocks = [[0,0], [0,0]];
270 this.vr = null;
271 this.drawOffer = "";
272 this.lastateAsked = false;
273 this.rematchOffer = "";
274 this.lastate = undefined;
275 this.newChat = "";
276 this.roomInitialized = false;
277 this.askGameTime = 0;
278 this.gameIsLoading = false;
279 this.gotLastate = false;
280 this.gotMoveIdx = -1;
281 this.opponentGotMove = false;
282 this.askLastate = null;
283 this.retrySendmove = null;
284 this.clockUpdate = null;
285 this.newConnect = {};
286 this.killed = {};
287 // 1] Initialize connection
288 this.connexionString =
289 params.socketUrl +
290 "/?sid=" +
291 this.st.user.sid +
292 "&id=" +
293 this.st.user.id +
294 "&tmpId=" +
295 getRandString() +
296 "&page=" +
297 // Discard potential "/?next=[...]" for page indication:
298 encodeURIComponent(this.$route.path.match(/\/game\/[a-zA-Z0-9]+/)[0]);
299 this.conn = new WebSocket(this.connexionString);
300 this.conn.onmessage = this.socketMessageListener;
301 this.conn.onclose = this.socketCloseListener;
302 // Socket init required before loading remote game:
303 const socketInit = callback => {
304 if (!!this.conn && this.conn.readyState == 1)
305 // 1 == OPEN state
306 callback();
307 else
308 // Socket not ready yet (initial loading)
309 // NOTE: it's important to call callback without arguments,
310 // otherwise first arg is Websocket object and loadGame fails.
311 this.conn.onopen = () => callback();
312 };
313 if (!this.gameRef.rid)
314 // Game stored locally or on server
315 this.loadGame(null, () => socketInit(this.roomInit));
316 else
317 // Game stored remotely: need socket to retrieve it
318 // NOTE: the callback "roomInit" will be lost, so we don't provide it.
319 // --> It will be given when receiving "fullgame" socket event.
320 socketInit(this.loadGame);
321 },
322 cleanBeforeDestroy: function() {
323 if (!!this.askLastate)
324 clearInterval(this.askLastate);
325 if (!!this.retrySendmove)
326 clearInterval(this.retrySendmove);
327 if (!!this.clockUpdate)
328 clearInterval(this.clockUpdate);
329 this.send("disconnect");
330 },
331 roomInit: function() {
332 if (!this.roomInitialized) {
333 // Notify the room only now that I connected, because
334 // messages might be lost otherwise (if game loading is slow)
335 this.send("connect");
336 this.send("pollclients");
337 // We may ask fullgame several times if some moves are lost,
338 // but room should be init only once:
339 this.roomInitialized = true;
340 }
341 },
342 send: function(code, obj) {
343 if (!!this.conn)
344 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
345 },
346 isConnected: function(index) {
347 const player = this.game.players[index];
348 // Is it me ? In this case no need to bother with focus
349 if (this.st.user.sid == player.sid || this.st.user.id == player.uid)
350 // Still have to check for name (because of potential multi-accounts
351 // on same browser, although this should be rare...)
352 return (!this.st.user.name || this.st.user.name == player.name);
353 // Try to find a match in people:
354 return (
355 (
356 !!player.sid &&
357 Object.keys(this.people).some(sid =>
358 sid == player.sid && this.people[sid].focus)
359 )
360 ||
361 (
362 player.uid &&
363 Object.values(this.people).some(p =>
364 p.id == player.uid && p.focus)
365 )
366 );
367 },
368 getOppsid: function() {
369 let oppsid = this.game.oppsid;
370 if (!oppsid) {
371 oppsid = Object.keys(this.people).find(
372 sid => this.people[sid].id == this.game.oppid
373 );
374 }
375 // oppsid is useful only if opponent is online:
376 if (!!oppsid && !!this.people[oppsid]) return oppsid;
377 return null;
378 },
379 resetChatColor: function() {
380 // TODO: this is called twice, once on opening an once on closing
381 document.getElementById("chatBtn").classList.remove("somethingnew");
382 },
383 processChat: function(chat) {
384 this.send("newchat", { data: chat });
385 // NOTE: anonymous chats in corr games are not stored on server (TODO?)
386 if (this.game.type == "corr" && this.st.user.id > 0)
387 this.updateCorrGame({ chat: chat });
388 },
389 clearChat: function() {
390 // Nothing more to do if game is live (chats not recorded)
391 if (this.game.type == "corr") {
392 if (!!this.game.mycolor) {
393 ajax(
394 "/chats",
395 "DELETE",
396 { data: { gid: this.game.id } }
397 );
398 }
399 this.$set(this.game, "chats", []);
400 }
401 },
402 getGameType: function(game) {
403 return game.cadence.indexOf("d") >= 0 ? "corr" : "live";
404 },
405 // Notify something after a new move (to opponent and me on MyGames page)
406 notifyMyGames: function(thing, data) {
407 this.send(
408 "notify" + thing,
409 {
410 data: data,
411 targets: this.game.players.map(p => {
412 return { sid: p.sid, uid: p.uid };
413 })
414 }
415 );
416 },
417 showNextGame: function() {
418 // Did I play in current game? If not, add it to nextIds list
419 if (this.game.score == "*" && this.vr.turn == this.game.mycolor)
420 this.nextIds.unshift(this.game.id);
421 const nextGid = this.nextIds.pop();
422 this.$router.push(
423 "/game/" + nextGid + "/?next=" + JSON.stringify(this.nextIds));
424 },
425 askGameAgain: function() {
426 this.gameIsLoading = true;
427 const currentUrl = document.location.href;
428 const doAskGame = () => {
429 if (document.location.href != currentUrl) return; //page change
430 if (!this.gameRef.rid)
431 // This is my game: just reload.
432 this.loadGame();
433 else
434 // Just ask fullgame again (once!), this is much simpler.
435 // If this fails, the user could just reload page :/
436 this.send("askfullgame", { target: this.gameRef.rid });
437 };
438 // Delay of at least 2s between two game requests
439 const now = Date.now();
440 const delay = Math.max(2000 - (now - this.askGameTime), 0);
441 this.askGameTime = now;
442 setTimeout(doAskGame, delay);
443 },
444 socketMessageListener: function(msg) {
445 if (!this.conn) return;
446 const data = JSON.parse(msg.data);
447 switch (data.code) {
448 case "pollclients":
449 data.sockIds.forEach(sid => {
450 if (sid != this.st.user.sid) {
451 this.people[sid] = { focus: true };
452 this.send("askidentity", { target: sid });
453 }
454 });
455 break;
456 case "connect":
457 if (!this.people[data.from]) {
458 this.people[data.from] = { focus: true };
459 this.newConnect[data.from] = true; //for self multi-connects tests
460 this.send("askidentity", { target: data.from });
461 }
462 break;
463 case "disconnect":
464 this.$delete(this.people, data.from);
465 break;
466 case "getfocus": {
467 let player = this.people[data.from];
468 if (!!player) {
469 player.focus = true;
470 this.$forceUpdate(); //TODO: shouldn't be required
471 }
472 break;
473 }
474 case "losefocus": {
475 let player = this.people[data.from];
476 if (!!player) {
477 player.focus = false;
478 this.$forceUpdate(); //TODO: shouldn't be required
479 }
480 break;
481 }
482 case "killed":
483 // I logged in elsewhere:
484 this.conn = null;
485 alert(this.st.tr["New connexion detected: tab now offline"]);
486 break;
487 case "askidentity": {
488 // Request for identification
489 const me = {
490 // Decompose to avoid revealing email
491 name: this.st.user.name,
492 sid: this.st.user.sid,
493 id: this.st.user.id
494 };
495 this.send("identity", { data: me, target: data.from });
496 break;
497 }
498 case "identity": {
499 const user = data.data;
500 let player = this.people[user.sid];
501 // player.focus is already set
502 player.name = user.name;
503 player.id = user.id;
504 this.$forceUpdate(); //TODO: shouldn't be required
505 // If I multi-connect, kill current connexion if no mark (I'm older)
506 if (this.newConnect[user.sid]) {
507 if (
508 user.id > 0 &&
509 user.id == this.st.user.id &&
510 user.sid != this.st.user.sid &&
511 !this.killed[this.st.user.sid]
512 ) {
513 this.send("killme", { sid: this.st.user.sid });
514 this.killed[this.st.user.sid] = true;
515 }
516 delete this.newConnect[user.sid];
517 }
518 if (!this.killed[this.st.user.sid]) {
519 // Ask potentially missed last state, if opponent and I play
520 if (
521 !!this.game.mycolor &&
522 this.game.type == "live" &&
523 this.game.score == "*" &&
524 this.game.players.some(p => p.sid == user.sid)
525 ) {
526 this.send("asklastate", { target: user.sid });
527 let counter = 1;
528 this.askLastate = setInterval(
529 () => {
530 // Ask at most 3 times:
531 // if no reply after that there should be a network issue.
532 if (
533 counter < 3 &&
534 !this.gotLastate &&
535 !!this.people[user.sid]
536 ) {
537 this.send("asklastate", { target: user.sid });
538 counter++;
539 } else {
540 clearInterval(this.askLastate);
541 }
542 },
543 1500
544 );
545 }
546 }
547 break;
548 }
549 case "askgame":
550 // Send current (live) game if not asked by any of the players
551 if (
552 this.game.type == "live" &&
553 this.game.players.every(p => p.sid != data.from[0])
554 ) {
555 const myGame = {
556 id: this.game.id,
557 fen: this.game.fen,
558 players: this.game.players,
559 vid: this.game.vid,
560 cadence: this.game.cadence,
561 score: this.game.score,
562 rid: this.st.user.sid //useful in Hall if I'm an observer
563 };
564 this.send("game", { data: myGame, target: data.from });
565 }
566 break;
567 case "askfullgame":
568 const gameToSend = Object.keys(this.game)
569 .filter(k =>
570 [
571 "id","fen","players","vid","cadence","fenStart","vname",
572 "moves","clocks","initime","score","drawOffer","rematchOffer"
573 ].includes(k))
574 .reduce(
575 (obj, k) => {
576 obj[k] = this.game[k];
577 return obj;
578 },
579 {}
580 );
581 this.send("fullgame", { data: gameToSend, target: data.from });
582 break;
583 case "fullgame":
584 // Callback "roomInit" to poll clients only after game is loaded
585 this.loadGame(data.data, this.roomInit);
586 break;
587 case "asklastate":
588 // Sending informative last state if I played a move or score != "*"
589 // If the game or moves aren't loaded yet, delay the sending:
590 if (!this.game || !this.game.moves) this.lastateAsked = true;
591 else this.sendLastate(data.from);
592 break;
593 case "lastate": {
594 // Got opponent infos about last move
595 this.gotLastate = true;
596 if (!data.data.nothing) {
597 this.lastate = data.data;
598 if (this.game.rendered)
599 // Game is rendered (Board component)
600 this.processLastate();
601 // Else: will be processed when game is ready
602 }
603 break;
604 }
605 case "newmove": {
606 const movePlus = data.data;
607 const movesCount = this.game.moves.length;
608 if (movePlus.index > movesCount) {
609 // This can only happen if I'm an observer and missed a move.
610 if (this.gotMoveIdx < movePlus.index)
611 this.gotMoveIdx = movePlus.index;
612 if (!this.gameIsLoading) this.askGameAgain();
613 }
614 else {
615 if (
616 movePlus.index < movesCount ||
617 this.gotMoveIdx >= movePlus.index
618 ) {
619 // Opponent re-send but we already have the move:
620 // (maybe he didn't receive our pingback...)
621 this.send("gotmove", {data: movePlus.index, target: data.from});
622 } else {
623 this.gotMoveIdx = movePlus.index;
624 const receiveMyMove = (movePlus.color == this.game.mycolor);
625 if (!receiveMyMove && !!this.game.mycolor)
626 // Notify opponent that I got the move:
627 this.send("gotmove", {data: movePlus.index, target: data.from});
628 if (movePlus.cancelDrawOffer) {
629 // Opponent refuses draw
630 this.drawOffer = "";
631 // NOTE for corr games: drawOffer reset by player in turn
632 if (
633 this.game.type == "live" &&
634 !!this.game.mycolor &&
635 !receiveMyMove
636 ) {
637 GameStorage.update(this.gameRef.id, { drawOffer: "" });
638 }
639 }
640 this.$refs["basegame"].play(movePlus.move, "received", null, true);
641 this.processMove(
642 movePlus.move,
643 {
644 clock: movePlus.clock,
645 receiveMyMove: receiveMyMove
646 }
647 );
648 }
649 }
650 break;
651 }
652 case "gotmove": {
653 this.opponentGotMove = true;
654 // Now his clock starts running:
655 const oppIdx = ['w','b'].indexOf(this.vr.turn);
656 this.game.initime[oppIdx] = Date.now();
657 this.re_setClocks();
658 break;
659 }
660 case "resign":
661 const score = data.side == "b" ? "1-0" : "0-1";
662 const side = data.side == "w" ? "White" : "Black";
663 this.gameOver(score, side + " surrender");
664 break;
665 case "abort":
666 this.gameOver("?", "Stop");
667 break;
668 case "draw":
669 this.gameOver("1/2", data.data);
670 break;
671 case "drawoffer":
672 // NOTE: observers don't know who offered draw
673 this.drawOffer = "received";
674 break;
675 case "rematchoffer":
676 // NOTE: observers don't know who offered rematch
677 this.rematchOffer = data.data ? "received" : "";
678 break;
679 case "newgame": {
680 // A game started, redirect if I'm playing in
681 const gameInfo = data.data;
682 const gameType = this.getGameType(gameInfo);
683 if (
684 gameType == "live" &&
685 gameInfo.players.some(p => p.sid == this.st.user.sid)
686 ) {
687 this.addAndGotoLiveGame(gameInfo);
688 } else if (
689 gameType == "corr" &&
690 gameInfo.players.some(p => p.uid == this.st.user.id)
691 ) {
692 this.$router.push("/game/" + gameInfo.id);
693 } else {
694 let urlRid = "";
695 if (gameInfo.cadence.indexOf('d') === -1) {
696 urlRid = "/?rid=";
697 // Select sid of any of the online players:
698 let onlineSid = [];
699 gameInfo.players.forEach(p => {
700 if (!!this.people[p.sid]) onlineSid.push(p.sid);
701 });
702 urlRid += onlineSid[Math.floor(Math.random() * onlineSid.length)];
703 }
704 this.infoMessage =
705 this.st.tr["Rematch in progress:"] +
706 " <a href='#/game/" +
707 gameInfo.id + urlRid +
708 "'>" +
709 "#/game/" +
710 gameInfo.id + urlRid +
711 "</a>";
712 document.getElementById("modalInfo").checked = true;
713 }
714 break;
715 }
716 case "newchat":
717 this.newChat = data.data;
718 if (!document.getElementById("modalChat").checked)
719 document.getElementById("chatBtn").classList.add("somethingnew");
720 break;
721 }
722 },
723 socketCloseListener: function() {
724 this.conn = new WebSocket(this.connexionString);
725 this.conn.addEventListener("message", this.socketMessageListener);
726 this.conn.addEventListener("close", this.socketCloseListener);
727 },
728 updateCorrGame: function(obj, callback) {
729 ajax(
730 "/games",
731 "PUT",
732 {
733 data: {
734 gid: this.gameRef.id,
735 newObj: obj
736 },
737 success: () => {
738 if (!!callback) callback();
739 }
740 }
741 );
742 },
743 sendLastate: function(target) {
744 if (
745 (this.game.moves.length > 0 && this.vr.turn != this.game.mycolor) ||
746 this.game.score != "*" ||
747 this.drawOffer == "sent" ||
748 this.rematchOffer == "sent"
749 ) {
750 // Send our "last state" informations to opponent
751 const L = this.game.moves.length;
752 const myIdx = ["w", "b"].indexOf(this.game.mycolor);
753 const myLastate = {
754 lastMove: L > 0 ? this.game.moves[L - 1] : undefined,
755 clock: this.game.clocks[myIdx],
756 // Since we played a move (or abort or resign),
757 // only drawOffer=="sent" is possible
758 drawSent: this.drawOffer == "sent",
759 rematchSent: this.rematchOffer == "sent",
760 score: this.game.score,
761 scoreMsg: this.game.scoreMsg,
762 movesCount: L,
763 initime: this.game.initime[1 - myIdx] //relevant only if I played
764 };
765 this.send("lastate", { data: myLastate, target: target });
766 } else {
767 this.send("lastate", { data: {nothing: true}, target: target });
768 }
769 },
770 // lastate was received, but maybe game wasn't ready yet:
771 processLastate: function() {
772 const data = this.lastate;
773 this.lastate = undefined; //security...
774 const L = this.game.moves.length;
775 if (data.movesCount > L) {
776 // Just got last move from him
777 this.$refs["basegame"].play(data.lastMove, "received", null, true);
778 this.processMove(data.lastMove, { clock: data.clock });
779 }
780 if (data.drawSent) this.drawOffer = "received";
781 if (data.rematchSent) this.rematchOffer = "received";
782 if (data.score != "*") {
783 this.drawOffer = "";
784 if (this.game.score == "*")
785 this.gameOver(data.score, data.scoreMsg);
786 }
787 },
788 clickDraw: function() {
789 if (!this.game.mycolor) return; //I'm just spectator
790 if (["received", "threerep"].includes(this.drawOffer)) {
791 if (!confirm(this.st.tr["Accept draw?"])) return;
792 const message =
793 this.drawOffer == "received"
794 ? "Mutual agreement"
795 : "Three repetitions";
796 this.send("draw", { data: message });
797 this.gameOver("1/2", message);
798 } else if (this.drawOffer == "") {
799 // No effect if drawOffer == "sent"
800 if (this.game.mycolor != this.vr.turn) {
801 alert(this.st.tr["Draw offer only in your turn"]);
802 return;
803 }
804 if (!confirm(this.st.tr["Offer draw?"])) return;
805 this.drawOffer = "sent";
806 this.send("drawoffer");
807 if (this.game.type == "live") {
808 GameStorage.update(
809 this.gameRef.id,
810 { drawOffer: this.game.mycolor }
811 );
812 } else this.updateCorrGame({ drawOffer: this.game.mycolor });
813 }
814 },
815 addAndGotoLiveGame: function(gameInfo, callback) {
816 const game = Object.assign(
817 {},
818 gameInfo,
819 {
820 // (other) Game infos: constant
821 fenStart: gameInfo.fen,
822 vname: this.game.vname,
823 created: Date.now(),
824 // Game state (including FEN): will be updated
825 moves: [],
826 clocks: [-1, -1], //-1 = unstarted
827 initime: [0, 0], //initialized later
828 score: "*"
829 }
830 );
831 GameStorage.add(game, (err) => {
832 // No error expected.
833 if (!err) {
834 if (this.st.settings.sound)
835 new Audio("/sounds/newgame.flac").play().catch(() => {});
836 callback();
837 this.$router.push("/game/" + gameInfo.id);
838 }
839 });
840 },
841 clickRematch: function() {
842 if (!this.game.mycolor) return; //I'm just spectator
843 if (this.rematchOffer == "received") {
844 // Start a new game!
845 let gameInfo = {
846 id: getRandString(), //ignored if corr
847 fen: V.GenRandInitFen(this.game.randomness),
848 players: this.game.players.reverse(),
849 vid: this.game.vid,
850 cadence: this.game.cadence
851 };
852 const notifyNewGame = () => {
853 let oppsid = this.getOppsid(); //may be null
854 this.send("rnewgame", { data: gameInfo, oppsid: oppsid });
855 // Also to MyGames page:
856 this.notifyMyGames("newgame", gameInfo);
857 };
858 if (this.game.type == "live")
859 this.addAndGotoLiveGame(gameInfo, notifyNewGame);
860 else {
861 // corr game
862 ajax(
863 "/games",
864 "POST",
865 {
866 // cid is useful to delete the challenge:
867 data: { gameInfo: gameInfo },
868 success: (response) => {
869 gameInfo.id = response.gameId;
870 notifyNewGame();
871 this.$router.push("/game/" + response.gameId);
872 }
873 }
874 );
875 }
876 } else if (this.rematchOffer == "") {
877 this.rematchOffer = "sent";
878 this.send("rematchoffer", { data: true });
879 if (this.game.type == "live") {
880 GameStorage.update(
881 this.gameRef.id,
882 { rematchOffer: this.game.mycolor }
883 );
884 } else this.updateCorrGame({ rematchOffer: this.game.mycolor });
885 } else if (this.rematchOffer == "sent") {
886 // Toggle rematch offer (on --> off)
887 this.rematchOffer = "";
888 this.send("rematchoffer", { data: false });
889 if (this.game.type == "live") {
890 GameStorage.update(
891 this.gameRef.id,
892 { rematchOffer: '' }
893 );
894 } else this.updateCorrGame({ rematchOffer: 'n' });
895 }
896 },
897 abortGame: function() {
898 if (!this.game.mycolor || !confirm(this.st.tr["Terminate game?"])) return;
899 this.gameOver("?", "Stop");
900 this.send("abort");
901 },
902 resign: function() {
903 if (!this.game.mycolor || !confirm(this.st.tr["Resign the game?"]))
904 return;
905 this.send("resign", { data: this.game.mycolor });
906 const score = this.game.mycolor == "w" ? "0-1" : "1-0";
907 const side = this.game.mycolor == "w" ? "White" : "Black";
908 this.gameOver(score, side + " surrender");
909 },
910 // 3 cases for loading a game:
911 // - from indexedDB (running or completed live game I play)
912 // - from server (one correspondance game I play[ed] or not)
913 // - from remote peer (one live game I don't play, finished or not)
914 loadGame: function(game, callback) {
915 const afterRetrieval = async (game) => {
916 const vModule = await import("@/variants/" + game.vname + ".js");
917 window.V = vModule.VariantRules;
918 this.vr = new V(game.fen);
919 const gtype = this.getGameType(game);
920 const tc = extractTime(game.cadence);
921 const myIdx = game.players.findIndex(p => {
922 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
923 });
924 const mycolor = [undefined, "w", "b"][myIdx + 1]; //undefined for observers
925 if (!game.chats) game.chats = []; //live games don't have chat history
926 if (gtype == "corr") {
927 if (game.players[0].color == "b") {
928 // Adopt the same convention for live and corr games: [0] = white
929 [game.players[0], game.players[1]] = [
930 game.players[1],
931 game.players[0]
932 ];
933 }
934 // NOTE: clocks in seconds, initime in milliseconds
935 game.moves.sort((m1, m2) => m1.idx - m2.idx); //in case of
936 game.clocks = [tc.mainTime, tc.mainTime];
937 const L = game.moves.length;
938 if (game.score == "*") {
939 // Set clocks + initime
940 game.initime = [0, 0];
941 if (L >= 1) {
942 const gameLastupdate = game.moves[L-1].played;
943 game.initime[L % 2] = gameLastupdate;
944 if (L >= 2) {
945 game.clocks[L % 2] =
946 tc.mainTime - (Date.now() - gameLastupdate) / 1000;
947 }
948 }
949 }
950 // Sort chat messages from newest to oldest
951 game.chats.sort((c1, c2) => {
952 return c2.added - c1.added;
953 });
954 if (myIdx >= 0 && game.score == "*" && game.chats.length > 0) {
955 // Did a chat message arrive after my last move?
956 let dtLastMove = 0;
957 if (L == 1 && myIdx == 0)
958 dtLastMove = game.moves[0].played;
959 else if (L >= 2) {
960 if (L % 2 == 0) {
961 // It's now white turn
962 dtLastMove = game.moves[L-1-(1-myIdx)].played;
963 } else {
964 // Black turn:
965 dtLastMove = game.moves[L-1-myIdx].played;
966 }
967 }
968 if (dtLastMove < game.chats[0].added)
969 document.getElementById("chatBtn").classList.add("somethingnew");
970 }
971 // Now that we used idx and played, re-format moves as for live games
972 game.moves = game.moves.map(m => m.squares);
973 }
974 if (gtype == "live" && game.clocks[0] < 0) {
975 // Game is unstarted
976 game.clocks = [tc.mainTime, tc.mainTime];
977 if (game.score == "*") {
978 game.initime[0] = Date.now();
979 if (myIdx >= 0) {
980 // I play in this live game; corr games don't have clocks+initime
981 GameStorage.update(game.id, {
982 clocks: game.clocks,
983 initime: game.initime
984 });
985 }
986 }
987 }
988 // TODO: merge next 2 "if" conditions
989 if (!!game.drawOffer) {
990 if (game.drawOffer == "t")
991 // Three repetitions
992 this.drawOffer = "threerep";
993 else {
994 // Draw offered by any of the players:
995 if (myIdx < 0) this.drawOffer = "received";
996 else {
997 // I play in this game:
998 if (
999 (game.drawOffer == "w" && myIdx == 0) ||
1000 (game.drawOffer == "b" && myIdx == 1)
1001 )
1002 this.drawOffer = "sent";
1003 else this.drawOffer = "received";
1004 }
1005 }
1006 }
1007 if (!!game.rematchOffer) {
1008 if (myIdx < 0) this.rematchOffer = "received";
1009 else {
1010 // I play in this game:
1011 if (
1012 (game.rematchOffer == "w" && myIdx == 0) ||
1013 (game.rematchOffer == "b" && myIdx == 1)
1014 )
1015 this.rematchOffer = "sent";
1016 else this.rematchOffer = "received";
1017 }
1018 }
1019 this.repeat = {}; //reset: scan past moves' FEN:
1020 let repIdx = 0;
1021 let vr_tmp = new V(game.fenStart);
1022 let curTurn = "n";
1023 game.moves.forEach(m => {
1024 playMove(m, vr_tmp);
1025 const fenIdx = vr_tmp.getFen().replace(/ /g, "_");
1026 this.repeat[fenIdx] = this.repeat[fenIdx]
1027 ? this.repeat[fenIdx] + 1
1028 : 1;
1029 });
1030 if (this.repeat[repIdx] >= 3) this.drawOffer = "threerep";
1031 this.game = Object.assign(
1032 // NOTE: assign mycolor here, since BaseGame could also be VS computer
1033 {
1034 type: gtype,
1035 increment: tc.increment,
1036 mycolor: mycolor,
1037 // opponent sid not strictly required (or available), but easier
1038 // at least oppsid or oppid is available anyway:
1039 oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid,
1040 oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].uid
1041 },
1042 game,
1043 );
1044 this.$refs["basegame"].re_setVariables(this.game);
1045 if (!this.gameIsLoading) {
1046 // Initial loading:
1047 this.gotMoveIdx = game.moves.length - 1;
1048 // If we arrive here after 'nextGame' action, the board might be hidden
1049 let boardDiv = document.querySelector(".game");
1050 if (!!boardDiv && boardDiv.style.visibility == "hidden")
1051 boardDiv.style.visibility = "visible";
1052 }
1053 this.re_setClocks();
1054 this.$nextTick(() => {
1055 this.game.rendered = true;
1056 // Did lastate arrive before game was rendered?
1057 if (this.lastate) this.processLastate();
1058 });
1059 if (this.lastateAsked) {
1060 this.lastateAsked = false;
1061 this.sendLastate(game.oppsid);
1062 }
1063 if (this.gameIsLoading) {
1064 this.gameIsLoading = false;
1065 if (this.gotMoveIdx >= game.moves.length)
1066 // Some moves arrived meanwhile...
1067 this.askGameAgain();
1068 }
1069 if (!!callback) callback();
1070 };
1071 if (!!game) {
1072 afterRetrieval(game);
1073 return;
1074 }
1075 if (this.gameRef.rid) {
1076 // Remote live game: forgetting about callback func... (TODO: design)
1077 this.send("askfullgame", { target: this.gameRef.rid });
1078 } else {
1079 // Local or corr game on server.
1080 // NOTE: afterRetrieval() is never called if game not found
1081 const gid = this.gameRef.id;
1082 if (Number.isInteger(gid) || !isNaN(parseInt(gid))) {
1083 // corr games identifiers are integers
1084 ajax(
1085 "/games",
1086 "GET",
1087 {
1088 data: { gid: gid },
1089 success: (res) => {
1090 let g = res.game;
1091 g.moves.forEach(m => {
1092 m.squares = JSON.parse(m.squares);
1093 });
1094 afterRetrieval(g);
1095 }
1096 }
1097 );
1098 }
1099 else
1100 // Local game
1101 GameStorage.get(this.gameRef.id, afterRetrieval);
1102 }
1103 },
1104 re_setClocks: function() {
1105 if (this.game.moves.length < 2 || this.game.score != "*") {
1106 // 1st move not completed yet, or game over: freeze time
1107 this.virtualClocks = this.game.clocks.map(s => ppt(s).split(':'));
1108 return;
1109 }
1110 const currentTurn = this.vr.turn;
1111 const currentMovesCount = this.game.moves.length;
1112 const colorIdx = ["w", "b"].indexOf(currentTurn);
1113 let countdown =
1114 this.game.clocks[colorIdx] -
1115 (Date.now() - this.game.initime[colorIdx]) / 1000;
1116 this.virtualClocks = [0, 1].map(i => {
1117 const removeTime =
1118 i == colorIdx ? (Date.now() - this.game.initime[colorIdx]) / 1000 : 0;
1119 return ppt(this.game.clocks[i] - removeTime).split(':');
1120 });
1121 this.clockUpdate = setInterval(
1122 () => {
1123 if (
1124 countdown < 0 ||
1125 this.game.moves.length > currentMovesCount ||
1126 this.game.score != "*"
1127 ) {
1128 clearInterval(this.clockUpdate);
1129 if (countdown < 0)
1130 this.gameOver(
1131 currentTurn == "w" ? "0-1" : "1-0",
1132 "Time"
1133 );
1134 } else
1135 this.$set(
1136 this.virtualClocks,
1137 colorIdx,
1138 ppt(Math.max(0, --countdown)).split(':')
1139 );
1140 },
1141 1000
1142 );
1143 },
1144 // Update variables and storage after a move:
1145 processMove: function(move, data) {
1146 if (!data) data = {};
1147 const moveCol = this.vr.turn;
1148 const doProcessMove = () => {
1149 const colorIdx = ["w", "b"].indexOf(moveCol);
1150 const nextIdx = 1 - colorIdx;
1151 const origMovescount = this.game.moves.length;
1152 let addTime = 0; //for live games
1153 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1154 if (this.drawOffer == "received")
1155 // I refuse draw
1156 this.drawOffer = "";
1157 if (this.game.type == "live" && origMovescount >= 2) {
1158 const elapsed = Date.now() - this.game.initime[colorIdx];
1159 // elapsed time is measured in milliseconds
1160 addTime = this.game.increment - elapsed / 1000;
1161 }
1162 }
1163 // Update current game object:
1164 playMove(move, this.vr);
1165 // The move is played: stop clock
1166 clearInterval(this.clockUpdate);
1167 if (!data.score) {
1168 // Received move, score has not been computed in BaseGame (!!noemit)
1169 const score = this.vr.getCurrentScore();
1170 if (score != "*") this.gameOver(score);
1171 }
1172 this.game.moves.push(move);
1173 this.game.fen = this.vr.getFen();
1174 if (this.game.type == "live") {
1175 if (!!data.clock) this.game.clocks[colorIdx] = data.clock;
1176 else this.game.clocks[colorIdx] += addTime;
1177 }
1178 // In corr games, just reset clock to mainTime:
1179 else {
1180 this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime;
1181 }
1182 // NOTE: opponent's initime is reset after "gotmove" is received
1183 if (
1184 !this.game.mycolor ||
1185 moveCol != this.game.mycolor ||
1186 !!data.receiveMyMove
1187 ) {
1188 this.game.initime[nextIdx] = Date.now();
1189 }
1190 // If repetition detected, consider that a draw offer was received:
1191 const fenObj = this.vr.getFenForRepeat();
1192 this.repeat[fenObj] =
1193 !!this.repeat[fenObj]
1194 ? this.repeat[fenObj] + 1
1195 : 1;
1196 if (this.repeat[fenObj] >= 3) this.drawOffer = "threerep";
1197 else if (this.drawOffer == "threerep") this.drawOffer = "";
1198 if (!!this.game.mycolor && !data.receiveMyMove) {
1199 // NOTE: 'var' to see that variable outside this block
1200 var filtered_move = getFilteredMove(move);
1201 }
1202 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1203 // Notify turn on MyGames page:
1204 this.notifyMyGames(
1205 "turn",
1206 {
1207 gid: this.gameRef.id,
1208 turn: this.vr.turn
1209 }
1210 );
1211 }
1212 // Since corr games are stored at only one location, update should be
1213 // done only by one player for each move:
1214 if (
1215 !!this.game.mycolor &&
1216 !data.receiveMyMove &&
1217 (this.game.type == "live" || moveCol == this.game.mycolor)
1218 ) {
1219 let drawCode = "";
1220 switch (this.drawOffer) {
1221 case "threerep":
1222 drawCode = "t";
1223 break;
1224 case "sent":
1225 drawCode = this.game.mycolor;
1226 break;
1227 case "received":
1228 drawCode = V.GetOppCol(this.game.mycolor);
1229 break;
1230 }
1231 if (this.game.type == "corr") {
1232 // corr: only move, fen and score
1233 this.updateCorrGame({
1234 fen: this.game.fen,
1235 move: {
1236 squares: filtered_move,
1237 played: Date.now(),
1238 idx: origMovescount
1239 },
1240 // Code "n" for "None" to force reset (otherwise it's ignored)
1241 drawOffer: drawCode || "n"
1242 });
1243 }
1244 else {
1245 const updateStorage = () => {
1246 GameStorage.update(this.gameRef.id, {
1247 fen: this.game.fen,
1248 move: filtered_move,
1249 moveIdx: origMovescount,
1250 clocks: this.game.clocks,
1251 initime: this.game.initime,
1252 drawOffer: drawCode
1253 });
1254 };
1255 // The active tab can update storage immediately
1256 if (!document.hidden) updateStorage();
1257 // Small random delay otherwise
1258 else setTimeout(updateStorage, 500 + 1000 * Math.random());
1259 }
1260 }
1261 // Send move ("newmove" event) to people in the room (if our turn)
1262 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1263 let sendMove = {
1264 move: filtered_move,
1265 index: origMovescount,
1266 // color is required to check if this is my move (if several tabs opened)
1267 color: moveCol,
1268 cancelDrawOffer: this.drawOffer == ""
1269 };
1270 if (this.game.type == "live")
1271 sendMove["clock"] = this.game.clocks[colorIdx];
1272 this.opponentGotMove = false;
1273 this.send("newmove", {data: sendMove});
1274 // If the opponent doesn't reply gotmove soon enough, re-send move:
1275 // Do this at most 2 times, because mpore would mean network issues,
1276 // opponent would then be expected to disconnect/reconnect.
1277 let counter = 1;
1278 const currentUrl = document.location.href;
1279 this.retrySendmove = setInterval(
1280 () => {
1281 if (
1282 counter >= 3 ||
1283 this.opponentGotMove ||
1284 document.location.href != currentUrl //page change
1285 ) {
1286 clearInterval(this.retrySendmove);
1287 return;
1288 }
1289 const oppsid = this.getOppsid();
1290 if (!oppsid)
1291 // Opponent is disconnected: he'll ask last state
1292 clearInterval(this.retrySendmove);
1293 else {
1294 this.send("newmove", { data: sendMove, target: oppsid });
1295 counter++;
1296 }
1297 },
1298 1500
1299 );
1300 }
1301 else
1302 // Not my move or I'm an observer: just start other player's clock
1303 this.re_setClocks();
1304 };
1305 if (
1306 this.game.type == "corr" &&
1307 moveCol == this.game.mycolor &&
1308 !data.receiveMyMove
1309 ) {
1310 let boardDiv = document.querySelector(".game");
1311 const afterSetScore = () => {
1312 doProcessMove();
1313 if (this.st.settings.gotonext && this.nextIds.length > 0)
1314 this.showNextGame();
1315 else {
1316 // The board might have been hidden:
1317 if (boardDiv.style.visibility == "hidden")
1318 boardDiv.style.visibility = "visible";
1319 }
1320 };
1321 let el = document.querySelector("#buttonsConfirm > .acceptBtn");
1322 // We may play several moves in a row: in case of, remove listener:
1323 let elClone = el.cloneNode(true);
1324 el.parentNode.replaceChild(elClone, el);
1325 elClone.addEventListener(
1326 "click",
1327 () => {
1328 document.getElementById("modalConfirm").checked = false;
1329 if (!!data.score && data.score != "*")
1330 // Set score first
1331 this.gameOver(data.score, null, afterSetScore);
1332 else afterSetScore();
1333 }
1334 );
1335 // PlayOnBoard is enough, and more appropriate for Synchrone Chess
1336 V.PlayOnBoard(this.vr.board, move);
1337 const position = this.vr.getBaseFen();
1338 V.UndoOnBoard(this.vr.board, move);
1339 if (["all","byrow"].includes(V.ShowMoves)) {
1340 this.curDiag = getDiagram({
1341 position: position,
1342 orientation: V.CanFlip ? this.game.mycolor : "w"
1343 });
1344 document.querySelector("#confirmDiv > .card").style.width =
1345 boardDiv.offsetWidth + "px";
1346 } else {
1347 // Incomplete information: just ask confirmation
1348 // Hide the board, because otherwise it could reveal infos
1349 boardDiv.style.visibility = "hidden";
1350 this.moveNotation = getFullNotation(move);
1351 }
1352 document.getElementById("modalConfirm").checked = true;
1353 }
1354 else {
1355 // Normal situation
1356 if (!!data.score && data.score != "*")
1357 this.gameOver(data.score, null, doProcessMove);
1358 else doProcessMove();
1359 }
1360 },
1361 cancelMove: function() {
1362 let boardDiv = document.querySelector(".game");
1363 if (boardDiv.style.visibility == "hidden")
1364 boardDiv.style.visibility = "visible";
1365 document.getElementById("modalConfirm").checked = false;
1366 this.$refs["basegame"].cancelLastMove();
1367 },
1368 // In corr games, callback to change page only after score is set:
1369 gameOver: function(score, scoreMsg, callback) {
1370 this.game.score = score;
1371 if (!scoreMsg) scoreMsg = getScoreMessage(score);
1372 this.game.scoreMsg = scoreMsg;
1373 this.$set(this.game, "scoreMsg", scoreMsg);
1374 const myIdx = this.game.players.findIndex(p => {
1375 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
1376 });
1377 if (myIdx >= 0) {
1378 // OK, I play in this game
1379 const scoreObj = {
1380 score: score,
1381 scoreMsg: scoreMsg
1382 };
1383 if (this.game.type == "live") {
1384 GameStorage.update(this.gameRef.id, scoreObj);
1385 if (!!callback) callback();
1386 }
1387 else this.updateCorrGame(scoreObj, callback);
1388 // Notify the score to main Hall. TODO: only one player (currently double send)
1389 this.send("result", { gid: this.game.id, score: score });
1390 // Also to MyGames page (TODO: doubled as well...)
1391 this.notifyMyGames(
1392 "score",
1393 {
1394 gid: this.gameRef.id,
1395 score: score
1396 }
1397 );
1398 }
1399 else if (!!callback) callback();
1400 }
1401 }
1402 };
1403 </script>
1404
1405 <style lang="sass" scoped>
1406 #infoDiv > .card
1407 padding: 15px 0
1408 max-width: 430px
1409
1410 .connected
1411 background-color: lightgreen
1412
1413 #participants
1414 margin-left: 5px
1415
1416 .anonymous
1417 color: grey
1418 font-style: italic
1419
1420 #playersInfo > p
1421 margin: 0
1422
1423 @media screen and (min-width: 768px)
1424 #actions
1425 width: 300px
1426 @media screen and (max-width: 767px)
1427 .game
1428 width: 100%
1429
1430 #actions
1431 display: inline-block
1432 margin: 0
1433
1434 button
1435 display: inline-block
1436 margin: 0
1437 display: inline-flex
1438 img
1439 height: 24px
1440 display: flex
1441 @media screen and (max-width: 767px)
1442 height: 18px
1443
1444 @media screen and (max-width: 767px)
1445 #aboveBoard
1446 text-align: center
1447 @media screen and (min-width: 768px)
1448 #aboveBoard
1449 margin-left: 30%
1450
1451 .variant-cadence
1452 padding-right: 10px
1453
1454 .variant-name
1455 font-weight: bold
1456 padding-right: 10px
1457
1458 span#nextGame
1459 background-color: #edda99
1460 cursor: pointer
1461 display: inline-block
1462 margin-right: 10px
1463
1464 span.name
1465 font-size: 1.5rem
1466 padding: 0 3px
1467
1468 span.time
1469 font-size: 2rem
1470 display: inline-block
1471 .time-left
1472 margin-left: 10px
1473 .time-right
1474 margin-left: 5px
1475 .time-separator
1476 margin-left: 5px
1477 position: relative
1478 top: -1px
1479
1480 span.yourturn
1481 color: #831B1B
1482 .time-separator
1483 animation: blink-animation 2s steps(3, start) infinite
1484 @keyframes blink-animation
1485 to
1486 visibility: hidden
1487
1488 .split-names
1489 display: inline-block
1490 margin: 0 15px
1491
1492 #chatWrap > .card
1493 padding-top: 20px
1494 max-width: 767px
1495 border: none
1496
1497 #confirmDiv > .card
1498 max-width: 767px
1499 max-height: 100%
1500
1501 .draw-sent, .draw-sent:hover
1502 background-color: lightyellow
1503
1504 .draw-received, .draw-received:hover
1505 background-color: lightgreen
1506
1507 .draw-threerep, .draw-threerep:hover
1508 background-color: #e4d1fc
1509
1510 .rematch-sent, .rematch-sent:hover
1511 background-color: lightyellow
1512
1513 .rematch-received, .rematch-received:hover
1514 background-color: lightgreen
1515
1516 .somethingnew
1517 background-color: #c5fefe
1518
1519 .diagram
1520 margin: 0 auto
1521 width: 100%
1522
1523 #buttonsConfirm
1524 margin: 0
1525 & > button > span
1526 width: 100%
1527 text-align: center
1528
1529 button.acceptBtn
1530 background-color: lightgreen
1531 button.refuseBtn
1532 background-color: red
1533 </style>