diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/main.css | 8 | ||||
-rw-r--r-- | src/app/main.js | 22 | ||||
-rw-r--r-- | src/index.js | 16 | ||||
-rw-r--r-- | src/lang/en.json | 5 | ||||
-rw-r--r-- | src/utils.js | 99 |
5 files changed, 138 insertions, 12 deletions
diff --git a/src/app/main.css b/src/app/main.css index c6c9bb9..8776ec9 100644 --- a/src/app/main.css +++ b/src/app/main.css @@ -47,11 +47,19 @@ nobr {white-space: nowrap} } #modsdiv { + padding: 1px; border-radius: var(--padding); background: var(--boxbackground); margin: calc(var(--padding) / 3) var(--padding); } +.mod { + margin: calc(var(--padding) / 3); + border-radius: calc(var(--padding) / 2) !important; +} + +.mod.selected {background: var(--background)} + .buttons { text-align: right; margin-left: auto; diff --git a/src/app/main.js b/src/app/main.js index ab80ba9..c500ba3 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -45,6 +45,18 @@ function setButtons(state) { } } +function select(entry) { + let entries = document.querySelectorAll("#modsdiv .mod"); + + for (let i = 0; i < entries.length; i++) { + if (entries[i].innerHTML == entry) { + entries[i].classList.add("selected"); + } else { + entries[i].classList.remove("selected"); + } + } +} + ipcRenderer.on("ns-updated", () => {setButtons(true)}) ipcRenderer.on("ns-updating", () => {setButtons(false)}) @@ -55,10 +67,14 @@ ipcRenderer.on("newpath", (event, newpath) => { ipcRenderer.on("log", (event, msg) => {log(msg)}) ipcRenderer.on("mods", (event, mods) => { - modcount.innerHTML = `${lang("gui.mods.count")} ${mods.length}`; + modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; - for (let i = 0; i < mods.length; i++) { - modsdiv.innerHTML += `<div class="mod">${mods[i].Name}</div>`; + for (let i = 0; i < mods.enabled.length; i++) { + modsdiv.innerHTML += `<div onclick="select('${mods.enabled[i].Name}')" class="mod">${mods.enabled[i].Name}</div>`; + } + + for (let i = 0; i < mods.disabled.length; i++) { + modsdiv.innerHTML += `<div onclick="select('${mods.disabled[i].Name} - Disabled')" class="mod">${mods.disabled[i].Name} - Disabled</div>`; } }) diff --git a/src/index.js b/src/index.js index 511aadb..161092a 100644 --- a/src/index.js +++ b/src/index.js @@ -83,10 +83,18 @@ ipcMain.on("versioncli", () => { ipcMain.on("getmods", (event) => { let mods = utils.mods.list(); - if (mods.length > 0) { - console.log(`${utils.lang("general.mods.installed")} ${mods.length}`) - for (let i = 0; i < mods.length; i++) { - console.log(` ${mods[i].Name} ${mods[i].Version}`) + if (mods.all.length > 0) { + console.log(`${utils.lang("general.mods.installed")} ${mods.all.length}`) + console.log(`${utils.lang("general.mods.enabled")} ${mods.enabled.length}`) + for (let i = 0; i < mods.enabled.length; i++) { + console.log(` ${mods.enabled[i].Name} ${mods.enabled[i].Version}`) + } + + if (mods.disabled.length > 0) { + console.log(`${utils.lang("general.mods.disabled")} ${mods.disabled.length}`) + for (let i = 0; i < mods.disabled.length; i++) { + console.log(` ${mods.disabled[i].Name} ${mods.disabled[i].Version}`) + } } cli.exit(0); } else { diff --git a/src/lang/en.json b/src/lang/en.json index 4221edb..c5e0d77 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -18,6 +18,9 @@ "cli.launch.linuxerror": "Launching the game is not currently supported on Linux", + "cli.mods.notamod": "Selected folder/file is not a mod", + "cli.mods.improperjson": "%s's mod.json has formatting errors", + "gui.welcome": "Welcome to Viper!", "gui.versions.viper": "Viper version", "gui.versions.northstar": "Northstar version", @@ -47,6 +50,8 @@ "general.launching": "Launching", + "general.mods.enabled": "Enabled mods:", + "general.mods.disabled": "Disabled mods:", "general.mods.installed": "Installed mods:", "general.missingpath": "Game path is not set!" } diff --git a/src/utils.js b/src/utils.js index c89a033..88e5f3a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,6 @@ -const fs = require("fs"); const path = require("path"); +const fs = require("fs-extra"); +const copy = require("copy-dir"); const { app, dialog, ipcMain } = require("electron"); const Emitter = require("events"); @@ -164,23 +165,111 @@ function winLog(msg) { ipcMain.emit("winLog", msg, msg); } +let modpath = path.join(settings.gamepath, "R2Northstar/mods"); const mods = { list: () => { let mods = []; - let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + let disabled = []; files = fs.readdirSync(modpath) files.forEach((file) => { if (fs.statSync(path.join(modpath, file)).isDirectory()) { if (fs.existsSync(path.join(modpath, file, "mod.json"))) { - mods.push(require(path.join(modpath, file, "mod.json"))) + try { + mods.push({...require(path.join(modpath, file, "mod.json")), FolderName: file, Disabled: false}) + }catch(err) { + console.log("error: " + lang("cli.mods.improperjson"), file) + mods.push({Name: file, FolderName: file, Version: "unknown", Disabled: false}) + } + } + } + }) + + let disabledPath = path.join(modpath, "disabled") + files = fs.readdirSync(disabledPath) + files.forEach((file) => { + if (fs.statSync(path.join(disabledPath, file)).isDirectory()) { + if (fs.existsSync(path.join(disabledPath, file, "mod.json"))) { + try { + disabled.push({...require(path.join(disabledPath, file, "mod.json")), FolderName: file, Disabled: true}) + }catch(err) { + console.log("error: " + lang("cli.mods.improperjson"), file) + disabled.push({Name: file, FolderName: file, Version: "unknown", Disabled: false}) + } } } }) - return mods; + return { + enabled: mods, + disabled: disabled, + all: [...mods, ...disabled] + }; }, -} + get: (mod) => { + let list = mods.list().all; + + for (let i = 0; i < list.length; i++) { + if (list[i].Name == mod) { + return list[i]; + } else {continue} + } + + return false; + }, + install: (mod) => { + if (fs.statSync(mod).isDirectory()) { + if (fs.statSync(path.join(mod, "mod.json"))) { + copy(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { + mode: true, + cover: true, + utimes: true, + }, (err) => { + if(err) {console.log("error:", err)}; + console.log(); + }); + cli.exit(); + return + } else { + console.log("error: " + lang("cli.mods.notamod")) + cli.exit(1); + return; + } + } + + fs.createReadStream(mod).pipe(unzip.Extract({path: modpath})) + .on("finish", () => { + cli.exit(); + }); + }, + remove: (mod) => { + let modName = mods.get(mod).FolderName; + let modPath = path.join(modpath, modName); + if (fs.statSync(modPath).isDirectory()) { + fs.rmSync(modPath, {recursive: true}); + cli.exit(); + } else { + cli.exit(1); + } + }, + toggle: (mod) => { + let disabled = path.join(modpath, "disabled"); + if (! fs.existsSync(disabled)) { + fs.mkdirSync(disabled) + } + + let modName = mods.get(mod).FolderName; + let modPath = path.join(modpath, modName); + let dest = path.join(disabled, modName); + + if (mods.get(mod).Disabled) { + modPath = path.join(disabled, modName); + dest = path.join(modpath, modName); + } + + fs.moveSync(modPath, dest) + } +}; module.exports = { mods, |