X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=1b216efae937c63afda5cc41cdd17dbd0110b2c0;hb=3c09dc498791ac478679bf2f42f441342c4fa22c;hp=3f74fde92a0552a5f11681f273c88df22a751bea;hpb=4b3539364e8fea527158f4ba27db1c0870ffd2fc;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 3f74fde9..1b216efa 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -393,6 +393,11 @@ Vue.component('my-game', { ? localStorage.getItem("myid") // random enough (TODO: function) : (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase(); + if (!continuation) + { + // HACK: play a small silent sound to allow "new game" sound later if tab not focused + new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {}); + } this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant); const socketOpenListener = () => { if (continuation) @@ -644,6 +649,13 @@ Vue.component('my-game', { }, playComputerMove: function() { const timeStart = Date.now(); + const nbMoves = this.vr.moves.length; //using played moves to know if search finished + setTimeout( + () => { + const L = this.vr.moves.length; + if (nbMoves == L || !this.vr.moves[L-1].notation) //move search didn't finish + this.vr.shouldReturn = true; + }, 5000); const compMove = this.vr.getComputerMove(); // (first move) HACK: avoid selecting elements before they appear on page: const delay = Math.max(500-(Date.now()-timeStart), 0); @@ -734,8 +746,9 @@ Vue.component('my-game', { let rectStart = startSquare.getBoundingClientRect(); let rectEnd = endSquare.getBoundingClientRect(); let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y}; - let movingPiece = document.querySelector("#" + this.getSquareId(move.start) + " > img.piece"); - // HACK for animation (otherwise with positive translate, image slides "under background"...) + let movingPiece = + document.querySelector("#" + this.getSquareId(move.start) + " > img.piece"); + // HACK for animation (with positive translate, image slides "under background"...) // Possible improvement: just alter squares on the piece's way... squares = document.getElementsByClassName("board"); for (let i=0; i