X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=app.js;h=5a46190adf4245414050f818aa225f861434fcea;hb=cc2c71836442d7495ec570f8f78c006ea60852e0;hp=8bd5e70a73f2f78e6f65be16244946cbd3e359e2;hpb=016306e3aa2262e141899f8d4b900421d68f5439;p=xogo.git diff --git a/app.js b/app.js index 8bd5e70..5a46190 100644 --- a/app.js +++ b/app.js @@ -95,8 +95,8 @@ function showNewGameForm() { $.getElementById("selectColor").selectedIndex = 0; toggleVisible("newGameForm"); import(`/variants/${vname}/class.js`).then(module => { - const Rules = module.default; - prepareOptions(Rules); + window.V = module.default; + prepareOptions(); }); } } @@ -108,9 +108,9 @@ function toggleStyle(e, word) { } let options; -function prepareOptions(Rules) { +function prepareOptions() { options = {}; - let optHtml = Rules.Options.select.map(select => { return ` + let optHtml = V.Options.select.map(select => { return `
@@ -128,7 +128,7 @@ function prepareOptions(Rules) {
`; }).join(""); - optHtml += Rules.Options.check.map(check => { + optHtml += V.Options.check.map(check => { return `
`; }).join(""); - if (Rules.Options.styles.length >= 1) { + if (V.Options.styles.length >= 1) { optHtml += '
'; let i = 0; - const stylesLength = Rules.Options.styles.length; + const stylesLength = V.Options.styles.length; while (i < stylesLength) { optHtml += '
'; for (let j=i; j${style}`; } @@ -165,10 +165,11 @@ function getGameLink() { for (const select of $.querySelectorAll("#gameOptions select")) { let value = select.value; if (select.attributes["data-numeric"]) value = parseInt(value, 10); - options[ select.id.split("_")[1] ] = value; + if (value) options[ select.id.split("_")[1] ] = value; + } + for (const check of $.querySelectorAll("#gameOptions input")) { + if (check.checked) options[ check.id.split("_")[1] ] = check.checked; } - for (const check of $.querySelectorAll("#gameOptions input")) - options[ check.id.split("_")[1] ] = check.checked; send("creategame", { vname: vname, player: { sid: sid, name: localStorage.getItem("name"), color: color }, @@ -404,21 +405,31 @@ let vr, playerColor; function initializeGame(obj) { const options = obj.options || {}; import(`/variants/${obj.vname}/class.js`).then(module => { - const Rules = module.default; + window.V = module.default; conditionalLoadCSS(obj.vname); playerColor = (sid == obj.players[0].sid ? "w" : "b"); // Init + remove potential extra DOM elements from a previous game: document.getElementById("boardContainer").innerHTML = `
- + + + + +
- + + + + +
`; - vr = new Rules({ + vr = new V({ seed: obj.seed, //may be null if FEN already exists (running game) fen: obj.fen, element: "chessboard",