aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-06-08 18:36:27 +0200
committer0neGal <mail@0negal.com>2024-06-08 18:36:27 +0200
commit0577977182e7f4be2722f54ae50ff23aa8fe9032 (patch)
tree11613eceff4fc919d28df2c7d372ca0affad2469
parentceb90ab941a159d63ea5cace1c24dde6b8b96a86 (diff)
downloadViper-0577977182e7f4be2722f54ae50ff23aa8fe9032.tar.gz
Viper-0577977182e7f4be2722f54ae50ff23aa8fe9032.zip
convert js/launcher.js to a CommonJS module
-rw-r--r--src/app/index.html19
-rw-r--r--src/app/js/gamepath.js3
-rw-r--r--src/app/js/launcher.js40
-rw-r--r--src/app/main.js1
4 files changed, 34 insertions, 29 deletions
diff --git a/src/app/index.html b/src/app/index.html
index 5d5f0fc..d6df23e 100644
--- a/src/app/index.html
+++ b/src/app/index.html
@@ -230,17 +230,17 @@
</div>
<nav class="gamesContainer">
- <button id="vpBtn" tooltip="%%tooltip.pages.viper%%" tooltip-position="horizontal" onclick="page(0)"></button>
- <button id="nsBtn" tooltip="%%tooltip.pages.northstar%%" tooltip-position="horizontal" onclick="page(1)"></button>
- <button id="tfBtn" tooltip="%%tooltip.pages.titanfall%%" tooltip-position="horizontal" onclick="page(2)"></button>
+ <button id="vpBtn" tooltip="%%tooltip.pages.viper%%" tooltip-position="horizontal" onclick="launcher.change_page(0)"></button>
+ <button id="nsBtn" tooltip="%%tooltip.pages.northstar%%" tooltip-position="horizontal" onclick="launcher.change_page(1)"></button>
+ <button id="tfBtn" tooltip="%%tooltip.pages.titanfall%%" tooltip-position="horizontal" onclick="launcher.change_page(2)"></button>
</nav>
<div class="mainContainer">
<div id="vpContent" class="contentContainer">
<ul class="contentMenu">
- <li id="vpMainBtn" active onclick="showVpSection('main')">%%viper.menu.main%%</li>
- <li id="vpReleaseBtn" onclick="showVpSection('release')">%%viper.menu.release%%</li>
- <li id="vpInfoBtn" onclick="showVpSection('info')">%%viper.menu.info%%</li>
+ <li id="vpMainBtn" active onclick="launcher.show_vp('main')">%%viper.menu.main%%</li>
+ <li id="vpReleaseBtn" onclick="launcher.show_vp('release')">%%viper.menu.release%%</li>
+ <li id="vpInfoBtn" onclick="launcher.show_vp('info')">%%viper.menu.info%%</li>
</ul>
<div class="contentBody">
<div id="vpMain" class="section">
@@ -269,9 +269,9 @@
<div id="nsContent" class="contentContainer">
<ul class="contentMenu">
- <li id="nsMainBtn" active onclick="showNsSection('main')">%%ns.menu.main%%</li>
- <li id="nsModsBtn" onclick="showNsSection('mods')">%%ns.menu.mods%%</li>
- <li id="nsReleaseBtn" onclick="showNsSection('release')">%%ns.menu.release%%</li>
+ <li id="nsMainBtn" active onclick="launcher.show_ns('main')">%%ns.menu.main%%</li>
+ <li id="nsModsBtn" onclick="launcher.show_ns('mods')">%%ns.menu.mods%%</li>
+ <li id="nsReleaseBtn" onclick="launcher.show_ns('release')">%%ns.menu.release%%</li>
</ul>
<div class="contentBody">
<div id="nsMain" class="section">
@@ -336,6 +336,5 @@
<script src="js/popups.js"></script>
<script src="js/tooltip.js"></script>
<script src="js/browser.js"></script>
- <script src="js/launcher.js"></script>
</body>
</html>
diff --git a/src/app/js/gamepath.js b/src/app/js/gamepath.js
index 80e3158..c3e5c2b 100644
--- a/src/app/js/gamepath.js
+++ b/src/app/js/gamepath.js
@@ -2,6 +2,7 @@ const ipcRenderer = require("electron").ipcRenderer;
const lang = require("../../lang");
const process = require("./process");
+const launcher = require("./launcher");
const settings = require("./settings");
// frontend part of settings a new game path
@@ -16,7 +17,7 @@ ipcRenderer.on("newpath", (_, newpath) => {
// a previously valid gamepath no longer exists, and is therefore lost
ipcRenderer.on("gamepath-lost", () => {
- page(0);
+ launcher.change_page(0);
set_buttons(false, true);
alert(lang("gui.gamepath.lost"));
})
diff --git a/src/app/js/launcher.js b/src/app/js/launcher.js
index 6fe1686..913762b 100644
--- a/src/app/js/launcher.js
+++ b/src/app/js/launcher.js
@@ -1,11 +1,13 @@
const markdown = require("marked").parse;
+let launcher = {};
+
var servercount;
var playercount;
var masterserver;
// changes the main page, this is the tabs in the sidebar
-function page(page) {
+launcher.change_page = (page) => {
let btns = document.querySelectorAll(".gamesContainer button");
let pages = document.querySelectorAll(".mainContainer .contentContainer");
@@ -20,9 +22,9 @@ function page(page) {
pages[page].classList.remove("hidden");
btns[page].classList.remove("inactive");
bgHolder.setAttribute("bg", page);
-}; page(1)
+}; launcher.change_page(1)
-function formatRelease(notes) {
+launcher.format_release = (notes) => {
if (! notes) {return ""}
let content = "";
@@ -61,7 +63,7 @@ function formatRelease(notes) {
// sets content of `div` to a single release block with centered text
// inside it, the text being `lang(lang_key)`
-let set_error_content = (div, lang_key) => {
+launcher.error = (div, lang_key) => {
div.innerHTML =
"<div class='release-block'>" +
"<p><center>" +
@@ -73,39 +75,39 @@ let set_error_content = (div, lang_key) => {
// updates the Viper release notes
ipcRenderer.on("vp-notes", (event, response) => {
if (! response) {
- return set_error_content(
+ return launcher.error(
vpReleaseNotes,
"request.no_vp_release_notes"
)
}
- vpReleaseNotes.innerHTML = formatRelease(response);
+ vpReleaseNotes.innerHTML = launcher.format_release(response);
});
// updates the Northstar release notes
ipcRenderer.on("ns-notes", (event, response) => {
if (! response) {
- return set_error_content(
+ return launcher.error(
nsRelease,
"request.no_ns_release_notes"
)
}
- nsRelease.innerHTML = formatRelease(response);
+ nsRelease.innerHTML = launcher.format_release(response);
});
-async function loadVpReleases() {
+launcher.load_vp_notes = async () => {
ipcRenderer.send("get-vp-notes");
-}; loadVpReleases();
+}; launcher.load_vp_notes();
-async function loadNsReleases() {
+launcher.load_ns_notes = async () => {
ipcRenderer.send("get-ns-notes");
-}; loadNsReleases();
+}; launcher.load_ns_notes();
// 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) {
+launcher.show_vp = (section) => {
if (!["main", "release", "info", "credits"].includes(section)) throw new Error("unknown vp section");
vpMainBtn.removeAttribute("active");
vpReleaseBtn.removeAttribute("active");
@@ -131,8 +133,8 @@ function showVpSection(section) {
}
}
-function showNsSection(section) {
- if (!["main", "release", "mods"].includes(section)) {
+launcher.show_ns = (section) => {
+ if (! ["main", "release", "mods"].includes(section)) {
throw new Error("unknown ns section");
}
@@ -161,7 +163,7 @@ function showNsSection(section) {
}
}
-async function loadServers() {
+launcher.check_servers = async () => {
serverstatus.classList.add("checking");
try {
@@ -205,9 +207,11 @@ async function loadServers() {
serverstatus.innerHTML = lang("gui.server.offline");
}
-}; loadServers()
+}; launcher.check_servers()
// refreshes every 5 minutes
setInterval(() => {
- loadServers();
+ launcher.check_servers();
}, 300000)
+
+module.exports = launcher;
diff --git a/src/app/main.js b/src/app/main.js
index 9ad6344..b72c1f9 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -37,6 +37,7 @@ const request = require("./js/request");
const process = require("./js/process");
const settings = require("./js/settings");
const gamepath = require("./js/gamepath");
+const launcher = require("./js/launcher");
const is_running = require("./js/is_running");
const set_buttons = require("./js/set_buttons");