X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=acee324a26f394eaaa40a7f16e55151cda5dcedd;hb=016306e3aa2262e141899f8d4b900421d68f5439;hp=6f11aa13225133ef932a12b573d5b8f092ee554a;hpb=fd31883bca850ffe4b854d8cc52d7457a61b9010;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 6f11aa1..acee324 100644 --- a/base_rules.js +++ b/base_rules.js @@ -482,7 +482,7 @@ export default class ChessRules { for (let y=0; y style --> background-image ? - board += ` { - window.onfocus = undefined; - setTimeout(() => this.playReceivedMove(moves, callback), 700); + const launchAnimation = () => { + const r = + document.getElementById(this.containerId).getBoundingClientRect(); + const animateRec = i => { + this.animate(moves[i], () => { + this.playVisual(moves[i], r); + this.play(moves[i]); + if (i < moves.length - 1) setTimeout(() => animateRec(i+1), 300); + else callback(); + }); }; - return; - } - const r = - document.getElementById(this.containerId).getBoundingClientRect(); - const animateRec = i => { - this.animate(moves[i], () => { - this.playVisual(moves[i], r); - this.play(moves[i]); - if (i < moves.length - 1) setTimeout(() => animateRec(i+1), 300); - else callback(); - }); + animateRec(0); }; - animateRec(0); + const checkDisplayThenAnimate = () => { + if (boardContainer.style.display == "none") { + alert("New move! Let's go back to game..."); + document.getElementById("gameInfos").style.display = "none"; + boardContainer.style.display = "block"; + setTimeout(launchAnimation, 700); + } + else launchAnimation(); //focused user! + }; + let boardContainer = document.getElementById("boardContainer"); + if (document.hidden) { + document.onvisibilitychange = () => { + document.onvisibilitychange = undefined; + checkDisplayThenAnimate(); + }; + } + else checkDisplayThenAnimate(); } };