X-Git-Url: https://git.auder.net/?p=xogo.git;a=blobdiff_plain;f=app.js;h=12c2b7ab65fea59a497ed1901a924889b0225491;hp=a6ee234aed96c204a2d7dd1ba63a46b5a1fdaa5b;hb=HEAD;hpb=e5f9342704d2a453c3cd2f84e31b1ea384b2d03d diff --git a/app.js b/app.js index a6ee234..c5d5c7f 100644 --- a/app.js +++ b/app.js @@ -34,7 +34,8 @@ $.getElementById("myName").value = localStorage.getItem("name"); let inputName = document.getElementById("myName"); let formField = document.getElementById("ng-name"); const setActive = (active) => { - if (active) formField.classList.add("form-field--is-active"); + if (active) + formField.classList.add("form-field--is-active"); else { formField.classList.remove("form-field--is-active"); inputName.value == '' @@ -57,8 +58,10 @@ function setName() { // Turn a "tab" on, and "close" all others function toggleVisible(element) { for (elt of document.querySelectorAll("main > div")) { - if (elt.id != element) elt.style.display = "none"; - else elt.style.display = "block"; + if (elt.id != element) + elt.style.display = "none"; + else + elt.style.display = "block"; } if (element == "boardContainer") { // Avoid smartphone scrolling effects (TODO?) @@ -69,7 +72,8 @@ function toggleVisible(element) { document.querySelector("html").style.overflow = "visible"; document.body.style.overflow = "visible"; // Workaround "superposed texts" effect: - if (element == "newGame") setActive(false); + if (element == "newGame") + setActive(false); } } @@ -83,27 +87,32 @@ function seekGame() { } } function cancelSeek() { - if (send("cancelseek", {vname: seek_vname})) toggleVisible("newGame"); + if (send("cancelseek", {vname: seek_vname})) + toggleVisible("newGame"); } -function sendRematch() { - if (send("rematch", {gid: gid})) toggleVisible("pendingRematch"); +function sendRematch(random) { + if (send("rematch", {gid: gid, random: !!random})) + toggleVisible("pendingRematch"); } function cancelRematch() { - if (send("norematch", {gid: gid})) toggleVisible("newGame"); + if (send("norematch", {gid: gid})) + toggleVisible("newGame"); } // Play with a friend (or not ^^) function showNewGameForm() { const vname = $.getElementById("selectVariant").value; - if (vname == "_random") alert("Select a variant first"); + if (vname == "_random") + alert("Select a variant first"); else { $.getElementById("gameLink").innerHTML = ""; $.getElementById("selectColor").selectedIndex = 0; toggleVisible("newGameForm"); import(`/variants/${vname}/class.js`).then(module => { window.V = module.default; - V.Aliases.forEach(e => window[e.key] = e.val); + for (const [k, v] of Object.entries(V.Aliases)) + window[k] = v; prepareOptions(); }); } @@ -121,11 +130,13 @@ function toggleStyle(event, obj) { let options; function prepareOptions() { options = {}; - let optHtml = V.Options.select.map(select => { return ` + let optHtml = ""; + if (V.Options.select) { + optHtml += V.Options.select.map(select => { return `
- ` + select.options.map(option => { return `
`; - }).join(""); - optHtml += V.Options.check.map(check => { - return ` -
-