Typo
[vchess.git] / client / src / views / Game.vue
CommitLineData
a6088c90 1<template lang="pug">
7aa548e7 2main
07052665
BA
3 input#modalRules.modal(type="checkbox")
4 div#rulesDiv(
5 role="dialog"
6 data-checkbox="modalRules"
7 )
8 .card
9 label.modal-close(for="modalRules")
eaa5ad3e 10 a#variantNameInGame(:href="'/#/variants/'+game.vname") {{ game.vdisp }}
07052665 11 div(v-html="rulesContent")
3ca0ef9e
BA
12 input#modalScore.modal(type="checkbox")
13 div#scoreDiv(
c292ebb2 14 role="dialog"
3ca0ef9e 15 data-checkbox="modalScore"
c292ebb2
BA
16 )
17 .card.text-center
3ca0ef9e 18 label.modal-close(for="modalScore")
af34341d 19 p.score-section
3ca0ef9e
BA
20 span.score {{ game.score }}
21 | &nbsp;:&nbsp;
22 span.score-msg {{ st.tr[game.scoreMsg] }}
23 input#modalRematch.modal(type="checkbox")
24 div#rematchDiv(
25 role="dialog"
26 data-checkbox="modalRematch"
27 )
28 .card.text-center
29 label.modal-close(for="modalRematch")
f14572c4
BA
30 a(
31 :href="'#/game/' + rematchId"
3ca0ef9e 32 onClick="document.getElementById('modalRematch').checked=false"
f14572c4
BA
33 )
34 | {{ st.tr["Rematch in progress"] }}
910d631b
BA
35 input#modalChat.modal(
36 type="checkbox"
8be8238c 37 @click="toggleChat()"
910d631b
BA
38 )
39 div#chatWrap(
40 role="dialog"
41 data-checkbox="modalChat"
42 )
5b4de147 43 .card
a1c48034 44 label.modal-close(for="modalChat")
ed06d9e9 45 #participants
afde7666 46 span {{ st.tr["Participant(s):"] }}
910d631b
BA
47 span(
48 v-for="p in Object.values(people)"
964eda04 49 v-if="!!p.name"
910d631b 50 )
ed06d9e9 51 | {{ p.name }}
7ebc0408 52 span.anonymous(v-if="someAnonymousPresent()") + @nonymous
910d631b 53 Chat(
aae89b49 54 ref="chatcomp"
910d631b
BA
55 :players="game.players"
56 :pastChats="game.chats"
910d631b 57 @mychat="processChat"
db1f1f9a 58 @chatcleared="clearChat"
910d631b 59 )
5b4de147
BA
60 input#modalConfirm.modal(type="checkbox")
61 div#confirmDiv(role="dialog")
62 .card
a17ae317
BA
63 .diagram(
64 v-if="!!vr && ['all','byrow'].includes(vr.showMoves)"
65 v-html="curDiag"
66 )
67 p.text-center(v-else)
68 span {{ st.tr["Move played:"] + " " }}
69 span.bold {{ moveNotation }}
70 br
71 span {{ st.tr["Are you sure?"] }}
5b4de147
BA
72 .button-group#buttonsConfirm
73 // onClick for acceptBtn: set dynamically
74 button.acceptBtn
75 span {{ st.tr["Validate"] }}
76 button.refuseBtn(@click="cancelMove()")
77 span {{ st.tr["Cancel"] }}
7aa548e7 78 .row
07052665 79 #aboveBoard.col-sm-12
1ef65040 80 span.variant-cadence(v-if="game.type!='import'") {{ game.cadence }}
eb2d61de
BA
81 span.variant-name
82 | {{ game.vname }}
3d9745ae 83 | {{ !!vr ? vr.constructor.AbbreviateOptions(game.options) : '' }}
feaf1bf7
BA
84 span#nextGame(
85 v-if="nextIds.length > 0"
86 @click="showNextGame()"
87 )
88 | {{ st.tr["Next_g"] }}
1e02d16d
BA
89 button#chatBtn(
90 :class="btnTooltipClass()"
feaf1bf7
BA
91 onClick="window.doClick('modalChat')"
92 aria-label="Chat"
93 )
94 img(src="/images/icons/chat.svg")
f296c3d4 95 #actions(v-if="game.score=='*'")
1e02d16d 96 button(
910d631b 97 @click="clickDraw()"
1e02d16d 98 :class="btnTooltipClass('draw')"
feaf1bf7 99 :aria-label="st.tr['Draw']"
910d631b 100 )
feaf1bf7 101 img(src="/images/icons/draw.svg")
1e02d16d
BA
102 button(
103 v-if="!!game.mycolor"
104 :class="btnTooltipClass()"
910d631b 105 @click="abortGame()"
feaf1bf7 106 :aria-label="st.tr['Abort']"
910d631b 107 )
feaf1bf7 108 img(src="/images/icons/abort.svg")
1e02d16d
BA
109 button(
110 v-if="!!game.mycolor"
111 :class="btnTooltipClass()"
910d631b 112 @click="resign()"
feaf1bf7 113 :aria-label="st.tr['Resign']"
910d631b 114 )
feaf1bf7 115 img(src="/images/icons/resign.svg")
1e02d16d 116 button(
f296c3d4 117 v-else
1e02d16d 118 :class="btnTooltipClass('rematch')"
c292ebb2 119 @click="clickRematch()"
feaf1bf7
BA
120 :aria-label="st.tr['Rematch']"
121 )
122 img(src="/images/icons/rematch.svg")
050ae3b5 123 #playersInfo
847ba842 124 div(v-if="isLargeScreen()")
80b38d46
BA
125 UserBio.user-bio(
126 :class="{connected: isConnected(0)}"
127 :uid="game.players[0].id"
128 :uname="game.players[0].name"
129 )
57eb158f
BA
130 span.time(
131 v-if="game.score=='*'"
132 :class="{yourturn: !!vr && vr.turn == 'w'}"
133 )
134 span.time-left {{ virtualClocks[0][0] }}
135 span.time-separator(v-if="!!virtualClocks[0][1]") :
aae89b49
BA
136 span.time-right(v-if="!!virtualClocks[0][1]")
137 | {{ virtualClocks[0][1] }}
050ae3b5 138 span.split-names -
80b38d46
BA
139 UserBio.user-bio(
140 :class="{connected: isConnected(1)}"
141 :uid="game.players[1].id"
142 :uname="game.players[1].name"
143 )
57eb158f
BA
144 span.time(
145 v-if="game.score=='*'"
146 :class="{yourturn: !!vr && vr.turn == 'b'}"
147 )
148 span.time-left {{ virtualClocks[1][0] }}
149 span.time-separator(v-if="!!virtualClocks[1][1]") :
aae89b49
BA
150 span.time-right(v-if="!!virtualClocks[1][1]")
151 | {{ virtualClocks[1][1] }}
847ba842 152 div(v-else)
80b38d46
BA
153 UserBio.user-bio(
154 :class="{connected: isConnected(0)}"
155 :uid="game.players[0].id"
156 :uname="game.players[0].name"
157 )
49dad261 158 span.split-names -
80b38d46
BA
159 UserBio.user-bio(
160 :class="{connected: isConnected(1)}"
161 :uid="game.players[1].id"
162 :uname="game.players[1].name"
163 )
1e02d16d
BA
164 div(v-if="game.score=='*'")
165 span.time(:class="{yourturn: !!vr && vr.turn == 'w'}")
166 span.time-left {{ virtualClocks[0][0] }}
167 span.time-separator(v-if="!!virtualClocks[0][1]") :
168 span.time-right(v-if="!!virtualClocks[0][1]")
169 | {{ virtualClocks[0][1] }}
170 span.separator
171 span.time(:class="{yourturn: !!vr && vr.turn == 'b'}")
172 span.time-left {{ virtualClocks[1][0] }}
173 span.time-separator(v-if="!!virtualClocks[1][1]") :
174 span.time-right(v-if="!!virtualClocks[1][1]")
175 | {{ virtualClocks[1][1] }}
910d631b 176 BaseGame(
8477e53d 177 ref="basegame"
910d631b 178 :game="game"
910d631b 179 @newmove="processMove"
910d631b 180 )
a6088c90
BA
181</template>
182
183<script>
46284a2f 184import BaseGame from "@/components/BaseGame.vue";
80b38d46 185import UserBio from "@/components/UserBio.vue";
f21cd6d9 186import Chat from "@/components/Chat.vue";
a6088c90 187import { store } from "@/store";
967a2686 188import { GameStorage } from "@/utils/gameStorage";
5f918a27 189import { ImportgameStorage } from "@/utils/importgameStorage";
5b87454c 190import { ppt } from "@/utils/datetime";
f5768809 191import { notify } from "@/utils/notifications";
23ecf008 192import { ajax } from "@/utils/ajax";
66d03f23 193import { extractTime } from "@/utils/timeControl";
51d87b52 194import { getRandString } from "@/utils/alea";
5aa14a21
BA
195import { getScoreMessage } from "@/utils/scoring";
196import { getFullNotation } from "@/utils/notation";
07052665 197import { getDiagram, replaceByDiag } from "@/utils/printDiagram";
dcd68c41 198import { processModalClick } from "@/utils/modalClick";
e71161fb 199import { playMove, getFilteredMove } from "@/utils/playUndo";
1611a25f 200import { ArrayFun } from "@/utils/array";
70c9745d 201import afterRawLoad from "@/utils/afterRawLoad";
8418f0d7 202import params from "@/parameters";
a6088c90 203export default {
6808d7a1 204 name: "my-game",
a6088c90
BA
205 components: {
206 BaseGame,
80b38d46
BA
207 Chat,
208 UserBio
a6088c90 209 },
a6088c90
BA
210 data: function() {
211 return {
212 st: store.state,
f54f4c26
BA
213 // gameRef can point to a corr game, local game or remote live game
214 gameRef: "",
feaf1bf7 215 nextIds: [],
aae89b49 216 game: {}, //passed to BaseGame
1a3cfdc0 217 focus: !document.hidden, //will not always work... TODO
aae89b49 218 // virtualClocks will be initialized from true game.clocks
d060d8cb 219 // TODO: clock update triggers re-rendering. Should be out of Vue
aae89b49 220 virtualClocks: [],
6dd02928 221 vr: null, //"variant rules" object initialized from FEN
07052665 222 rulesContent: "",
dcd68c41 223 drawOffer: "",
585d0955 224 rematchId: "",
c292ebb2 225 rematchOffer: "",
584f81b9 226 lastateAsked: false,
dcd68c41 227 people: {}, //players + observers
760adbce 228 lastate: undefined, //used if opponent send lastate before game is ready
72ccbd67 229 repeat: {}, //detect position repetition
5b4de147 230 curDiag: "", //for corr moves confirmation
8418f0d7 231 conn: null,
f9c36b2d 232 roomInitialized: false,
f9c36b2d
BA
233 // If asklastate got no reply, ask again:
234 gotLastate: false,
e5c1d0fb 235 gotMoveIdx: -1, //last move index received
f9c36b2d
BA
236 // If newmove got no pingback, send again:
237 opponentGotMove: false,
51d87b52 238 connexionString: "",
16d06164
BA
239 reopenTimeout: 0,
240 reconnectTimeout: 0,
a17ae317
BA
241 // Incomplete info games: show move played
242 moveNotation: "",
aae89b49 243 // Intervals from setInterval():
aae89b49
BA
244 askLastate: null,
245 retrySendmove: null,
246 clockUpdate: null,
51d87b52 247 // Related to (killing of) self multi-connects:
49dad261 248 newConnect: {}
a6088c90
BA
249 };
250 },
251 watch: {
aae89b49 252 $route: function(to, from) {
7ebc0408 253 if (to.path.length < 6 || to.path.substr(0, 6) != "/game/")
1112f1fd
BA
254 // Page change
255 this.cleanBeforeDestroy();
256 else if (from.params["id"] != to.params["id"]) {
aae89b49
BA
257 // Change everything:
258 this.cleanBeforeDestroy();
5aa14a21
BA
259 let boardDiv = document.querySelector(".game");
260 if (!!boardDiv)
261 // In case of incomplete information variant:
262 boardDiv.style.visibility = "hidden";
aae89b49 263 this.atCreation();
58aedcd1
BA
264 }
265 else
aae89b49 266 // Same game ID
aae89b49 267 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
6808d7a1 268 }
92a523d1 269 },
71468011 270 // NOTE: some redundant code with Hall.vue (mostly related to people array)
a6088c90 271 created: function() {
aae89b49 272 this.atCreation();
cdb34c93 273 },
dcd68c41 274 mounted: function() {
1ef65040
BA
275 document.getElementById("chatWrap")
276 .addEventListener("click", (e) => {
277 processModalClick(e, () => {
278 this.toggleChat("close")
279 });
280 });
07052665 281 ["rulesDiv", "rematchDiv", "scoreDiv"].forEach(
3ca0ef9e
BA
282 (eltName) => {
283 document.getElementById(eltName)
284 .addEventListener("click", processModalClick);
285 }
286 );
dcd68c41 287 },
8418f0d7 288 beforeDestroy: function() {
aae89b49 289 this.cleanBeforeDestroy();
8418f0d7 290 },
cdb34c93 291 methods: {
1112f1fd
BA
292 cleanBeforeDestroy: function() {
293 document.removeEventListener('visibilitychange', this.visibilityChange);
f5768809
BA
294 window.removeEventListener('focus', this.onFocus);
295 window.removeEventListener('blur', this.onBlur);
7ebc0408
BA
296 if (!!this.askLastate) clearInterval(this.askLastate);
297 if (!!this.retrySendmove) clearInterval(this.retrySendmove);
298 if (!!this.clockUpdate) clearInterval(this.clockUpdate);
16d06164 299 clearTimeout(this.reopenTimeout);
1112f1fd 300 this.send("disconnect");
68e3aa8c 301 this.conn = null;
1112f1fd 302 },
a041d5d8
BA
303 visibilityChange: function() {
304 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
f5768809 305 this.focus = (document.visibilityState == "visible");
f5768809
BA
306 this.send(this.focus ? "getfocus" : "losefocus");
307 },
308 onFocus: function() {
309 this.focus = true;
310 this.send("getfocus");
311 },
312 onBlur: function() {
313 this.focus = false;
f5768809 314 this.send("losefocus");
a041d5d8 315 },
5d4a9ad4 316 isLargeScreen: function() {
847ba842 317 return window.innerWidth >= 768;
5d4a9ad4 318 },
1e02d16d
BA
319 btnTooltipClass: function(thing) {
320 let append = {};
321 if (!!thing) append = { [thing + "-" + this[thing + "Offer"]]: true };
322 return (
323 Object.assign(
324 { tooltip: !("ontouchstart" in window) },
325 append
326 )
327 );
328 },
7ebc0408
BA
329 someAnonymousPresent: function() {
330 return (
331 Object.values(this.people).some(p =>
332 !p.name && Object.keys(p.tmpIds).some(x => p.tmpIds[x].focus)
333 )
334 );
335 },
4313762d
BA
336 requestLastate: function(sid) {
337 // TODO: maybe also find opponent SID ?
338 //const oppSid =
339 // this.game.players.find(p => p.sid != this.st.user.sid).sid;
340 this.send("asklastate", { target: sid });
341 let counter = 1;
342 this.askLastate = setInterval(
343 () => {
344 // Ask at most 3 times:
345 // if no reply after that there should be a network issue.
346 if (
347 counter < 3 &&
348 !this.gotLastate &&
349 !!this.people[sid]
350 ) {
351 this.send("asklastate", { target: sid });
352 counter++;
353 }
354 else clearInterval(this.askLastate);
355 },
356 1500
357 );
358 },
aae89b49 359 atCreation: function() {
1112f1fd 360 document.addEventListener('visibilitychange', this.visibilityChange);
f5768809
BA
361 window.addEventListener('focus', this.onFocus);
362 window.addEventListener('blur', this.onBlur);
aae89b49 363 // 0] (Re)Set variables
f54f4c26
BA
364 this.gameRef = this.$route.params["id"];
365 // next = next corr games IDs to navigate faster (if applicable)
aae89b49
BA
366 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
367 // Always add myself to players' list
368 const my = this.st.user;
7ebc0408 369 const tmpId = getRandString();
a041d5d8
BA
370 this.$set(
371 this.people,
372 my.sid,
373 {
374 id: my.id,
375 name: my.name,
7ebc0408 376 tmpIds: {
16d06164 377 [tmpId]: { focus: true }
7ebc0408 378 }
a041d5d8
BA
379 }
380 );
aae89b49
BA
381 this.game = {
382 players: [{ name: "" }, { name: "" }],
383 chats: [],
384 rendered: false
385 };
386 let chatComp = this.$refs["chatcomp"];
387 if (!!chatComp) chatComp.chats = [];
388 this.virtualClocks = [[0,0], [0,0]];
389 this.vr = null;
07052665 390 this.rulesContent = "";
aae89b49 391 this.drawOffer = "";
584f81b9 392 this.lastateAsked = false;
c292ebb2 393 this.rematchOffer = "";
aae89b49 394 this.lastate = undefined;
aae89b49 395 this.roomInitialized = false;
aae89b49
BA
396 this.gotLastate = false;
397 this.gotMoveIdx = -1;
398 this.opponentGotMove = false;
aae89b49
BA
399 this.askLastate = null;
400 this.retrySendmove = null;
401 this.clockUpdate = null;
402 this.newConnect = {};
aae89b49
BA
403 // 1] Initialize connection
404 this.connexionString =
405 params.socketUrl +
7ebc0408
BA
406 "/?sid=" + this.st.user.sid +
407 "&id=" + this.st.user.id +
408 "&tmpId=" + tmpId +
aae89b49
BA
409 "&page=" +
410 // Discard potential "/?next=[...]" for page indication:
411 encodeURIComponent(this.$route.path.match(/\/game\/[a-zA-Z0-9]+/)[0]);
e9d5a418 412 this.openConnection();
16d06164
BA
413 },
414 openConnection: function() {
aae89b49 415 this.conn = new WebSocket(this.connexionString);
16d06164
BA
416 const onOpen = () => {
417 this.reconnectTimeout = 250;
418 const oppSid = this.getOppsid();
419 if (!!oppSid) this.requestLastate(oppSid); //in case of
420 };
421 this.conn.onopen = onOpen;
422 this.conn.onmessage = this.socketMessageListener;
423 const closeConnection = () => {
424 this.reopenTimeout = setTimeout(
425 () => {
426 this.openConnection();
427 this.reconnectTimeout = Math.min(2*this.reconnectTimeout, 30000);
428 },
429 this.reconnectTimeout
430 );
431 };
432 this.conn.onerror = closeConnection;
433 this.conn.onclose = closeConnection;
aae89b49
BA
434 // Socket init required before loading remote game:
435 const socketInit = callback => {
3f22c2c3 436 if (this.conn.readyState == 1)
aae89b49
BA
437 // 1 == OPEN state
438 callback();
16d06164 439 else {
aae89b49 440 // Socket not ready yet (initial loading)
f54f4c26 441 // NOTE: first arg is Websocket object, unused here:
16d06164
BA
442 this.conn.onopen = () => {
443 onOpen();
444 callback();
445 };
446 }
aae89b49 447 };
f54f4c26 448 this.fetchGame((game) => {
eb2d61de
BA
449 if (!!game) {
450 if (!game.options) {
451 // Patch for retro-compatibility (TODO: remove it)
452 game.options = { randomness: game.randomness };
453 delete game["randomness"];
454 }
455 else game.options = JSON.parse(game.options);
f54f4c26 456 this.loadVariantThenGame(game, () => socketInit(this.roomInit));
eb2d61de 457 }
f54f4c26
BA
458 else
459 // Live game stored remotely: need socket to retrieve it
2c5d7b20 460 // NOTE: the callback "roomInit" will be lost, so it's not provided.
f54f4c26
BA
461 // --> It will be given when receiving "fullgame" socket event.
462 socketInit(() => { this.send("askfullgame"); });
463 });
aae89b49 464 },
760adbce 465 roomInit: function() {
f9c36b2d
BA
466 if (!this.roomInitialized) {
467 // Notify the room only now that I connected, because
468 // messages might be lost otherwise (if game loading is slow)
469 this.send("connect");
470 this.send("pollclients");
471 // We may ask fullgame several times if some moves are lost,
472 // but room should be init only once:
473 this.roomInitialized = true;
474 }
71468011
BA
475 },
476 send: function(code, obj) {
5a187b07 477 if (!!this.conn && this.conn.readyState == 1)
6808d7a1 478 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
5f131484 479 },
050ae3b5 480 isConnected: function(index) {
29ced362 481 const player = this.game.players[index];
a041d5d8 482 // Is it me ? In this case no need to bother with focus
751d7ca4
BA
483 if (
484 this.st.user.sid == player.sid ||
485 (!!player.name && this.st.user.id == player.id)
486 ) {
0a17525e
BA
487 // Still have to check for name (because of potential multi-accounts
488 // on same browser, although this should be rare...)
489 return (!this.st.user.name || this.st.user.name == player.name);
751d7ca4 490 }
29ced362 491 // Try to find a match in people:
6808d7a1 492 return (
1611a25f 493 (
a041d5d8 494 !!player.sid &&
7ebc0408
BA
495 Object.keys(this.people).some(sid => {
496 return (
497 sid == player.sid &&
498 Object.values(this.people[sid].tmpIds).some(v => v.focus)
499 );
500 })
1611a25f
BA
501 )
502 ||
503 (
751d7ca4 504 player.id > 0 &&
7ebc0408
BA
505 Object.values(this.people).some(p => {
506 return (
507 p.id == player.id &&
508 Object.values(p.tmpIds).some(v => v.focus)
509 );
510 })
1611a25f 511 )
6808d7a1 512 );
050ae3b5 513 },
c292ebb2
BA
514 getOppsid: function() {
515 let oppsid = this.game.oppsid;
516 if (!oppsid) {
517 oppsid = Object.keys(this.people).find(
518 sid => this.people[sid].id == this.game.oppid
519 );
520 }
521 // oppsid is useful only if opponent is online:
522 if (!!oppsid && !!this.people[oppsid]) return oppsid;
523 return null;
524 },
1ef65040
BA
525 // NOTE: action if provided is always a closing action
526 toggleChat: function(action) {
527 if (!action && document.getElementById("modalChat").checked)
8be8238c
BA
528 // Entering chat
529 document.getElementById("inputChat").focus();
1ef65040
BA
530 else {
531 document.getElementById("chatBtn").classList.remove("somethingnew");
532 if (!!this.game.mycolor) {
533 // Update "chatRead" variable either on server or locally
534 if (this.game.type == "corr")
535 this.updateCorrGame({ chatRead: this.game.mycolor });
536 else if (this.game.type == "live")
537 GameStorage.update(this.gameRef, { chatRead: true });
538 }
539 }
db1f1f9a
BA
540 },
541 processChat: function(chat) {
542 this.send("newchat", { data: chat });
543 // NOTE: anonymous chats in corr games are not stored on server (TODO?)
1ef65040
BA
544 if (!!this.game.mycolor) {
545 if (this.game.type == "corr")
546 this.updateCorrGame({ chat: chat });
547 else {
548 // Live game
549 chat.added = Date.now();
550 GameStorage.update(this.gameRef, { chat: chat });
551 }
1a021529 552 }
db1f1f9a
BA
553 },
554 clearChat: function() {
1a021529
BA
555 if (!!this.game.mycolor) {
556 if (this.game.type == "corr") {
e57c4de4
BA
557 ajax(
558 "/chats",
559 "DELETE",
560 { data: { gid: this.game.id } }
561 );
4a209313
BA
562 }
563 else {
1a021529
BA
564 // Live game
565 GameStorage.update(this.gameRef, { delchat: true });
e57c4de4 566 }
dcff8e82 567 this.$set(this.game, "chats", []);
db1f1f9a
BA
568 }
569 },
584f81b9 570 getGameType: function(game) {
a8ed3182 571 if (!!game.id.toString().match(/^i/)) return "import";
50330595 572 return (game.cadence.indexOf("d") >= 0 ? "corr" : "live");
584f81b9 573 },
cafe0166
BA
574 // Notify something after a new move (to opponent and me on MyGames page)
575 notifyMyGames: function(thing, data) {
576 this.send(
577 "notify" + thing,
578 {
579 data: data,
580 targets: this.game.players.map(p => {
0234201f 581 return { sid: p.sid, id: p.id };
cafe0166
BA
582 })
583 }
584 );
1611a25f 585 },
feaf1bf7
BA
586 showNextGame: function() {
587 // Did I play in current game? If not, add it to nextIds list
588 if (this.game.score == "*" && this.vr.turn == this.game.mycolor)
589 this.nextIds.unshift(this.game.id);
590 const nextGid = this.nextIds.pop();
591 this.$router.push(
592 "/game/" + nextGid + "/?next=" + JSON.stringify(this.nextIds));
593 },
cdb34c93 594 socketMessageListener: function(msg) {
6808d7a1 595 if (!this.conn) return;
a6088c90 596 const data = JSON.parse(msg.data);
6808d7a1 597 switch (data.code) {
5f131484 598 case "pollclients":
7ebc0408
BA
599 // TODO: shuffling and random filtering on server,
600 // if the room is really crowded.
601 Object.keys(data.sockIds).forEach(sid => {
a041d5d8 602 if (sid != this.st.user.sid) {
6808d7a1 603 this.send("askidentity", { target: sid });
0d5335de 604 this.people[sid] = { tmpIds: data.sockIds[sid] };
3d65195b
BA
605 }
606 else {
0d5335de
BA
607 // Complete my tmpIds:
608 Object.assign(this.people[sid].tmpIds, data.sockIds[sid]);
a041d5d8 609 }
5f131484
BA
610 });
611 break;
71468011 612 case "connect":
7ebc0408
BA
613 if (!this.people[data.from[0]]) {
614 // focus depends on the tmpId (e.g. tab)
615 this.$set(
616 this.people,
617 data.from[0],
618 {
619 tmpIds: {
620 [data.from[1]]: { focus: true }
621 }
622 }
623 );
49dad261
BA
624 // For self multi-connects tests:
625 this.newConnect[data.from[0]] = true;
7ebc0408 626 this.send("askidentity", { target: data.from[0] });
4a209313
BA
627 }
628 else {
7ebc0408 629 this.people[data.from[0]].tmpIds[data.from[1]] = { focus: true };
a2bd587a 630 this.$forceUpdate(); //TODO: shouldn't be required
51d87b52 631 }
71468011
BA
632 break;
633 case "disconnect":
7ebc0408
BA
634 if (!this.people[data.from[0]]) return;
635 delete this.people[data.from[0]].tmpIds[data.from[1]];
636 if (Object.keys(this.people[data.from[0]].tmpIds).length == 0)
637 this.$delete(this.people, data.from[0]);
638 else this.$forceUpdate(); //TODO: shouldn't be required
71468011 639 break;
a041d5d8 640 case "getfocus": {
7ebc0408 641 let player = this.people[data.from[0]];
a041d5d8 642 if (!!player) {
7ebc0408 643 player.tmpIds[data.from[1]].focus = true;
a041d5d8
BA
644 this.$forceUpdate(); //TODO: shouldn't be required
645 }
646 break;
647 }
648 case "losefocus": {
7ebc0408 649 let player = this.people[data.from[0]];
a041d5d8 650 if (!!player) {
7ebc0408 651 player.tmpIds[data.from[1]].focus = false;
a041d5d8
BA
652 this.$forceUpdate(); //TODO: shouldn't be required
653 }
654 break;
655 }
6808d7a1 656 case "askidentity": {
efdfb4c7 657 // Request for identification
51d87b52
BA
658 const me = {
659 // Decompose to avoid revealing email
660 name: this.st.user.name,
661 sid: this.st.user.sid,
6808d7a1 662 id: this.st.user.id
51d87b52 663 };
6808d7a1 664 this.send("identity", { data: me, target: data.from });
5f131484 665 break;
51d87b52 666 }
6808d7a1 667 case "identity": {
71468011 668 const user = data.data;
a041d5d8 669 let player = this.people[user.sid];
7ebc0408 670 // player.tmpIds is already set
a041d5d8
BA
671 player.name = user.name;
672 player.id = user.id;
3d65195b
BA
673 if (this.game.type == "live") {
674 const myGidx =
675 this.game.players.findIndex(p => p.sid == this.st.user.sid);
676 // Sometimes a player name isn't stored yet (TODO: why?)
677 if (
678 myGidx >= 0 &&
679 !this.game.players[1 - myGidx].name &&
680 this.game.players[1 - myGidx].sid == user.sid &&
681 !!user.name
682 ) {
683 this.game.players[1-myGidx].name = user.name;
684 GameStorage.update(
685 this.gameRef,
686 { playerName: { idx: 1 - myGidx, name: user.name } }
687 );
688 }
689 }
a041d5d8 690 this.$forceUpdate(); //TODO: shouldn't be required
f9c36b2d
BA
691 // If I multi-connect, kill current connexion if no mark (I'm older)
692 if (this.newConnect[user.sid]) {
49dad261 693 delete this.newConnect[user.sid];
6808d7a1 694 if (
6808d7a1
BA
695 user.id > 0 &&
696 user.id == this.st.user.id &&
49dad261 697 user.sid != this.st.user.sid
6808d7a1 698 ) {
49dad261
BA
699 this.cleanBeforeDestroy();
700 alert(this.st.tr["New connexion detected: tab now offline"]);
701 break;
51d87b52 702 }
a0c41e7e 703 }
49dad261
BA
704 // Ask potentially missed last state, if opponent and I play
705 if (
706 !this.gotLastate &&
707 !!this.game.mycolor &&
708 this.game.type == "live" &&
49dad261
BA
709 this.game.players.some(p => p.sid == user.sid)
710 ) {
8899888e 711 this.requestLastate(user.sid);
dcff8e82 712 }
a0c41e7e 713 break;
71468011
BA
714 }
715 case "askgame":
1ef65040
BA
716 // Send current (live or import) game,
717 // if not asked by any of the players
6808d7a1 718 if (
1ef65040 719 this.game.type != "corr" &&
6808d7a1
BA
720 this.game.players.every(p => p.sid != data.from[0])
721 ) {
71468011
BA
722 const myGame = {
723 id: this.game.id,
1ef65040 724 // FEN is current position, unused for now
71468011
BA
725 fen: this.game.fen,
726 players: this.game.players,
727 vid: this.game.vid,
728 cadence: this.game.cadence,
f54f4c26 729 score: this.game.score
71468011 730 };
6808d7a1 731 this.send("game", { data: myGame, target: data.from });
71468011
BA
732 }
733 break;
734 case "askfullgame":
e8da204a
BA
735 const gameToSend = Object.keys(this.game)
736 .filter(k =>
737 [
eb2d61de 738 "id","fen","players","vid","cadence","fenStart","options",
3f22c2c3 739 "moves","clocks","score","drawOffer","rematchOffer"
e8da204a
BA
740 ].includes(k))
741 .reduce(
742 (obj, k) => {
743 obj[k] = this.game[k];
744 return obj;
745 },
746 {}
747 );
748 this.send("fullgame", { data: gameToSend, target: data.from });
71468011
BA
749 break;
750 case "fullgame":
c7550017
BA
751 if (!!data.data.empty) {
752 alert(this.st.tr["The game should be in another tab"]);
753 this.$router.go(-1);
754 }
755 else
756 // Callback "roomInit" to poll clients only after game is loaded
757 this.loadVariantThenGame(data.data, this.roomInit);
71468011 758 break;
a0c41e7e 759 case "asklastate":
dcff8e82 760 // Sending informative last state if I played a move or score != "*"
584f81b9 761 // If the game or moves aren't loaded yet, delay the sending:
2c5d7b20 762 // TODO: socket init after game load, so the game is supposedly ready
584f81b9
BA
763 if (!this.game || !this.game.moves) this.lastateAsked = true;
764 else this.sendLastate(data.from);
c6788ecf 765 break;
4f524197
BA
766 // TODO: possible bad scenario: reload page while oppponent sends a
767 // move => get both lastate and newmove, process both, add move twice.
768 // Confirm scenario? Fix?
dcff8e82
BA
769 case "lastate": {
770 // Got opponent infos about last move
771 this.gotLastate = true;
3f22c2c3 772 this.lastate = data.data;
b9ce3d0f
BA
773 if (this.lastate.movesCount - 1 > this.gotMoveIdx)
774 this.gotMoveIdx = this.lastate.movesCount - 1;
3f22c2c3
BA
775 if (this.game.rendered)
776 // Game is rendered (Board component)
777 this.processLastate();
778 // Else: will be processed when game is ready
71468011 779 break;
dcff8e82 780 }
6808d7a1 781 case "newmove": {
a6363ac1
BA
782
783// DEBUG:
50330595
BA
784//console.log("Receive move");
785//console.log(data.data);
786//moveslist not updated when receiving a move? (see in BaseGame)
a6363ac1 787
dcff8e82
BA
788 const movePlus = data.data;
789 const movesCount = this.game.moves.length;
ad030c7d
BA
790 if (
791 movePlus.index < movesCount ||
792 this.gotMoveIdx >= movePlus.index
793 ) {
794 // Opponent re-send but we already have the move:
795 // (maybe he didn't receive our pingback...)
796 this.send("gotmove", {data: movePlus.index, target: data.from});
d6f08e56
BA
797 }
798 else {
ad030c7d
BA
799 this.gotMoveIdx = movePlus.index;
800 const receiveMyMove = (movePlus.color == this.game.mycolor);
801 const moveColIdx = ["w", "b"].indexOf(movePlus.color);
802 if (!receiveMyMove && !!this.game.mycolor) {
803 // Notify opponent that I got the move:
804 this.send(
805 "gotmove",
806 { data: movePlus.index, target: data.from }
807 );
808 // And myself if I'm elsewhere:
809 if (!this.focus) {
810 notify(
811 "New move",
812 {
813 body:
814 (this.game.players[moveColIdx].name || "@nonymous") +
815 " just played."
816 }
2c5d7b20 817 );
f5768809 818 }
ad030c7d
BA
819 }
820 if (movePlus.cancelDrawOffer) {
821 // Opponent refuses draw
822 this.drawOffer = "";
823 // NOTE for corr games: drawOffer reset by player in turn
824 if (
825 this.game.type == "live" &&
826 !!this.game.mycolor &&
827 !receiveMyMove
828 ) {
829 GameStorage.update(this.gameRef, { drawOffer: "" });
f9c36b2d 830 }
f9c36b2d 831 }
ad030c7d
BA
832 this.$refs["basegame"].play(movePlus.move, "received");
833 // Freeze time while the move is being play
834 // (TODO: a callback would be cleaner here)
835 clearInterval(this.clockUpdate);
836 this.clockUpdate = null;
837 const freezeDuration = ["all", "highlight"].includes(V.ShowMoves)
838 // 250 = length of animation, 500 = delay between sub-moves
839 ? 250 + 750 *
840 (Array.isArray(movePlus.move) ? movePlus.move.length - 1 : 0)
841 // Incomplete information: no move animation
842 : 0;
843 setTimeout(
844 () => {
845 this.game.clocks[moveColIdx] = movePlus.clock;
846 this.processMove(
847 movePlus.move,
848 { receiveMyMove: receiveMyMove }
849 );
850 },
851 freezeDuration
852 );
633959bf 853 }
a6088c90 854 break;
71468011 855 }
f9c36b2d
BA
856 case "gotmove": {
857 this.opponentGotMove = true;
3f22c2c3 858 // Now his clock starts running on my side:
e01e086d 859 const oppIdx = ['w','b'].indexOf(this.vr.turn);
7ebc0408
BA
860 // NOTE: next line to avoid multi-resetClocks when several tabs
861 // on same game, resulting in a faster countdown.
862 if (!!this.clockUpdate) clearInterval(this.clockUpdate);
e01e086d 863 this.re_setClocks();
f9c36b2d
BA
864 break;
865 }
93d1d7a7 866 case "resign":
059228c9
BA
867 const score = (data.data == "b" ? "1-0" : "0-1");
868 const side = (data.data == "w" ? "White" : "Black");
8477e53d 869 this.gameOver(score, side + " surrender");
93d1d7a7 870 break;
93d1d7a7 871 case "abort":
8477e53d 872 this.gameOver("?", "Stop");
93d1d7a7 873 break;
2cc10cdb 874 case "draw":
71468011 875 this.gameOver("1/2", data.data);
2cc10cdb
BA
876 break;
877 case "drawoffer":
41c80bb6
BA
878 // NOTE: observers don't know who offered draw
879 this.drawOffer = "received";
1ef65040 880 if (!!this.game.mycolor && this.game.type == "live") {
f54f4c26
BA
881 GameStorage.update(
882 this.gameRef,
883 { drawOffer: V.GetOppCol(this.game.mycolor) }
884 );
885 }
6d9f4315 886 break;
c292ebb2
BA
887 case "rematchoffer":
888 // NOTE: observers don't know who offered rematch
889 this.rematchOffer = data.data ? "received" : "";
1ef65040 890 if (!!this.game.mycolor && this.game.type == "live") {
f54f4c26
BA
891 GameStorage.update(
892 this.gameRef,
9eccb8aa 893 { rematchOffer: data.data ? V.GetOppCol(this.game.mycolor) : "" }
f54f4c26
BA
894 );
895 }
c292ebb2
BA
896 break;
897 case "newgame": {
898 // A game started, redirect if I'm playing in
899 const gameInfo = data.data;
584f81b9 900 const gameType = this.getGameType(gameInfo);
c292ebb2 901 if (
584f81b9
BA
902 gameType == "live" &&
903 gameInfo.players.some(p => p.sid == this.st.user.sid)
904 ) {
905 this.addAndGotoLiveGame(gameInfo);
4a209313
BA
906 }
907 else if (
584f81b9 908 gameType == "corr" &&
751d7ca4 909 this.st.user.id > 0 &&
0234201f 910 gameInfo.players.some(p => p.id == this.st.user.id)
c292ebb2
BA
911 ) {
912 this.$router.push("/game/" + gameInfo.id);
4a209313
BA
913 }
914 else {
f54f4c26 915 this.rematchId = gameInfo.id;
5b18515f
BA
916 document.getElementById("modalRules").checked = false;
917 document.getElementById("modalScore").checked = false;
3ca0ef9e 918 document.getElementById("modalRematch").checked = true;
c292ebb2
BA
919 }
920 break;
921 }
1a021529
BA
922 case "newchat": {
923 let chat = data.data;
924 this.$refs["chatcomp"].newChat(chat);
925 if (this.game.type == "live") {
926 chat.added = Date.now();
1ef65040
BA
927 if (!!this.game.mycolor)
928 GameStorage.update(this.gameRef, { chat: chat });
1a021529 929 }
71468011 930 if (!document.getElementById("modalChat").checked)
2f258c37 931 document.getElementById("chatBtn").classList.add("somethingnew");
a6088c90 932 break;
1a021529 933 }
a6088c90 934 }
cdb34c93 935 },
5aa14a21 936 updateCorrGame: function(obj, callback) {
aae89b49
BA
937 ajax(
938 "/games",
939 "PUT",
940 {
e57c4de4 941 data: {
f54f4c26 942 gid: this.gameRef,
e57c4de4
BA
943 newObj: obj
944 },
945 success: () => {
946 if (!!callback) callback();
947 }
aae89b49
BA
948 }
949 );
950 },
584f81b9 951 sendLastate: function(target) {
3f22c2c3
BA
952 // Send our "last state" informations to opponent
953 const L = this.game.moves.length;
954 const myIdx = ["w", "b"].indexOf(this.game.mycolor);
955 const myLastate = {
956 lastMove:
957 (L > 0 && this.vr.turn != this.game.mycolor)
958 ? this.game.moves[L - 1]
959 : undefined,
960 clock: this.game.clocks[myIdx],
961 // Since we played a move (or abort or resign),
962 // only drawOffer=="sent" is possible
9eccb8aa
BA
963 drawSent: this.drawOffer == "sent" ? true : undefined,
964 rematchSent: this.rematchOffer == "sent" ? true : undefined,
3f22c2c3
BA
965 score: this.game.score != "*" ? this.game.score : undefined,
966 scoreMsg: this.game.score != "*" ? this.game.scoreMsg : undefined,
967 movesCount: L
968 };
969 this.send("lastate", { data: myLastate, target: target });
584f81b9 970 },
760adbce
BA
971 // lastate was received, but maybe game wasn't ready yet:
972 processLastate: function() {
973 const data = this.lastate;
974 this.lastate = undefined; //security...
3f22c2c3 975 if (!!data.score) {
9eccb8aa
BA
976 const oppCol = V.GetOppCol(this.game.mycolor);
977 if (!!data.rematchSent) {
978 if (this.game.rematchOffer != oppCol) {
979 // Opponent sended rematch offer while we were offline:
980 this.rematchOffer = "received";
981 GameStorage.update(
982 this.gameRef,
983 { rematchOffer: oppCol }
984 );
985 }
986 }
987 else {
988 if (this.game.rematchOffer == oppCol) {
989 // Opponent cancelled rematch offer while we were offline:
990 this.rematchOffer = "";
991 GameStorage.update(
992 this.gameRef,
993 { rematchOffer: "" }
994 );
995 }
996 }
997 }
998 else {
999 const L = this.game.moves.length;
1000 const oppIdx = 1 - ["w", "b"].indexOf(this.game.mycolor);
1001 this.game.clocks[oppIdx] = data.clock;
1002 if (data.movesCount > L) {
1003 // Just got last move from him
1004 this.$refs["basegame"].play(data.lastMove, "received");
1005 this.processMove(data.lastMove);
4a209313
BA
1006 }
1007 else {
9eccb8aa
BA
1008 if (!!this.clockUpdate) clearInterval(this.clockUpdate);
1009 this.re_setClocks();
1010 }
1011 if (!!data.drawSent) this.drawOffer = "received";
1012 if (!!data.score) {
1013 this.drawOffer = "";
1014 if (this.game.score == "*")
1015 this.gameOver(data.score, data.scoreMsg);
1016 }
760adbce
BA
1017 }
1018 },
dcd68c41 1019 clickDraw: function() {
1ef65040 1020 if (!this.game.mycolor || this.game.type == "import") return;
6808d7a1
BA
1021 if (["received", "threerep"].includes(this.drawOffer)) {
1022 if (!confirm(this.st.tr["Accept draw?"])) return;
1023 const message =
1024 this.drawOffer == "received"
1025 ? "Mutual agreement"
1026 : "Three repetitions";
1027 this.send("draw", { data: message });
77c50966 1028 this.gameOver("1/2", message);
4a209313
BA
1029 }
1030 else if (this.drawOffer == "") {
e71161fb 1031 // No effect if drawOffer == "sent"
9ee2826a 1032 if (this.game.mycolor != this.vr.turn) {
6808d7a1 1033 alert(this.st.tr["Draw offer only in your turn"]);
6fba6e0c 1034 return;
6808d7a1
BA
1035 }
1036 if (!confirm(this.st.tr["Offer draw?"])) return;
760adbce 1037 this.drawOffer = "sent";
71468011 1038 this.send("drawoffer");
aae89b49
BA
1039 if (this.game.type == "live") {
1040 GameStorage.update(
f54f4c26 1041 this.gameRef,
aae89b49
BA
1042 { drawOffer: this.game.mycolor }
1043 );
4a209313
BA
1044 }
1045 else this.updateCorrGame({ drawOffer: this.game.mycolor });
a6088c90
BA
1046 }
1047 },
584f81b9
BA
1048 addAndGotoLiveGame: function(gameInfo, callback) {
1049 const game = Object.assign(
1050 {},
1051 gameInfo,
1052 {
1053 // (other) Game infos: constant
1054 fenStart: gameInfo.fen,
584f81b9
BA
1055 created: Date.now(),
1056 // Game state (including FEN): will be updated
1057 moves: [],
1058 clocks: [-1, -1], //-1 = unstarted
978fa11c 1059 chats: [],
584f81b9
BA
1060 score: "*"
1061 }
1062 );
1063 GameStorage.add(game, (err) => {
1064 // No error expected.
1065 if (!err) {
1066 if (this.st.settings.sound)
1067 new Audio("/sounds/newgame.flac").play().catch(() => {});
585d0955 1068 if (!!callback) callback();
584f81b9
BA
1069 this.$router.push("/game/" + gameInfo.id);
1070 }
1071 });
1072 },
c292ebb2 1073 clickRematch: function() {
1ef65040 1074 if (!this.game.mycolor || this.game.type == "import") return;
c292ebb2
BA
1075 if (this.rematchOffer == "received") {
1076 // Start a new game!
1077 let gameInfo = {
1078 id: getRandString(), //ignored if corr
eb2d61de 1079 fen: V.GenRandInitFen(this.game.options),
902378e6 1080 options: JSON.stringify(this.game.options),
b4f2488a 1081 players: [this.game.players[1], this.game.players[0]],
c292ebb2
BA
1082 vid: this.game.vid,
1083 cadence: this.game.cadence
1084 };
584f81b9 1085 const notifyNewGame = () => {
9f9e9a05 1086 this.send("rnewgame", { data: gameInfo });
f14572c4
BA
1087 // To main Hall if corr game:
1088 if (this.game.type == "corr")
7ebc0408 1089 this.send("newgame", { data: gameInfo, page: "/" });
cafe0166
BA
1090 // Also to MyGames page:
1091 this.notifyMyGames("newgame", gameInfo);
584f81b9 1092 };
af4a532a 1093 if (this.game.type == "live") {
9f9e9a05
BA
1094 GameStorage.update(
1095 this.gameRef,
1096 { rematchOffer: "" }
1097 );
af4a532a
BA
1098 // Increment game stats counter in DB
1099 ajax(
1100 "/gamestat",
1101 "POST",
1102 { data: { vid: gameInfo.vid } }
1103 );
584f81b9 1104 this.addAndGotoLiveGame(gameInfo, notifyNewGame);
af4a532a 1105 }
c292ebb2
BA
1106 else {
1107 // corr game
9f9e9a05 1108 this.updateCorrGame({ rematchOffer: 'n' });
c292ebb2
BA
1109 ajax(
1110 "/games",
1111 "POST",
1112 {
902378e6 1113 data: { gameInfo: gameInfo },
c292ebb2 1114 success: (response) => {
9f9e9a05 1115 gameInfo.id = response.id;
584f81b9 1116 notifyNewGame();
9f9e9a05 1117 this.$router.push("/game/" + response.id);
c292ebb2
BA
1118 }
1119 }
1120 );
1121 }
4a209313
BA
1122 }
1123 else if (this.rematchOffer == "") {
c292ebb2
BA
1124 this.rematchOffer = "sent";
1125 this.send("rematchoffer", { data: true });
1126 if (this.game.type == "live") {
1127 GameStorage.update(
f54f4c26 1128 this.gameRef,
c292ebb2
BA
1129 { rematchOffer: this.game.mycolor }
1130 );
4a209313
BA
1131 }
1132 else this.updateCorrGame({ rematchOffer: this.game.mycolor });
1133 }
1134 else if (this.rematchOffer == "sent") {
c292ebb2
BA
1135 // Toggle rematch offer (on --> off)
1136 this.rematchOffer = "";
1137 this.send("rematchoffer", { data: false });
1138 if (this.game.type == "live") {
1139 GameStorage.update(
f54f4c26 1140 this.gameRef,
c292ebb2
BA
1141 { rematchOffer: '' }
1142 );
4a209313
BA
1143 }
1144 else this.updateCorrGame({ rematchOffer: 'n' });
c292ebb2
BA
1145 }
1146 },
7f3484bd 1147 abortGame: function() {
2c5d7b20
BA
1148 if (!this.game.mycolor || !confirm(this.st.tr["Terminate game?"]))
1149 return;
8477e53d 1150 this.gameOver("?", "Stop");
71468011 1151 this.send("abort");
a6088c90 1152 },
6808d7a1 1153 resign: function() {
77c50966 1154 if (!this.game.mycolor || !confirm(this.st.tr["Resign the game?"]))
a6088c90 1155 return;
6808d7a1 1156 this.send("resign", { data: this.game.mycolor });
059228c9
BA
1157 const score = (this.game.mycolor == "w" ? "0-1" : "1-0");
1158 const side = (this.game.mycolor == "w" ? "White" : "Black");
8477e53d 1159 this.gameOver(score, side + " surrender");
a6088c90 1160 },
760adbce 1161 loadGame: function(game, callback) {
1ef65040 1162 const gtype = game.type || this.getGameType(game);
32f6285e
BA
1163 const tc = extractTime(game.cadence);
1164 const myIdx = game.players.findIndex(p => {
751d7ca4
BA
1165 return (
1166 p.sid == this.st.user.sid ||
1167 (!!p.name && p.id == this.st.user.id)
1168 );
32f6285e 1169 });
3d65195b
BA
1170 // Sometimes the name isn't stored yet (TODO: why?)
1171 if (
1172 myIdx >= 0 &&
1173 gtype == "live" &&
1174 !game.players[myIdx].name &&
1175 !!this.st.user.name
1176 ) {
1177 game.players[myIdx].name = this.st.user.name;
1178 GameStorage.update(
1179 game.id,
1180 { playerName: { idx: myIdx, name: this.st.user.name } }
1181 );
1182 }
2c5d7b20
BA
1183 // "mycolor" is undefined for observers
1184 const mycolor = [undefined, "w", "b"][myIdx + 1];
32f6285e 1185 if (gtype == "corr") {
1ef65040
BA
1186 if (mycolor == 'w') game.chatRead = game.chatReadWhite;
1187 else if (mycolor == 'b') game.chatRead = game.chatReadBlack;
3f22c2c3 1188 // NOTE: clocks in seconds
32f6285e
BA
1189 game.moves.sort((m1, m2) => m1.idx - m2.idx); //in case of
1190 game.clocks = [tc.mainTime, tc.mainTime];
1191 const L = game.moves.length;
1192 if (game.score == "*") {
3f22c2c3
BA
1193 // Adjust clocks
1194 if (L >= 2) {
1195 game.clocks[L % 2] -=
1196 (Date.now() - game.moves[L-1].played) / 1000;
1197 }
66d03f23 1198 }
32f6285e
BA
1199 // Now that we used idx and played, re-format moves as for live games
1200 game.moves = game.moves.map(m => m.squares);
1201 }
1ef65040 1202 else if (gtype == "live") {
3f22c2c3
BA
1203 if (game.clocks[0] < 0) {
1204 // Game is unstarted. clock is ignored until move 2
1205 game.clocks = [tc.mainTime, tc.mainTime];
1206 if (myIdx >= 0) {
1207 // I play in this live game
3d65195b
BA
1208 GameStorage.update(
1209 game.id,
1210 { clocks: game.clocks }
1211 );
3f22c2c3 1212 }
77c50966 1213 }
4a209313
BA
1214 else if (!!game.initime)
1215 // It's my turn: clocks not updated yet
1216 game.clocks[myIdx] -= (Date.now() - game.initime) / 1000;
32f6285e 1217 }
1ef65040
BA
1218 else
1219 // gtype == "import"
1220 game.clocks = [tc.mainTime, tc.mainTime];
1221 // Live games before 26/03/2020 don't have chat history:
1222 if (!game.chats) game.chats = []; //TODO: remove line
1223 // Sort chat messages from newest to oldest
1224 game.chats.sort((c1, c2) => c2.added - c1.added);
1225 if (
1226 myIdx >= 0 &&
1227 game.chats.length > 0 &&
1228 (!game.chatRead || game.chatRead < game.chats[0].added)
1229 ) {
1230 // A chat message arrived since my last reading:
1231 document.getElementById("chatBtn").classList.add("somethingnew");
1232 }
32f6285e
BA
1233 // TODO: merge next 2 "if" conditions
1234 if (!!game.drawOffer) {
1235 if (game.drawOffer == "t")
1236 // Three repetitions
1237 this.drawOffer = "threerep";
1238 else {
1239 // Draw offered by any of the players:
1240 if (myIdx < 0) this.drawOffer = "received";
c292ebb2
BA
1241 else {
1242 // I play in this game:
1243 if (
32f6285e
BA
1244 (game.drawOffer == "w" && myIdx == 0) ||
1245 (game.drawOffer == "b" && myIdx == 1)
c292ebb2 1246 )
32f6285e
BA
1247 this.drawOffer = "sent";
1248 else this.drawOffer = "received";
c292ebb2
BA
1249 }
1250 }
32f6285e
BA
1251 }
1252 if (!!game.rematchOffer) {
1253 if (myIdx < 0) this.rematchOffer = "received";
1254 else {
1255 // I play in this game:
1256 if (
1257 (game.rematchOffer == "w" && myIdx == 0) ||
1258 (game.rematchOffer == "b" && myIdx == 1)
9eccb8aa 1259 ) {
32f6285e 1260 this.rematchOffer = "sent";
9eccb8aa 1261 }
32f6285e 1262 else this.rematchOffer = "received";
5aa14a21 1263 }
32f6285e
BA
1264 }
1265 this.repeat = {}; //reset: scan past moves' FEN:
1266 let repIdx = 0;
1ef65040 1267 this.vr = new V(game.fenStart);
32f6285e
BA
1268 let curTurn = "n";
1269 game.moves.forEach(m => {
1ef65040
BA
1270 playMove(m, this.vr);
1271 const fenIdx = this.vr.getFenForRepeat();
32f6285e
BA
1272 this.repeat[fenIdx] = this.repeat[fenIdx]
1273 ? this.repeat[fenIdx] + 1
1274 : 1;
1275 });
1ef65040
BA
1276 // Imported games don't have current FEN
1277 if (!game.fen) game.fen = this.vr.getFen();
32f6285e
BA
1278 if (this.repeat[repIdx] >= 3) this.drawOffer = "threerep";
1279 this.game = Object.assign(
1280 // NOTE: assign mycolor here, since BaseGame could also be VS computer
1281 {
1282 type: gtype,
1283 increment: tc.increment,
1284 mycolor: mycolor,
1285 // opponent sid not strictly required (or available), but easier
1286 // at least oppsid or oppid is available anyway:
1287 oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid,
1288 oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].id
1289 },
1290 game
1291 );
1292 this.$refs["basegame"].re_setVariables(this.game);
ad030c7d
BA
1293 // Initial loading:
1294 this.gotMoveIdx = game.moves.length - 1;
1295 // If we arrive here after 'nextGame' action, the board might be hidden
1296 let boardDiv = document.querySelector(".game");
1297 if (!!boardDiv && boardDiv.style.visibility == "hidden")
1298 boardDiv.style.visibility = "visible";
32f6285e
BA
1299 this.re_setClocks();
1300 this.$nextTick(() => {
1301 this.game.rendered = true;
1302 // Did lastate arrive before game was rendered?
b9ce3d0f 1303 if (!!this.lastate) this.processLastate();
32f6285e
BA
1304 });
1305 if (this.lastateAsked) {
1306 this.lastateAsked = false;
1307 this.sendLastate(game.oppsid);
1308 }
32f6285e
BA
1309 if (!!callback) callback();
1310 },
f54f4c26 1311 loadVariantThenGame: async function(game, callback) {
eaa5ad3e
BA
1312 const afterSetVname = async () => {
1313 await import("@/variants/" + game.vname + ".js")
1314 .then((vModule) => {
1315 window.V = vModule[game.vname + "Rules"];
1316 this.loadGame(game, callback);
1317 });
1318 this.rulesContent =
1319 afterRawLoad(
1320 require(
1321 "raw-loader!@/translations/rules/" +
1322 game.vname + "/" + this.st.lang + ".pug"
1323 ).default
1324 ).replace(/(fen:)([^:]*):/g, replaceByDiag);
1325 };
1326 let variant = undefined;
1327 const trySetVname = setInterval(
1328 () => {
1329 // this.st.variants might be uninitialized (variant == null)
7c4601d0
BA
1330 variant = this.st.variants.find(v => {
1331 return v.id == game.vid || v.name == game.vname
1332 });
eaa5ad3e
BA
1333 if (!!variant) {
1334 clearInterval(trySetVname);
1335 game.vname = variant.name;
1336 game.vdisp = variant.display;
1337 afterSetVname();
1338 }
1339 }, 500
1340 );
f54f4c26
BA
1341 },
1342 // 3 cases for loading a game:
1343 // - from indexedDB (running or completed live game I play)
1344 // - from server (one correspondance game I play[ed] or not)
1345 // - from remote peer (one live game I don't play, finished or not)
1346 fetchGame: function(callback) {
e50a8025
BA
1347 if (
1348 Number.isInteger(this.gameRef) ||
1349 !isNaN(parseInt(this.gameRef, 10))
1350 ) {
f54f4c26
BA
1351 // corr games identifiers are integers
1352 ajax(
1353 "/games",
1354 "GET",
1355 {
1356 data: { gid: this.gameRef },
1357 success: (res) => {
1358 res.game.moves.forEach(m => {
1359 m.squares = JSON.parse(m.squares);
1360 });
1361 callback(res.game);
e57c4de4 1362 }
f54f4c26
BA
1363 }
1364 );
5f918a27 1365 }
1ef65040 1366 else if (!!this.gameRef.match(/^i/))
5f918a27
BA
1367 // Game import (maybe remote)
1368 ImportgameStorage.get(this.gameRef, callback);
1369 else
1370 // Local live game (or remote)
f54f4c26 1371 GameStorage.get(this.gameRef, callback);
a6088c90 1372 },
9ef63965 1373 re_setClocks: function() {
3f22c2c3 1374 this.virtualClocks = this.game.clocks.map(s => ppt(s).split(':'));
dcff8e82 1375 if (this.game.moves.length < 2 || this.game.score != "*") {
9ef63965 1376 // 1st move not completed yet, or game over: freeze time
9ef63965
BA
1377 return;
1378 }
1379 const currentTurn = this.vr.turn;
8477e53d 1380 const currentMovesCount = this.game.moves.length;
6808d7a1 1381 const colorIdx = ["w", "b"].indexOf(currentTurn);
e01e086d
BA
1382 this.clockUpdate = setInterval(
1383 () => {
1384 if (
3f22c2c3 1385 this.game.clocks[colorIdx] < 0 ||
e01e086d
BA
1386 this.game.moves.length > currentMovesCount ||
1387 this.game.score != "*"
1388 ) {
1389 clearInterval(this.clockUpdate);
7ebc0408 1390 this.clockUpdate = null;
3f22c2c3 1391 if (this.game.clocks[colorIdx] < 0)
e01e086d
BA
1392 this.gameOver(
1393 currentTurn == "w" ? "0-1" : "1-0",
1394 "Time"
1395 );
4a209313
BA
1396 }
1397 else {
e01e086d
BA
1398 this.$set(
1399 this.virtualClocks,
1400 colorIdx,
3f22c2c3 1401 ppt(Math.max(0, --this.game.clocks[colorIdx])).split(':')
6808d7a1 1402 );
3f22c2c3 1403 }
e01e086d
BA
1404 },
1405 1000
1406 );
9ef63965 1407 },
57eb158f 1408 // Update variables and storage after a move:
e71161fb 1409 processMove: function(move, data) {
1ef65040
BA
1410 if (this.game.type == "import")
1411 // Shouldn't receive any messages in this mode:
1412 return;
e5c1d0fb 1413 if (!data) data = {};
e71161fb 1414 const moveCol = this.vr.turn;
8f16069a
BA
1415 const colorIdx = ["w", "b"].indexOf(moveCol);
1416 const nextIdx = 1 - colorIdx;
e71161fb 1417 const doProcessMove = () => {
dcff8e82 1418 const origMovescount = this.game.moves.length;
3f22c2c3
BA
1419 // The move is (about to be) played: stop clock
1420 clearInterval(this.clockUpdate);
7ebc0408 1421 this.clockUpdate = null;
f9c36b2d 1422 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
e71161fb
BA
1423 if (this.drawOffer == "received")
1424 // I refuse draw
1425 this.drawOffer = "";
dcff8e82 1426 if (this.game.type == "live" && origMovescount >= 2) {
3f22c2c3
BA
1427 this.game.clocks[colorIdx] += this.game.increment;
1428 // For a correct display in casqe of disconnected opponent:
1429 this.$set(
1430 this.virtualClocks,
1431 colorIdx,
1432 ppt(this.game.clocks[colorIdx]).split(':')
1433 );
1434 GameStorage.update(this.gameRef, {
1435 // It's not my turn anymore:
1436 initime: null
1437 });
e71161fb 1438 }
dce792f6 1439 }
dcff8e82 1440 // Update current game object:
e71161fb 1441 playMove(move, this.vr);
f54f4c26
BA
1442 if (!data.score)
1443 // Received move, score is computed in BaseGame, but maybe not yet.
1444 // ==> Compute it here, although this is redundant (TODO)
1445 data.score = this.vr.getCurrentScore();
1446 if (data.score != "*") this.gameOver(data.score);
dcff8e82 1447 this.game.moves.push(move);
e71161fb 1448 this.game.fen = this.vr.getFen();
3f22c2c3 1449 if (this.game.type == "corr") {
8be8238c 1450 // In corr games, just reset clock to mainTime:
e01e086d
BA
1451 this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime;
1452 }
f0a812b7
BA
1453 if (!V.IgnoreRepetition) {
1454 // If repetition detected, consider that a draw offer was received:
1455 const fenObj = this.vr.getFenForRepeat();
1456 this.repeat[fenObj] =
1457 !!this.repeat[fenObj]
1458 ? this.repeat[fenObj] + 1
1459 : 1;
1460 if (this.repeat[fenObj] >= 3) {
809ab1a8 1461 if (this.vr.loseOnRepetition())
f0a812b7
BA
1462 this.gameOver(moveCol == "w" ? "0-1" : "1-0", "Repetition");
1463 else this.drawOffer = "threerep";
1464 }
1465 else if (this.drawOffer == "threerep") this.drawOffer = "";
9a1e3abe 1466 }
dcff8e82
BA
1467 if (!!this.game.mycolor && !data.receiveMyMove) {
1468 // NOTE: 'var' to see that variable outside this block
1469 var filtered_move = getFilteredMove(move);
1470 }
cafe0166
BA
1471 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1472 // Notify turn on MyGames page:
1473 this.notifyMyGames(
1474 "turn",
1475 {
f54f4c26 1476 gid: this.gameRef,
cafe0166
BA
1477 turn: this.vr.turn
1478 }
1479 );
1480 }
aae89b49
BA
1481 // Since corr games are stored at only one location, update should be
1482 // done only by one player for each move:
3f22c2c3
BA
1483 if (
1484 this.game.type == "live" &&
1485 !!this.game.mycolor &&
1486 moveCol != this.game.mycolor &&
1487 this.game.moves.length >= 2
1488 ) {
1489 // Receive a move: update initime
1490 this.game.initime = Date.now();
1491 GameStorage.update(this.gameRef, {
1492 // It's my turn now!
1493 initime: this.game.initime
1494 });
1495 }
e71161fb 1496 if (
f9c36b2d
BA
1497 !!this.game.mycolor &&
1498 !data.receiveMyMove &&
e71161fb
BA
1499 (this.game.type == "live" || moveCol == this.game.mycolor)
1500 ) {
1501 let drawCode = "";
1502 switch (this.drawOffer) {
1503 case "threerep":
1504 drawCode = "t";
1505 break;
1506 case "sent":
1507 drawCode = this.game.mycolor;
1508 break;
1509 case "received":
1510 drawCode = V.GetOppCol(this.game.mycolor);
1511 break;
1512 }
1513 if (this.game.type == "corr") {
aae89b49
BA
1514 // corr: only move, fen and score
1515 this.updateCorrGame({
e71161fb
BA
1516 fen: this.game.fen,
1517 move: {
1518 squares: filtered_move,
dcff8e82 1519 idx: origMovescount
e71161fb
BA
1520 },
1521 // Code "n" for "None" to force reset (otherwise it's ignored)
1522 drawOffer: drawCode || "n"
1523 });
1524 }
57eb158f
BA
1525 else {
1526 const updateStorage = () => {
f54f4c26 1527 GameStorage.update(this.gameRef, {
57eb158f
BA
1528 fen: this.game.fen,
1529 move: filtered_move,
1530 moveIdx: origMovescount,
1531 clocks: this.game.clocks,
57eb158f
BA
1532 drawOffer: drawCode
1533 });
1534 };
1535 // The active tab can update storage immediately
f5768809 1536 if (this.focus) updateStorage();
57eb158f
BA
1537 // Small random delay otherwise
1538 else setTimeout(updateStorage, 500 + 1000 * Math.random());
e71161fb 1539 }
e69f159d 1540 }
dcff8e82
BA
1541 // Send move ("newmove" event) to people in the room (if our turn)
1542 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
e01e086d 1543 let sendMove = {
dcff8e82
BA
1544 move: filtered_move,
1545 index: origMovescount,
2c5d7b20
BA
1546 // color is required to check if this is my move
1547 // (if several tabs opened)
dcff8e82 1548 color: moveCol,
dcff8e82
BA
1549 cancelDrawOffer: this.drawOffer == ""
1550 };
e01e086d
BA
1551 if (this.game.type == "live")
1552 sendMove["clock"] = this.game.clocks[colorIdx];
8f16069a 1553 // (Live) Clocks will re-start when the opponent pingback arrive
dcff8e82
BA
1554 this.opponentGotMove = false;
1555 this.send("newmove", {data: sendMove});
1556 // If the opponent doesn't reply gotmove soon enough, re-send move:
ad030c7d 1557 // Do this at most 2 times, because more would mean network issues,
e01e086d
BA
1558 // opponent would then be expected to disconnect/reconnect.
1559 let counter = 1;
1560 const currentUrl = document.location.href;
aae89b49 1561 this.retrySendmove = setInterval(
57eb158f 1562 () => {
e01e086d
BA
1563 if (
1564 counter >= 3 ||
1565 this.opponentGotMove ||
1566 document.location.href != currentUrl //page change
1567 ) {
aae89b49 1568 clearInterval(this.retrySendmove);
57eb158f
BA
1569 return;
1570 }
c292ebb2
BA
1571 const oppsid = this.getOppsid();
1572 if (!oppsid)
57eb158f 1573 // Opponent is disconnected: he'll ask last state
aae89b49 1574 clearInterval(this.retrySendmove);
e01e086d
BA
1575 else {
1576 this.send("newmove", { data: sendMove, target: oppsid });
1577 counter++;
1578 }
57eb158f 1579 },
e01e086d 1580 1500
57eb158f 1581 );
dcff8e82 1582 }
e01e086d
BA
1583 else
1584 // Not my move or I'm an observer: just start other player's clock
1585 this.re_setClocks();
e71161fb 1586 };
f9c36b2d
BA
1587 if (
1588 this.game.type == "corr" &&
1589 moveCol == this.game.mycolor &&
1590 !data.receiveMyMove
1591 ) {
a17ae317 1592 let boardDiv = document.querySelector(".game");
5aa14a21
BA
1593 const afterSetScore = () => {
1594 doProcessMove();
1595 if (this.st.settings.gotonext && this.nextIds.length > 0)
1596 this.showNextGame();
1597 else {
5aa14a21 1598 // The board might have been hidden:
5aa14a21
BA
1599 if (boardDiv.style.visibility == "hidden")
1600 boardDiv.style.visibility = "visible";
3f22c2c3 1601 if (data.score == "*") this.re_setClocks();
e71161fb 1602 }
5aa14a21 1603 };
f4221ff1
BA
1604 if (!V.CorrConfirm) {
1605 afterSetScore();
1606 return;
1607 }
a17ae317
BA
1608 let el = document.querySelector("#buttonsConfirm > .acceptBtn");
1609 // We may play several moves in a row: in case of, remove listener:
1610 let elClone = el.cloneNode(true);
1611 el.parentNode.replaceChild(elClone, el);
1612 elClone.addEventListener(
1613 "click",
1614 () => {
1615 document.getElementById("modalConfirm").checked = false;
1616 if (!!data.score && data.score != "*")
1617 // Set score first
1618 this.gameOver(data.score, null, afterSetScore);
1619 else afterSetScore();
1620 }
1621 );
1622 // PlayOnBoard is enough, and more appropriate for Synchrone Chess
12d38d0f
BA
1623 const arMove = (Array.isArray(move) ? move : [move]);
1624 for (let i = 0; i < arMove.length; i++)
1625 V.PlayOnBoard(this.vr.board, arMove[i]);
a17ae317 1626 const position = this.vr.getBaseFen();
12d38d0f
BA
1627 for (let i = arMove.length - 1; i >= 0; i--)
1628 V.UndoOnBoard(this.vr.board, arMove[i]);
5aa14a21 1629 if (["all","byrow"].includes(V.ShowMoves)) {
5aa14a21
BA
1630 this.curDiag = getDiagram({
1631 position: position,
81452d4d
BA
1632 orientation: V.CanFlip ? this.game.mycolor : "w",
1633 color: this.game.mycolor,
1634 score: "*"
5aa14a21 1635 });
f3fe29d8
BA
1636 document.querySelector("#confirmDiv > .card").style.width =
1637 boardDiv.offsetWidth + "px";
ad030c7d
BA
1638 }
1639 else {
5aa14a21 1640 // Incomplete information: just ask confirmation
a17ae317 1641 // Hide the board, because otherwise it could reveal infos
5aa14a21 1642 boardDiv.style.visibility = "hidden";
a17ae317 1643 this.moveNotation = getFullNotation(move);
5aa14a21 1644 }
a17ae317 1645 document.getElementById("modalConfirm").checked = true;
6d68309a 1646 }
aae89b49 1647 else {
5aa14a21 1648 // Normal situation
5aa14a21 1649 if (!!data.score && data.score != "*")
e01e086d
BA
1650 this.gameOver(data.score, null, doProcessMove);
1651 else doProcessMove();
aae89b49 1652 }
b4fb1612 1653 },
5b4de147 1654 cancelMove: function() {
a17ae317
BA
1655 let boardDiv = document.querySelector(".game");
1656 if (boardDiv.style.visibility == "hidden")
1657 boardDiv.style.visibility = "visible";
5b4de147
BA
1658 document.getElementById("modalConfirm").checked = false;
1659 this.$refs["basegame"].cancelLastMove();
1660 },
5aa14a21
BA
1661 // In corr games, callback to change page only after score is set:
1662 gameOver: function(score, scoreMsg, callback) {
430a2038 1663 this.game.score = score;
c11afcdf 1664 if (!scoreMsg) scoreMsg = getScoreMessage(score, V.ReverseColors);
a17ae317 1665 this.game.scoreMsg = scoreMsg;
5b18515f 1666 document.getElementById("modalRules").checked = false;
3ca0ef9e
BA
1667 // Display result in a un-missable way:
1668 document.getElementById("modalScore").checked = true;
5aa14a21 1669 this.$set(this.game, "scoreMsg", scoreMsg);
ab6f48ea 1670 const myIdx = this.game.players.findIndex(p => {
751d7ca4
BA
1671 return (
1672 p.sid == this.st.user.sid ||
1673 (!!p.name && p.id == this.st.user.id)
1674 );
ab6f48ea 1675 });
6808d7a1 1676 if (myIdx >= 0) {
8477e53d 1677 // OK, I play in this game
aae89b49 1678 const scoreObj = {
6808d7a1
BA
1679 score: score,
1680 scoreMsg: scoreMsg
aae89b49 1681 };
5aa14a21 1682 if (this.game.type == "live") {
f54f4c26 1683 GameStorage.update(this.gameRef, scoreObj);
f5768809
BA
1684 // Notify myself locally if I'm elsewhere:
1685 if (!this.focus) {
1686 notify(
1687 "Game over",
1688 { body: score + " : " + scoreMsg }
1689 );
1690 }
5aa14a21
BA
1691 if (!!callback) callback();
1692 }
1693 else this.updateCorrGame(scoreObj, callback);
2c5d7b20
BA
1694 // Notify the score to main Hall.
1695 // TODO: only one player (currently double send)
6808d7a1 1696 this.send("result", { gid: this.game.id, score: score });
cafe0166
BA
1697 // Also to MyGames page (TODO: doubled as well...)
1698 this.notifyMyGames(
1699 "score",
1700 {
f54f4c26 1701 gid: this.gameRef,
cafe0166
BA
1702 score: score
1703 }
1704 );
dcd68c41 1705 }
5aa14a21 1706 else if (!!callback) callback();
6808d7a1
BA
1707 }
1708 }
a6088c90
BA
1709};
1710</script>
7e1a1fe9 1711
41c80bb6 1712<style lang="sass" scoped>
3ca0ef9e 1713#scoreDiv > .card, #rematchDiv > .card
a06fc4ba 1714 padding: 10px 0
c292ebb2
BA
1715 max-width: 430px
1716
07052665
BA
1717#rulesDiv > .card
1718 padding: 5px 0
26d8a01a 1719 max-width: 50%
07052665 1720 max-height: 100%
26d8a01a
BA
1721 @media screen and (max-width: 1500px)
1722 max-width: 67%
07052665
BA
1723 @media screen and (max-width: 1024px)
1724 max-width: 85%
1725 @media screen and (max-width: 767px)
1726 max-width: 100%
1727
af34341d 1728p.score-section
a06fc4ba 1729 margin: 0
af34341d
BA
1730 font-size: 1.3em
1731 span.score
1732 font-weight: bold
3ca0ef9e 1733
72ccbd67 1734.connected
050ae3b5 1735 background-color: lightgreen
72ccbd67 1736
ed06d9e9
BA
1737#participants
1738 margin-left: 5px
1739
1740.anonymous
1741 color: grey
1742 font-style: italic
1743
ec905cbc
BA
1744#playersInfo > p
1745 margin: 0
1746
430a2038
BA
1747@media screen and (max-width: 767px)
1748 .game
1749 width: 100%
72ccbd67 1750
430a2038 1751#actions
cf94b843 1752 display: inline-block
1d6d7b1d 1753 margin: 0
feaf1bf7
BA
1754
1755button
1756 display: inline-block
1757 margin: 0
1758 display: inline-flex
1759 img
54ec15eb 1760 height: 22px
feaf1bf7
BA
1761 display: flex
1762 @media screen and (max-width: 767px)
1763 height: 18px
a1c48034 1764
07052665
BA
1765#aboveBoard
1766 text-align: center
050ae3b5 1767
80b38d46
BA
1768.user-bio
1769 display: inline
1770 font-size: 1.5rem
1771 @media screen and (max-width: 767px)
1772 font-size: 1.2rem
1773 padding: 0 3px
1774
2f258c37
BA
1775.variant-cadence
1776 padding-right: 10px
1777
1778.variant-name
8c5f5390 1779 font-weight: bold
77c50966 1780 padding-right: 10px
77c50966 1781
feaf1bf7
BA
1782span#nextGame
1783 background-color: #edda99
1784 cursor: pointer
1785 display: inline-block
1786 margin-right: 10px
1787
07052665
BA
1788span.separator
1789 display: inline-block
1790 margin: 0
1791 padding: 0
1792 width: 10px
1793
57eb158f 1794span.time
050ae3b5 1795 font-size: 2rem
847ba842
BA
1796 @media screen and (max-width: 767px)
1797 font-size: 1.5rem
050ae3b5 1798 display: inline-block
57eb158f
BA
1799 .time-left
1800 margin-left: 10px
1801 .time-right
1802 margin-left: 5px
1803 .time-separator
1804 margin-left: 5px
1805 position: relative
1806 top: -1px
1807
1808span.yourturn
1809 color: #831B1B
1810 .time-separator
1811 animation: blink-animation 2s steps(3, start) infinite
1812@keyframes blink-animation
1813 to
1814 visibility: hidden
050ae3b5
BA
1815
1816.split-names
1817 display: inline-block
1818 margin: 0 15px
1819
5b4de147 1820#chatWrap > .card
a1c48034 1821 padding-top: 20px
a154d45e 1822 max-width: 767px
5b4de147
BA
1823 border: none
1824
1825#confirmDiv > .card
1826 max-width: 767px
1827 max-height: 100%
cf94b843 1828
dcd68c41
BA
1829.draw-sent, .draw-sent:hover
1830 background-color: lightyellow
1831
1832.draw-received, .draw-received:hover
5b3d4006 1833 background-color: #73C6B6
dcd68c41
BA
1834
1835.draw-threerep, .draw-threerep:hover
659a9bd2 1836 background-color: #D2B4DE
2f258c37 1837
c292ebb2
BA
1838.rematch-sent, .rematch-sent:hover
1839 background-color: lightyellow
1840
1841.rematch-received, .rematch-received:hover
659a9bd2 1842 background-color: #48C9B0
c292ebb2 1843
2f258c37 1844.somethingnew
659a9bd2 1845 background-color: #D2B4DE
5b4de147
BA
1846
1847.diagram
1848 margin: 0 auto
5b4de147
BA
1849 width: 100%
1850
1851#buttonsConfirm
1852 margin: 0
1853 & > button > span
1854 width: 100%
1855 text-align: center
1856
1857button.acceptBtn
1858 background-color: lightgreen
1859button.refuseBtn
1860 background-color: red
07052665 1861
1c15969e
BA
1862a#variantNameInGame
1863 color: var(--card-fore-color)
07052665 1864 text-align: center
07052665 1865 font-weight: bold
1c15969e
BA
1866 font-size: calc(1rem * var(--heading-ratio))
1867 line-height: 1.2
1868 margin: calc(1.5 * var(--universal-margin))
07052665
BA
1869</style>
1870
1871<style lang="sass">
26d8a01a
BA
1872@import "@/styles/_rules.sass"
1873@import "@/styles/_board_squares_img.sass"
7e1a1fe9 1874</style>