aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/utils.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js
index 50ffed0..a41def4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -406,6 +406,56 @@ const mods = {
return false;
},
+
+ // Manages the enabledmods.json file
+ //
+ // It can both return info about the file, but also toggle mods in
+ // it, generate the file itself, and so on.
+ modfile: () => {
+ let file = path.join(modpath, "..", "enabledmods.json");
+
+ if (! fs.existsSync(modpath)) {
+ fs.mkdirSync(path.join(modpath), {recursive: true})
+ }
+
+ if (! fs.existsSync(file)) {
+ fs.writeFileSync(file, "{}")
+ }
+
+ return {
+ gen: () => {
+ let names = {};
+ let list = mods.list().all;
+ for (let i = 0; i < list.length; i++) {
+ names[list[i].Name] = true
+ }
+
+ fs.writeFileSync(file, JSON.stringify(names))
+ },
+ toggle: (mod) => {
+ let data = require(file);
+ data[mod] = !data[mod];
+ console.log(data)
+ },
+ get: () => {
+ let enabled = [];
+ let disabled = [];
+ let data = require(file);
+
+ for (let i in data) {
+ if (data[i]) {
+ enabled.push(data[i])
+ } else {disabled.push(data[i])}
+ }
+
+ return {
+ enabled: enabled,
+ disabled: disabled,
+ all: [...enabled, ...disabled]
+ }
+ }
+ };
+ },
// Installs mods from a file path
//
@@ -588,6 +638,8 @@ const mods = {
}
};
+console.log(mods.modfile().get())
+
module.exports = {
mods,
lang,