X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=68ca909ad1ab75a94e5f97cd8c05d1bfb8a436e6;hb=86f3c2cd59432a00121af015c505499a57edf568;hp=6f11aa13225133ef932a12b573d5b8f092ee554a;hpb=fd31883bca850ffe4b854d8cc52d7457a61b9010;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 6f11aa1..68ca909 100644 --- a/base_rules.js +++ b/base_rules.js @@ -628,12 +628,12 @@ export default class ChessRules { const ii = (flipped ? this.size.x - 1 - i : i); const jj = (flipped ? this.size.y - 1 - j : j); let fillOpacity = '1'; - if (this.options["dark"] && !this.enlightened[ii][jj]) - fillOpacity = '0.5'; + let classes = this.getSquareColorClass(ii, jj); + if (this.enlightened && !this.enlightened[ii][jj]) + classes += " in-shadow"; // NOTE: x / y reversed because coordinates system is reversed. - // TODO: CSS "wood" style, rect --> style --> background-image ? - board += ` { + 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(); } };