X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=eb01442da0132185abeeac5ed6b56c851c1707fe;hb=21e8e7122487ae9417c5e7e72c25aa642b7a1226;hp=6f11aa13225133ef932a12b573d5b8f092ee554a;hpb=a430bd53ded9c51a741acba820e153da5a138231;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 6f11aa1..eb01442 100644 --- a/base_rules.js +++ b/base_rules.js @@ -664,6 +664,7 @@ export default class ChessRules { } else this.g_pieces = ArrayFun.init(this.size.x, this.size.y, null); let container = document.getElementById(this.containerId); + if (!r) r = container.getBoundingClientRect(); const pieceWidth = this.getPieceWidth(r.width); for (let i=0; i < this.size.x; i++) { for (let j=0; j < this.size.y; j++) { @@ -2067,24 +2068,36 @@ export default class ChessRules { } playReceivedMove(moves, 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); + }; + 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; - setTimeout(() => this.playReceivedMove(moves, callback), 700); + checkDisplayThenAnimate(); }; - 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); + else checkDisplayThenAnimate(); } };