Increment game stat counter also for rematch live games
[vchess.git] / client / src / components / BaseGame.vue
1 <template lang="pug">
2 div#baseGame
3 input#modalEog.modal(type="checkbox")
4 div#eogDiv(
5 role="dialog"
6 data-checkbox="modalEog"
7 )
8 .card.text-center
9 label.modal-close(for="modalEog")
10 h3.section {{ endgameMessage }}
11 #gameContainer
12 #boardContainer
13 Board(
14 ref="board"
15 :vr="vr"
16 :last-move="lastMove"
17 :analyze="mode=='analyze'"
18 :score="game.score"
19 :user-color="game.mycolor"
20 :orientation="orientation"
21 :vname="game.vname"
22 :incheck="incheck"
23 @play-move="play"
24 @click-square="clickSquare"
25 )
26 #turnIndicator(v-if="showTurn") {{ turn }}
27 #controls.button-group
28 button(@click="gotoBegin()")
29 img.inline(src="/images/icons/fast-forward_rev.svg")
30 button(@click="undo()")
31 img.inline(src="/images/icons/play_rev.svg")
32 button(v-if="canFlip" @click="flip()")
33 img.inline(src="/images/icons/flip.svg")
34 button(
35 @click="runAutoplay()"
36 :class="{'in-autoplay': autoplay}"
37 )
38 img.inline(src="/images/icons/autoplay.svg")
39 button(@click="play()")
40 img.inline(src="/images/icons/play.svg")
41 button(@click="gotoEnd()")
42 img.inline(src="/images/icons/fast-forward.svg")
43 p#fenAnalyze(v-show="showFen") {{ (!!vr ? vr.getFen() : "") }}
44 #movesList
45 MoveList(
46 :show="showMoves"
47 :canAnalyze="canAnalyze"
48 :canDownload="allowDownloadPGN"
49 :score="game.score"
50 :message="game.scoreMsg"
51 :firstNum="firstMoveNumber"
52 :moves="moves"
53 :cursor="cursor"
54 :vname="game.vname"
55 @download="download"
56 @showrules="showRules"
57 @analyze="toggleAnalyze"
58 @goto-move="gotoMove"
59 @redraw-board="redrawBoard"
60 )
61 .clearer
62 </template>
63
64 <script>
65 import Board from "@/components/Board.vue";
66 import MoveList from "@/components/MoveList.vue";
67 import params from "@/parameters";
68 import { store } from "@/store";
69 import { getSquareId } from "@/utils/squareId";
70 import { getDate } from "@/utils/datetime";
71 import { processModalClick } from "@/utils/modalClick";
72 import { getScoreMessage } from "@/utils/scoring";
73 import { getFullNotation } from "@/utils/notation";
74 import { undoMove } from "@/utils/playUndo";
75 export default {
76 name: "my-base-game",
77 components: {
78 Board,
79 MoveList
80 },
81 props: ["game"],
82 data: function() {
83 return {
84 st: store.state,
85 // NOTE: all following variables must be reset at the beginning of a game
86 vr: null, //VariantRules object, game state
87 endgameMessage: "",
88 orientation: "w",
89 mode: "",
90 gameMode: "",
91 score: "*", //'*' means 'unfinished'
92 moves: [],
93 cursor: -1, //index of the move just played
94 lastMove: null,
95 touchLastClick: "",
96 firstMoveNumber: 0, //for printing
97 incheck: [], //for Board
98 inMultimove: false,
99 autoplay: false,
100 inPlay: false,
101 stackToPlay: []
102 };
103 },
104 computed: {
105 turn: function() {
106 if (!this.vr) return "";
107 if (this.vr.showMoves != "all") {
108 return this.st.tr[
109 (this.vr.turn == 'w' ? "White" : "Black") + " to move"];
110 }
111 // Cannot flip (racing king or circular chess), or Monochrome
112 return (
113 this.vr.movesCount == 0 && this.game.mycolor == "w"
114 ? this.st.tr["It's your turn!"]
115 : ""
116 );
117 },
118 showFen: function() {
119 return (
120 this.mode == "analyze" &&
121 this.$router.currentRoute.path.indexOf("/analyse") === -1
122 );
123 },
124 // TODO: is it OK to pass "computed" as properties?
125 // Also, some are seemingly not recomputed when vr is initialized.
126 showMoves: function() {
127 return (
128 !!this.game.score && this.game.score != "*"
129 ? "all"
130 : (!!this.vr ? this.vr.showMoves : "none")
131 );
132 },
133 showTurn: function() {
134 return (
135 !!this.game.score && this.game.score == '*' &&
136 !!this.vr &&
137 (
138 this.vr.showMoves != "all" ||
139 !this.vr.canFlip ||
140 this.vr.showFirstTurn
141 )
142 );
143 },
144 canAnalyze: function() {
145 return (
146 (!this.game.mode || this.game.mode != "analyze") &&
147 !!this.vr && this.vr.canAnalyze
148 );
149 },
150 canFlip: function() {
151 return !!this.vr && this.vr.canFlip;
152 },
153 allowDownloadPGN: function() {
154 return (
155 (!!this.game.score && this.game.score != "*") ||
156 (!!this.vr && !this.vr.someHiddenMoves)
157 );
158 }
159 },
160 created: function() {
161 if (!!this.game.fenStart) this.re_setVariables();
162 },
163 mounted: function() {
164 if (!("ontouchstart" in window)) {
165 // Desktop browser:
166 const baseGameDiv = document.getElementById("baseGame");
167 baseGameDiv.tabIndex = 0;
168 baseGameDiv.addEventListener("click", this.focusBg);
169 baseGameDiv.addEventListener("keydown", this.handleKeys);
170 baseGameDiv.addEventListener("wheel", this.handleScroll);
171 }
172 document.getElementById("eogDiv")
173 .addEventListener("click", processModalClick);
174 },
175 beforeDestroy: function() {
176 // TODO: probably not required
177 this.autoplay = false;
178 },
179 methods: {
180 focusBg: function() {
181 document.getElementById("baseGame").focus();
182 },
183 handleKeys: function(e) {
184 if ([32, 37, 38, 39, 40].includes(e.keyCode)) e.preventDefault();
185 switch (e.keyCode) {
186 case 37:
187 this.undo();
188 break;
189 case 39:
190 this.play();
191 break;
192 case 38:
193 this.gotoBegin();
194 break;
195 case 40:
196 this.gotoEnd();
197 break;
198 case 32:
199 this.flip();
200 break;
201 }
202 },
203 handleScroll: function(e) {
204 e.preventDefault();
205 if (e.deltaY < 0) this.undo();
206 else if (e.deltaY > 0) this.play();
207 },
208 redrawBoard: function() {
209 this.$refs["board"].re_setDrawings();
210 },
211 showRules: function() {
212 // The button is here only on Game page:
213 document.getElementById("modalRules").checked = true;
214 },
215 re_setVariables: function(game) {
216 if (!game) game = this.game; //in case of...
217 this.endgameMessage = "";
218 // "w": default orientation for observed games
219 this.orientation = game.mycolor || "w";
220 this.mode = game.mode || game.type; //TODO: merge...
221 this.moves = JSON.parse(JSON.stringify(game.moves || []));
222 // Post-processing: decorate each move with notation and FEN
223 this.vr = new V(game.fenStart);
224 this.inMultimove = false; //in case of
225 if (!!this.$refs["board"])
226 // Also in case of:
227 this.$refs["board"].resetCurrentAttempt();
228 let analyseBtn = document.getElementById("analyzeBtn");
229 if (!!analyseBtn) analyseBtn.classList.remove("active");
230 const parsedFen = V.ParseFen(game.fenStart);
231 const firstMoveColor = parsedFen.turn;
232 this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2) + 1;
233 let L = this.moves.length;
234 this.moves.forEach((move,idx) => {
235 // Strategy working also for multi-moves:
236 if (!Array.isArray(move)) move = [move];
237 move.forEach(m => {
238 m.notation = this.vr.getNotation(m);
239 m.unambiguous = V.GetUnambiguousNotation(m);
240 this.vr.play(m);
241 });
242 const Lm = move.length;
243 move[Lm - 1].fen = this.vr.getFen();
244 if (idx < L - 1 && this.vr.getCheckSquares().length > 0)
245 move[Lm - 1].notation += "+";
246 });
247 this.incheck = this.vr.getCheckSquares();
248 this.score = this.vr.getCurrentScore();
249 if (L >= 1) {
250 const move =
251 !Array.isArray(this.moves[L - 1])
252 ? [this.moves[L - 1]]
253 : this.moves[L - 1];
254 const Lm = move.length;
255 if (["1-0", "0-1"].includes(this.score)) move[Lm - 1].notation += "#";
256 else if (this.incheck.length > 0) move[Lm - 1].notation += "+";
257 }
258 if (this.score != '*') {
259 // Show score on screen
260 const message = getScoreMessage(this.score);
261 this.showEndgameMsg(this.score + " . " + this.st.tr[message]);
262 }
263 if (firstMoveColor == "b") {
264 // 'start' & 'end' is required for Board component
265 this.moves.unshift({
266 notation: "...",
267 unambiguous: "...",
268 start: { x: -1, y: -1 },
269 end: { x: -1, y: -1 },
270 fen: game.fenStart
271 });
272 L++;
273 }
274 this.positionCursorTo(L - 1);
275 },
276 positionCursorTo: function(index) {
277 this.cursor = index;
278 // Note: last move in moves array might be a multi-move
279 if (index >= 0) this.lastMove = this.moves[index];
280 else this.lastMove = null;
281 },
282 toggleAnalyze: function() {
283 // Freeze while choices are shown (and autoplay has priority)
284 if (
285 this.inPlay ||
286 this.$refs["board"].choices.length > 0 ||
287 this.autoplay
288 ) {
289 return;
290 }
291 if (this.mode != "analyze") {
292 // Enter analyze mode:
293 this.gameMode = this.mode; //was not 'analyze'
294 this.mode = "analyze";
295 if (this.inMultimove) this.cancelCurrentMultimove();
296 this.gameCursor = this.cursor;
297 this.gameMoves = JSON.parse(JSON.stringify(this.moves));
298 document.getElementById("analyzeBtn").classList.add("active");
299 }
300 else {
301 // Exit analyze mode:
302 this.mode = this.gameMode;
303 this.cursor = this.gameCursor;
304 this.moves = this.gameMoves;
305 let fen = this.game.fenStart;
306 if (this.cursor >= 0) {
307 let mv = this.moves[this.cursor];
308 if (!Array.isArray(mv)) mv = [mv];
309 fen = mv[mv.length-1].fen;
310 }
311 this.vr = new V(fen);
312 this.inMultimove = false; //in case of
313 this.$refs["board"].resetCurrentAttempt(); //also in case of
314 this.incheck = this.vr.getCheckSquares();
315 if (this.cursor >= 0) this.lastMove = this.moves[this.cursor];
316 else this.lastMove = null;
317 document.getElementById("analyzeBtn").classList.remove("active");
318 }
319 },
320 download: function() {
321 const content = this.getPgn();
322 // Prepare and trigger download link
323 let downloadAnchor = document.getElementById("download");
324 downloadAnchor.setAttribute("download", "game.pgn");
325 downloadAnchor.href =
326 "data:text/plain;charset=utf-8," + encodeURIComponent(content);
327 downloadAnchor.click();
328 },
329 getPgn: function() {
330 let pgn = "";
331 pgn += '[Site "vchess.club"]\n';
332 pgn += '[Variant "' + this.game.vname + '"]\n';
333 const gdt = getDate(new Date(this.game.created || Date.now()));
334 pgn += '[Date "' + gdt + '"]\n';
335 pgn += '[White "' + this.game.players[0].name + '"]\n';
336 pgn += '[Black "' + this.game.players[1].name + '"]\n';
337 pgn += '[Fen "' + this.game.fenStart + '"]\n';
338 pgn += '[Result "' + this.game.score + '"]\n';
339 if (!!this.game.id)
340 pgn += '[Url "' + params.serverUrl + '/game/' + this.game.id + '"]\n';
341 if (!!this.game.cadence)
342 pgn += '[Cadence "' + this.game.cadence + '"]\n';
343 pgn += '\n';
344 for (let i = 0; i < this.moves.length; i += 2) {
345 if (i > 0) pgn += " ";
346 // Adjust dots notation for a better display:
347 let fullNotation = getFullNotation(this.moves[i]);
348 if (fullNotation == "...") fullNotation = "..";
349 pgn += (i / 2 + this.firstMoveNumber) + "." + fullNotation;
350 if (i+1 < this.moves.length)
351 pgn += " " + getFullNotation(this.moves[i+1]);
352 }
353 pgn += "\n\n";
354 for (let i = 0; i < this.moves.length; i += 2) {
355 const moveNumber = i / 2 + this.firstMoveNumber;
356 // Skip "dots move", useless for machine reading:
357 if (this.moves[i].notation != "...") {
358 pgn += moveNumber + ".w " +
359 getFullNotation(this.moves[i], "unambiguous") + "\n";
360 }
361 if (i+1 < this.moves.length) {
362 pgn += moveNumber + ".b " +
363 getFullNotation(this.moves[i+1], "unambiguous") + "\n";
364 }
365 }
366 return pgn;
367 },
368 showEndgameMsg: function(message) {
369 this.endgameMessage = message;
370 document.getElementById("modalEog").checked = true;
371 },
372 runAutoplay: function() {
373 if (this.autoplay) {
374 this.autoplay = false;
375 if (this.stackToPlay.length > 0)
376 // Move(s) arrived in-between
377 this.play(this.stackToPlay.pop(), "received");
378 }
379 else if (this.cursor < this.moves.length - 1) {
380 this.autoplay = true;
381 this.play(null, null, null, "autoplay");
382 }
383 },
384 // Animate an elementary move
385 animateMove: function(move, callback) {
386 let startSquare = document.getElementById(getSquareId(move.start));
387 if (!startSquare) return; //shouldn't happen but...
388 let endSquare = document.getElementById(getSquareId(move.end));
389 let rectStart = startSquare.getBoundingClientRect();
390 let rectEnd = endSquare.getBoundingClientRect();
391 let translation = {
392 x: rectEnd.x - rectStart.x,
393 y: rectEnd.y - rectStart.y
394 };
395 let movingPiece = document.querySelector(
396 "#" + getSquareId(move.start) + " > img.piece"
397 );
398 // For some unknown reasons Opera get "movingPiece == null" error
399 // TODO: is it calling 'animate()' twice ? One extra time ?
400 if (!movingPiece) return;
401 const squares = document.getElementsByClassName("board");
402 for (let i = 0; i < squares.length; i++) {
403 let square = squares.item(i);
404 if (square.id != getSquareId(move.start))
405 // HACK for animation:
406 // (with positive translate, image slides "under background")
407 square.style.zIndex = "-1";
408 }
409 movingPiece.style.transform =
410 "translate(" + translation.x + "px," + translation.y + "px)";
411 movingPiece.style.transitionDuration = "0.25s";
412 movingPiece.style.zIndex = "3000";
413 setTimeout(() => {
414 for (let i = 0; i < squares.length; i++)
415 squares.item(i).style.zIndex = "auto";
416 movingPiece.style = {}; //required e.g. for 0-0 with KR swap
417 callback();
418 }, 250);
419 },
420 // For Analyse mode:
421 emitFenIfAnalyze: function() {
422 if (this.game.mode == "analyze") {
423 let fen = this.game.fenStart;
424 if (!!this.lastMove) {
425 if (Array.isArray(this.lastMove)) {
426 const L = this.lastMove.length;
427 fen = this.lastMove[L-1].fen;
428 }
429 else fen = this.lastMove.fen;
430 }
431 this.$emit("fenchange", fen);
432 }
433 },
434 clickSquare: function(square) {
435 // Some variants make use of a single click at specific times:
436 const move_s = this.vr.doClick(square);
437 if (!!move_s) {
438 const playMove = () => {
439 if (!Array.isArray(move_s)) this.play(move_s);
440 else this.$refs["board"].choices = move_s;
441 }
442 if ("ontouchstart" in window) {
443 const squareId = "sq-" + square[0] + "-" + square[1];
444 const highlight = function(on, sq) {
445 let elt = document.getElementById(sq);
446 if (!!elt) {
447 if (on) elt.classList.add("touch-hover");
448 else elt.classList.remove("touch-hover");
449 }
450 }
451 // Touch screen (smartphone): require confirmation
452 const squareStr = square[0] + "_" + square[1]
453 if (this.touchLastClick == squareId) {
454 highlight(false, squareId);
455 playMove();
456 }
457 else {
458 highlight(true, squareId);
459 highlight(false, this.touchLastClick);
460 }
461 this.touchLastClick = squareId;
462 }
463 else playMove();
464 }
465 },
466 // "light": if gotoMove() or gotoEnd()
467 play: function(move, received, light, autoplay) {
468 // Freeze while choices are shown:
469 if (
470 !!this.$refs["board"].selectedPiece ||
471 this.$refs["board"].choices.length > 0
472 ) {
473 return;
474 }
475 const navigate = !move;
476 // Forbid navigation during autoplay:
477 if (navigate && this.autoplay && !autoplay) return;
478 // Forbid playing outside analyze mode, except if move is received.
479 // Sufficient condition because Board already knows which turn it is.
480 if (
481 this.mode != "analyze" &&
482 !navigate &&
483 !received &&
484 (this.game.score != "*" || this.cursor < this.moves.length - 1)
485 ) {
486 return;
487 }
488 if (!!received) {
489 if (this.autoplay || this.inPlay) {
490 // Received moves while autoplaying are stacked,
491 // and in observed games they could arrive too fast:
492 this.stackToPlay.unshift(move);
493 return;
494 }
495 if (this.mode == "analyze") this.toggleAnalyze();
496 if (this.cursor < this.moves.length - 1)
497 // To play a received move, cursor must be at the end of the game:
498 this.gotoEnd();
499 this.inPlay = true;
500 }
501 // The board may show some possible moves: (TODO: bad solution)
502 this.$refs["board"].resetCurrentAttempt();
503 const playSubmove = (smove) => {
504 smove.notation = this.vr.getNotation(smove);
505 smove.unambiguous = V.GetUnambiguousNotation(smove);
506 this.vr.play(smove);
507 if (this.inMultimove && !!this.lastMove) {
508 if (!Array.isArray(this.lastMove))
509 this.lastMove = [this.lastMove, smove];
510 else this.lastMove.push(smove);
511 }
512 if (!this.inMultimove) {
513 // First sub-move:
514 this.lastMove = smove;
515 // Condition is "!navigate" but we mean "!this.autoplay"
516 if (!navigate) {
517 if (this.cursor < this.moves.length - 1)
518 this.moves = this.moves.slice(0, this.cursor + 1);
519 this.moves.push(smove);
520 }
521 this.inMultimove = true; //potentially
522 this.cursor++;
523 }
524 else if (!navigate) {
525 // Already in the middle of a multi-move
526 const L = this.moves.length;
527 if (!Array.isArray(this.moves[L-1]))
528 this.$set(this.moves, L-1, [this.moves[L-1], smove]);
529 else this.moves[L-1].push(smove);
530 }
531 };
532 const playMove = () => {
533 const animate = (
534 ["all", "highlight"].includes(V.ShowMoves) &&
535 (this.autoplay || !!received)
536 );
537 if (!Array.isArray(move)) move = [move];
538 let moveIdx = 0;
539 let self = this;
540 const initurn = this.vr.turn;
541 (function executeMove() {
542 const smove = move[moveIdx++];
543 // NOTE: condition "smove.start.x >= 0" required for Dynamo,
544 // because second move may be empty. noHighlight condition
545 // is used at least for Chakart.
546 if (animate && smove.start.x >= 0 && !smove.end.noHighlight) {
547 self.animateMove(smove, () => {
548 playSubmove(smove);
549 if (moveIdx < move.length) setTimeout(executeMove, 500);
550 else afterMove(smove, initurn);
551 });
552 }
553 else {
554 playSubmove(smove);
555 if (moveIdx < move.length) executeMove();
556 else afterMove(smove, initurn);
557 }
558 })();
559 };
560 const computeScore = () => {
561 const score = this.vr.getCurrentScore();
562 if (!navigate) {
563 if (["1-0", "0-1"].includes(score)) {
564 if (Array.isArray(this.lastMove)) {
565 const L = this.lastMove.length;
566 this.lastMove[L - 1].notation += "#";
567 }
568 else this.lastMove.notation += "#";
569 }
570 }
571 if (score != "*" && ["analyze", "versus"].includes(this.mode)) {
572 const message = getScoreMessage(score, V.ReverseColors);
573 // Show score on screen
574 this.showEndgameMsg(score + " . " + this.st.tr[message]);
575 }
576 return score;
577 };
578 const afterMove = (smove, initurn) => {
579 if (this.vr.turn != initurn) {
580 // Turn has changed: move is complete
581 if (!smove.fen)
582 // NOTE: only FEN of last sub-move is required (=> setting it here)
583 smove.fen = this.vr.getFen();
584 this.emitFenIfAnalyze();
585 this.inMultimove = false;
586 this.incheck = this.vr.getCheckSquares();
587 if (this.incheck.length > 0) smove.notation += "+";
588 this.score = computeScore();
589 if (this.autoplay) {
590 if (this.cursor < this.moves.length - 1)
591 setTimeout(() => this.play(null, null, null, "autoplay"), 1000);
592 else {
593 this.autoplay = false;
594 if (this.stackToPlay.length > 0)
595 // Move(s) arrived in-between
596 this.play(this.stackToPlay.pop(), "received");
597 }
598 }
599 if (this.mode != "analyze" && !navigate) {
600 if (!received) {
601 // Post-processing (e.g. computer play).
602 const L = this.moves.length;
603 // NOTE: always emit the score, even in unfinished
604 this.$emit("newmove", this.moves[L-1], { score: this.score });
605 }
606 else {
607 this.inPlay = false;
608 if (this.stackToPlay.length > 0)
609 // Move(s) arrived in-between
610 this.play(this.stackToPlay.pop(), "received");
611 }
612 }
613 }
614 };
615 // NOTE: navigate and received are mutually exclusive
616 if (navigate) {
617 // The move to navigate to is necessarily full:
618 if (this.cursor == this.moves.length - 1) return; //no more moves
619 move = this.moves[this.cursor + 1];
620 if (!this.autoplay) {
621 // Just play the move:
622 if (!Array.isArray(move)) move = [move];
623 for (let i=0; i < move.length; i++) this.vr.play(move[i]);
624 if (!light) {
625 this.lastMove = move;
626 this.incheck = this.vr.getCheckSquares();
627 this.score = computeScore();
628 this.emitFenIfAnalyze();
629 }
630 this.cursor++;
631 return;
632 }
633 }
634 playMove();
635 },
636 cancelCurrentMultimove: function() {
637 const L = this.moves.length;
638 let move = this.moves[L-1];
639 if (!Array.isArray(move)) move = [move];
640 for (let i = move.length - 1; i >= 0; i--) this.vr.undo(move[i]);
641 this.moves.pop();
642 this.cursor--;
643 this.inMultimove = false;
644 },
645 cancelLastMove: function() {
646 // The last played move was canceled (corr game)
647 this.undo();
648 this.moves.pop();
649 },
650 // "light": if gotoMove() or gotoBegin()
651 undo: function(move, light) {
652 if (
653 this.autoplay ||
654 !!this.$refs["board"].selectedPiece ||
655 this.$refs["board"].choices.length > 0
656 ) {
657 return;
658 }
659 this.$refs["board"].resetCurrentAttempt();
660 if (this.inMultimove) {
661 this.cancelCurrentMultimove();
662 this.incheck = this.vr.getCheckSquares();
663 if (this.cursor >= 0) this.lastMove = this.moves[this.cursor];
664 else this.lastMove = null;
665 }
666 else {
667 if (!move) {
668 const minCursor =
669 this.moves.length > 0 && this.moves[0].notation == "..."
670 ? 1
671 : 0;
672 if (this.cursor < minCursor) return; //no more moves
673 move = this.moves[this.cursor];
674 }
675 this.$refs["board"].resetCurrentAttempt();
676 undoMove(move, this.vr);
677 if (light) this.cursor--;
678 else {
679 this.positionCursorTo(this.cursor - 1);
680 this.incheck = this.vr.getCheckSquares();
681 this.emitFenIfAnalyze();
682 }
683 }
684 },
685 gotoMove: function(index) {
686 if (
687 this.autoplay ||
688 !!this.$refs["board"].selectedPiece ||
689 this.$refs["board"].choices.length > 0
690 ) {
691 return;
692 }
693 this.$refs["board"].resetCurrentAttempt();
694 if (this.inMultimove) this.cancelCurrentMultimove();
695 if (index == this.cursor) return;
696 if (index < this.cursor) {
697 while (this.cursor > index)
698 this.undo(null, null, "light");
699 }
700 else {
701 // index > this.cursor)
702 while (this.cursor < index)
703 this.play(null, null, "light");
704 }
705 // NOTE: next line also re-assign cursor, but it's very light
706 this.positionCursorTo(index);
707 this.incheck = this.vr.getCheckSquares();
708 this.emitFenIfAnalyze();
709 },
710 gotoBegin: function() {
711 if (
712 this.autoplay ||
713 !!this.$refs["board"].selectedPiece ||
714 this.$refs["board"].choices.length > 0
715 ) {
716 return;
717 }
718 this.$refs["board"].resetCurrentAttempt();
719 if (this.inMultimove) this.cancelCurrentMultimove();
720 const minCursor =
721 this.moves.length > 0 && this.moves[0].notation == "..."
722 ? 1
723 : 0;
724 while (this.cursor >= minCursor) this.undo(null, null, "light");
725 this.lastMove = (minCursor == 1 ? this.moves[0] : null);
726 this.incheck = this.vr.getCheckSquares();
727 this.emitFenIfAnalyze();
728 },
729 gotoEnd: function() {
730 if (this.cursor == this.moves.length - 1) return;
731 this.gotoMove(this.moves.length - 1);
732 },
733 flip: function() {
734 if (this.$refs["board"].choices.length > 0) return;
735 this.orientation = V.GetOppCol(this.orientation);
736 }
737 }
738 };
739 </script>
740
741 <style lang="sass" scoped>
742 [type="checkbox"]#modalEog+div .card
743 min-height: 45px
744 max-width: 350px
745
746 #baseGame
747 width: 100%
748 &:focus
749 outline: none
750
751 #gameContainer
752 margin-left: auto
753 margin-right: auto
754
755 #downloadDiv
756 display: inline-block
757
758 #controls
759 user-select: none
760 button
761 border: none
762 margin: 0
763 padding-top: 5px
764 padding-bottom: 5px
765
766 p#fenAnalyze
767 margin: 5px
768
769 .in-autoplay
770 background-color: #FACF8C
771
772 img.inline
773 height: 22px
774 padding-top: 5px
775 @media screen and (max-width: 767px)
776 height: 18px
777
778 #turnIndicator
779 text-align: center
780 font-weight: bold
781
782 #boardContainer
783 float: left
784 // TODO: later, maybe, allow movesList of variable width
785 // or e.g. between 250 and 350px (but more complicated)
786
787 #movesList
788 width: 280px
789 float: left
790
791 @media screen and (max-width: 767px)
792 #movesList
793 width: 100%
794 float: none
795 clear: both
796 </style>