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