aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-19 23:48:17 +0100
committerGitHub <noreply@github.com>2022-01-19 23:48:17 +0100
commitae7de46f4748c800097f0f3c700e6525d7d7cc4f (patch)
tree5c66168894e5ad3b26e0330d24d62e1a985bea7c /src/app
parent2ed4338b9608211c07c4dd620e7f3b073131388a (diff)
parentcc2fcbbdba49149724de7a07415d0dee23cc57d1 (diff)
downloadViper-ae7de46f4748c800097f0f3c700e6525d7d7cc4f.tar.gz
Viper-ae7de46f4748c800097f0f3c700e6525d7d7cc4f.zip
Merge pull request #46 from 0neGal/documentation
Adding documentation/comments
Diffstat (limited to 'src/app')
-rw-r--r--src/app/lang.js9
-rw-r--r--src/app/launcher.js5
-rw-r--r--src/app/main.js22
3 files changed, 33 insertions, 3 deletions
diff --git a/src/app/lang.js b/src/app/lang.js
index 5cc9708..6fdcd8d 100644
--- a/src/app/lang.js
+++ b/src/app/lang.js
@@ -1,12 +1,19 @@
+// Replaces strings in the HTML will language strings properly. This
+// searches for %%<string>%%, aka, %%gui.exit%% will be replaced with
+// "Exit", this works without issues.
function setlang() {
+ // Finds %%%% strings
html = document.body.innerHTML.split("%%");
for (let i = 0; i < html.length; i++) {
+ // Simply checks to make sure it is actually a lang string.
if (html[i][0] != " " &&
html[i][html[i].length - 1] != " ") {
+ // Replaces it with it's string
html[i] = lang(html[i])
}
}
-
+
+ // Replaces the original HTML with the translated/replaced HTML
document.body.innerHTML = html.join("");
}
diff --git a/src/app/launcher.js b/src/app/launcher.js
index 2c8d123..60c0d18 100644
--- a/src/app/launcher.js
+++ b/src/app/launcher.js
@@ -1,5 +1,7 @@
const markdown = require("marked").parse;
+// Changes the main page
+// This is the tabs in the sidebar
function page(page) {
let pages = document.querySelectorAll(".mainContainer .contentContainer")
let btns = document.querySelectorAll(".gamesContainer button")
@@ -18,6 +20,7 @@ function page(page) {
}; page(0)
+// Updates the Viper release notes
ipcRenderer.on("vp-notes", (event, response) => {
let content = "";
@@ -28,11 +31,13 @@ ipcRenderer.on("vp-notes", (event, response) => {
vpReleaseNotes.innerHTML = markdown(content);
});
+
async function loadVpReleases() {
ipcRenderer.send("get-vp-notes");
}; loadVpReleases();
+// Updates the Northstar release notes
ipcRenderer.on("ns-notes", (event, response) => {
let content = "";
diff --git a/src/app/main.js b/src/app/main.js
index 893572a..5f0cc9a 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -5,6 +5,7 @@ const { ipcRenderer, shell } = require("electron");
const lang = require("../lang");
let shouldInstallNorthstar = false;
+// Base settings
var settings = {
gamepath: "",
autoupdate: true,
@@ -16,8 +17,10 @@ var settings = {
]
}
+// Sets the lang to the system default
ipcRenderer.send("setlang", settings.lang);
+// Loads the settings
if (fs.existsSync("viper.json")) {
settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
@@ -38,11 +41,11 @@ function update() {ipcRenderer.send("update")}
// Reports to the main process about game path status.
// @param {boolean} value is game path loaded
-
function setpath(value = false) {
ipcRenderer.send("setpath", value);
}
+// Tells the main process to launch or install Northstar
function launch() {
if (shouldInstallNorthstar) {
update();
@@ -51,17 +54,23 @@ function launch() {
ipcRenderer.send("launch");
}
}
+
+// Tells the main process to launch the vanilla game
function launchVanilla() {ipcRenderer.send("launchVanilla")}
+// In conjunction with utils.js' winLog(), it'll send log messages in
+// the devTools from utils.js
function log(msg) {
console.log(msg);
- // welcome.innerHTML = msg;
}
+// Disables or enables certain buttons when for example
+// updating/installing Northstar.
function setButtons(state) {
playNsBtn.disabled = !state;
}
+// Frontend part of updating Northstar
ipcRenderer.on("ns-update-event", (event, key) => {
document.getElementById("update").innerText = `(${lang(key)})`;
console.log(key);
@@ -90,6 +99,7 @@ function select(entry) {
}
}
+// Mod selection
function selected(all) {
let selected = "";
if (all) {
@@ -138,17 +148,21 @@ function selected(all) {
}
}
+// Tells the main process to install a mod
function installmod() {
ipcRenderer.send("installmod")
}
+// Frontend part of settings a new game path
ipcRenderer.on("newpath", (event, newpath) => {
settings.gamepath = newpath;
})
+// Continuation of log()
ipcRenderer.on("log", (event, msg) => {log(msg)})
ipcRenderer.on("alert", (event, msg) => {alert(msg)})
+// Updates the installed mods
ipcRenderer.on("mods", (event, mods) => {
modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`;
modsdiv.innerHTML = "";
@@ -169,6 +183,7 @@ ipcRenderer.on("mods", (event, mods) => {
select(lastselected);
})
+// Updates version numbers
ipcRenderer.on("version", (event, versions) => {
vpversion.innerText = versions.vp;
nsversion.innerText = versions.ns;
@@ -187,17 +202,20 @@ ipcRenderer.on("version", (event, versions) => {
}
}); ipcRenderer.send("getversion");
+// When an update is available it'll ask the user about it
ipcRenderer.on("updateavailable", () => {
if (confirm(lang("gui.update.available"))) {
ipcRenderer.send("updatenow");
}
})
+// Error out when no game path is set
ipcRenderer.on("nopathselected", () => {
alert(lang("gui.gamepath.must"));
exit();
});
+// Error out when game path is wrong
ipcRenderer.on("wrongpath", () => {
alert(lang("gui.gamepath.wrong"));
setpath(false);