X-Git-Url: https://git.auder.net/pieces/Cwda/c_white_knight.svg?a=blobdiff_plain;ds=inline;f=app.js;h=6036d49756f322a8dcbc7f1d33ee676095b2fffd;hb=635418a5af6d4bf3f497d319a235bf72e40c5683;hp=d8719404449b07742cdd54656f354814782a6c0a;hpb=f8b43ef764be4e90761aa20d99af79a7e1c32bdd;p=xogo.git diff --git a/app.js b/app.js index d871940..6036d49 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,26 +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; + for (const [k, v] of Object.entries(V.Aliases)) + window[k] = v; prepareOptions(); }); } @@ -156,7 +166,8 @@ function prepareOptions() { while (i < stylesLength) { optHtml += '