X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=ff698f47bd0adb99b8f900d67295eb2f8cfa0e40;hb=2dba3fe12f4a2970e5ed01e77e07c7bece56bdc0;hp=ffb9fd65864e64d705683c3065b048ade8b8088c;hpb=41534b92f0bcfc8ef5f58d8040706a5e7ce088c6;p=xogo.git diff --git a/base_rules.js b/base_rules.js index ffb9fd6..ff698f4 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 += ` { - 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(); - }); + 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(); + }); + }; + 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.hasFocus()) { + window.onfocus = () => { + window.onfocus = undefined; + checkDisplayThenAnimate(); + }; + } + else checkDisplayThenAnimate(); } };