X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=app.js;h=1090b30ce6c6f2545e775c156c76892387301b75;hb=126ffc709b84d4919dc2c1726577e59211198a1b;hp=6f17c6491e5244759e6d835a0e2ed7b0331434a9;hpb=5f08c59b29c2173cc8b2df1a3799ee971a14e691;p=xogo.git diff --git a/app.js b/app.js index 6f17c64..1090b30 100644 --- a/app.js +++ b/app.js @@ -488,21 +488,22 @@ const afterPlay = (move_s, newTurn, ops) => { } }; -let vr, playerColor; +let vr = null, playerColor, lastVname = undefined; function initializeGame(obj) { const options = obj.options || {}; import(`/variants/${obj.vname}/class.js`).then(module => { window.V = module.default; for (const [k, v] of Object.entries(V.Aliases)) window[k] = v; - // Load CSS. Avoid loading twice the same stylesheet: - const allIds = [].slice.call($.styleSheets).map(s => s.id); - const newId = obj.vname + "_css"; - if (!allIds.includes(newId)) { + if (lastVname != obj.vname) { + // Load CSS + unload potential previous one. + if (lastVname) + document.getElementById(lastVname + "_css").remove(); $.getElementsByTagName("head")[0].insertAdjacentHTML( "beforeend", - ``); + lastVname = obj.vname; } playerColor = (sid == obj.players[0].sid ? "w" : "b"); // Init + remove potential extra DOM elements from a previous game: @@ -526,6 +527,9 @@ function initializeGame(obj) {
`; + if (vr) + // Avoid interferences: + vr.removeListeners(); vr = new V({ seed: obj.seed, //may be null if FEN already exists (running game) fen: obj.fen,