diff --git a/src/controllers/custom/getConfigDataController.ts b/src/controllers/custom/getConfigDataController.ts new file mode 100644 index 00000000..8d946384 --- /dev/null +++ b/src/controllers/custom/getConfigDataController.ts @@ -0,0 +1,8 @@ +import { RequestHandler } from "express"; +import configFile from "@/config.json"; + +const getConfigDataController: RequestHandler = (_req, res) => { + res.json(configFile); +}; + +export { getConfigDataController }; diff --git a/src/controllers/custom/updateConfigDataController.ts b/src/controllers/custom/updateConfigDataController.ts new file mode 100644 index 00000000..38d6ca35 --- /dev/null +++ b/src/controllers/custom/updateConfigDataController.ts @@ -0,0 +1,16 @@ +import { RequestHandler } from "express"; +import path from "path"; +import fs from "fs"; +const rootDir = path.join(__dirname, "../../.."); + +const updateConfigDataController: RequestHandler = (req) => { + const updateSettingsData = req.body; + + fs.writeFile(path.join(rootDir, "config.json"), updateSettingsData, function(err:any) { + if(err) { + return console.log(err); + } + }); +}; + +export { updateConfigDataController }; diff --git a/src/routes/custom.ts b/src/routes/custom.ts index 8a4218d7..6c0a7416 100644 --- a/src/routes/custom.ts +++ b/src/routes/custom.ts @@ -2,6 +2,8 @@ import express from "express"; import { getItemListsController } from "@/src/controllers/custom/getItemListsController"; import { createAccountController } from "@/src/controllers/custom/createAccountController"; import { addItemController } from "@/src/controllers/custom/addItemController"; +import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController"; +import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController"; const customRouter = express.Router(); @@ -10,4 +12,7 @@ customRouter.get("/getItemLists", getItemListsController); customRouter.post("/createAccount", createAccountController); customRouter.post("/addItem", addItemController); -export { customRouter }; +customRouter.get("/config", getConfigDataController); +customRouter.post("/config", updateConfigDataController); + +export { customRouter }; \ No newline at end of file diff --git a/src/routes/webui.ts b/src/routes/webui.ts index 677031c6..93005f34 100644 --- a/src/routes/webui.ts +++ b/src/routes/webui.ts @@ -19,6 +19,9 @@ webuiRouter.use("/webui", (req, res, next) => { }); // Serve virtual routes +webuiRouter.get("/webui/settings", (_req, res) => { + res.sendFile(path.join(rootDir, "static/webui/index.html")); +}); webuiRouter.get("/webui/inventory", (_req, res) => { res.sendFile(path.join(rootDir, "static/webui/index.html")); }); diff --git a/static/webui/index.html b/static/webui/index.html index a680fd33..6ab05bad 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -67,15 +67,21 @@ Mods +
-

- Note: Changes made here will only be reflected in-game when the game re-downloads your inventory. - Visiting the navigation should be the easiest way to trigger that. -

Login using your OpenWF account credentials.

@@ -89,6 +95,10 @@
+

+ Note: Changes made here will only be reflected in-game when the game re-downloads your inventory. + Visiting the navigation should be the easiest way to trigger that. +

Add Items
@@ -133,6 +143,10 @@
+

+ Note: Changes made here will only be reflected in-game when the game re-downloads your inventory. + Visiting the navigation should be the easiest way to trigger that. +

@@ -189,6 +203,62 @@
+
+
+
Change Settings
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+
diff --git a/static/webui/script.js b/static/webui/script.js index 4220234a..b03de1d2 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -15,6 +15,7 @@ function loginFromLocalStorage() { window.accountId = data.id; window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce; updateInventory(); + fetchSettings(); }, () => { logout(); @@ -618,3 +619,47 @@ function doAcquireMod() { $("#mod-to-acquire").on("input", () => { $("#mod-to-acquire").removeClass("is-invalid"); }); + +function fetchSettings() { + fetch('/custom/config') + .then((response) => response.json()) + .then((json) => Object.entries(json).forEach((entry) => { + const [key, value] = entry; + var x = document.getElementById(`${key}`); + if (x!=null) { + if (x.type == "checkbox") { + if (value === true) { + x.setAttribute("checked", "checked") + } + } else if (x.type == "number") { + x.setAttribute("value", `${value}`) + } + } + })); +} + +function doChangeSettings() { + fetch('/custom/config') + .then((response) => response.json()) + .then((json) => { + for(var i in json) { + var x = document.getElementById(`${i}`); + if (x!=null) { + if (x.type == "checkbox") { + if (x.checked === true) { + json[i]=true; + } else { + json[i]=false; + } + } else if (x.type == "number") { + json[i]=parseInt(x.value); + } + } + } + $.post({ + url: "/custom/config", + contentType: "text/plain", + data: JSON.stringify(json, null, 2) + }) + }) +} \ No newline at end of file