diff options
author | 0neGal <mail@0negal.com> | 2023-01-27 22:59:06 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2023-01-27 22:59:06 +0100 |
commit | feef5a6c98239a2c08433aec1bbc4e5510a79e32 (patch) | |
tree | edd7f6fc7451a2d1de0ae207e2a654eb7eeda222 /src/app/js/launcher.js | |
parent | dee886fb40c4e8600a309a44e4a6938bcb61d51d (diff) | |
download | Viper-feef5a6c98239a2c08433aec1bbc4e5510a79e32.tar.gz Viper-feef5a6c98239a2c08433aec1bbc4e5510a79e32.zip |
move app/*.js files into app/js/
Diffstat (limited to 'src/app/js/launcher.js')
-rw-r--r-- | src/app/js/launcher.js | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/src/app/js/launcher.js b/src/app/js/launcher.js new file mode 100644 index 0000000..5330b7a --- /dev/null +++ b/src/app/js/launcher.js @@ -0,0 +1,167 @@ +const markdown = require("marked").parse; + +var servercount; +var playercount; +var masterserver; + +// Changes the main page +// This is the tabs in the sidebar +function page(page) { + let btns = document.querySelectorAll(".gamesContainer button"); + let pages = document.querySelectorAll(".mainContainer .contentContainer"); + + for (let i = 0; i < pages.length; i++) { + pages[i].classList.add("hidden"); + } + + for (let i = 0; i < btns.length; i++) { + btns[i].classList.add("inactive"); + } + + pages[page].classList.remove("hidden"); + btns[page].classList.remove("inactive"); + bgHolder.setAttribute("bg", page); +}; page(1) + +function formatRelease(notes) { + let content = ""; + + if (notes.length === 1) { + content = notes[0]; + } else { + for (let release of notes) { + if (release.prerelease) {continue} + let new_content = "# " + release.name + "\n\n" + release.body + "\n\n\n"; + content += + "<div class='release-block'>\n" + + markdown(new_content, {breaks: true}) + "\n" + + "</div>"; + } + + content = content.replaceAll(/\@(\S+)/g, `<a href="https://github.com/$1">@$1</a>`); + } + + return markdown(content, { + breaks: true + }); +} + +// Updates the Viper release notes +ipcRenderer.on("vp-notes", (event, response) => { + vpReleaseNotes.innerHTML = formatRelease(response); +}); + +// Updates the Northstar release notes +ipcRenderer.on("ns-notes", (event, response) => { + nsRelease.innerHTML = formatRelease(response); +}); + +async function loadVpReleases() { + ipcRenderer.send("get-vp-notes"); +}; loadVpReleases(); + +async function loadNsReleases() { + ipcRenderer.send("get-ns-notes"); +}; loadNsReleases(); + +// TODO: We gotta make this more automatic instead of switch statements +// it's both not pretty, but adding more sections requires way too much +// effort, compared to how it should be. +function showVpSection(section) { + if (!["main", "release", "info", "credits"].includes(section)) throw new Error("unknown vp section"); + vpMainBtn.removeAttribute("active"); + vpReleaseBtn.removeAttribute("active"); + vpInfoBtn.removeAttribute("active"); + + vpMain.classList.add("hidden"); + vpReleaseNotes.classList.add("hidden"); + vpInfo.classList.add("hidden"); + + switch(section) { + case "main": + vpMainBtn.setAttribute("active", ""); + vpMain.classList.remove("hidden"); + break; + case "release": + vpReleaseBtn.setAttribute("active", ""); + vpReleaseNotes.classList.remove("hidden"); + break; + case "info": + vpInfoBtn.setAttribute("active", ""); + vpInfo.classList.remove("hidden"); + break; + } +} + +function showNsSection(section) { + if (!["main", "release", "mods"].includes(section)) { + throw new Error("unknown ns section"); + } + + nsMainBtn.removeAttribute("active"); + nsModsBtn.removeAttribute("active"); + nsReleaseBtn.removeAttribute("active"); + + nsMain.classList.add("hidden"); + nsMods.classList.add("hidden"); + nsRelease.classList.add("hidden"); + + switch(section) { + case "main": + nsMainBtn.setAttribute("active", ""); + nsMain.classList.remove("hidden"); + break; + case "mods": + nsModsBtn.setAttribute("active", ""); + nsMods.style.display = "block"; + nsMods.classList.remove("hidden"); + break; + case "release": + nsReleaseBtn.setAttribute("active", ""); + nsRelease.classList.remove("hidden"); + break; + } +} + +async function loadServers() { + serverstatus.classList.add("checking"); + + try { + let servers = await (await fetch("https://northstar.tf/client/servers")).json(); + masterserver = true; + + playercount = 0; + servercount = servers.length; + + for (let i = 0; i < servers.length; i++) { + playercount += servers[i].playerCount + } + }catch (err) { + playercount = 0; + servercount = 0; + masterserver = false; + } + + serverstatus.classList.remove("checking"); + + if (servercount == 0 || ! servercount || ! playercount) {masterserver = false} + + let playerstr = lang("gui.server.players"); + if (playercount == 1) { + playerstr = lang("gui.server.player"); + } + + if (masterserver) { + serverstatus.classList.add("up"); + serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${playerstr}`; + } else { + serverstatus.classList.add("down"); + serverstatus.innerHTML = lang("gui.server.offline"); + + } +}; loadServers() + +// Refreshes every 5 minutes +setInterval(() => { + loadServers(); +}, 300000) |