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