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