Add Config Change To WebUI

Adds a settings menu to change various options.

Currently can only change config.json, changing postTutorialInventory.json for the purpose of standing caps planned.
This commit is contained in:
Vampire Kitten 2024-06-14 01:49:18 +02:00
parent 60c7d5b5b0
commit 4204c21780
6 changed files with 157 additions and 11 deletions

View File

@ -0,0 +1,10 @@
import { RequestHandler } from "express";
import path from "path";
const rootDir = path.join(__dirname, "../../..");
const getConfigData: RequestHandler = (_req, res) => {
const configFile = require(path.join(rootDir, "config.json"));
res.json(configFile);
};
export { getConfigData };

View File

@ -0,0 +1,16 @@
import { RequestHandler } from "express";
import path from "path";
const rootDir = path.join(__dirname, "../../..");
const updateConfigData: RequestHandler = async (req) => {
const fs = require('fs');
const updateSettingsData = req.body;
fs.writeFile(path.join(rootDir, "config.json"), updateSettingsData, function(err:any) {
if(err) {
return console.log(err);
}
});
};
export { updateConfigData };

View File

@ -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 { getConfigData } from "@/src/controllers/custom/getConfigData";
import { updateConfigData } from "@/src/controllers/custom/updateConfigData";
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", getConfigData);
customRouter.post("/config", updateConfigData);
export { customRouter };

View File

@ -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"));
});

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" href="libs/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<body onload="fetchSettings()">
<nav class="navbar sticky-top bg-body-tertiary">
<div class="container">
<button
@ -47,6 +47,16 @@
<div class="offcanvas-body">
<div class="navbar p-0">
<ul class="navbar-nav justify-content-end">
<li class="nav-item">
<a
class="nav-link"
href="/webui/settings"
data-bs-dismiss="offcanvas"
data-bs-target="#sidebar"
>
Settings
</a>
</li>
<li class="nav-item">
<a
class="nav-link"
@ -72,10 +82,6 @@
</div>
</div>
<div>
<p id="refresh-note" class="mb-4">
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.
</p>
<div data-route="/webui/" data-title="Login | OpenWF WebUI">
<p>Login using your OpenWF account credentials.</p>
<form onsubmit="doLogin();return false;">
@ -88,7 +94,67 @@
<button class="btn btn-primary" type="submit">Login</button>
</form>
</div>
<div data-route="/webui/settings" data-title="Settings | OpenWF WebUI">
<div class="card mb-4">
<h5 class="card-header">Change Settings</h5>
<form class="card-body" onsubmit="doChangeSettings();return false;">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="skipStoryModeChoice" />
<label label class="form-check-label" for="skipStoryModeChoice">Skip Story Mode Choice?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="skipTutorial" />
<label label class="form-check-label" for="skipTutorial">Skip Tutorial?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllScans" />
<label label class="form-check-label" for="unlockAllScans">Unlock All Scans?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllMissions" />
<label label class="form-check-label" for="unlockAllMissions">Unlock All Missions?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllQuests" />
<label label class="form-check-label" for="unlockAllQuests">Unlock All Quests?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="completeAllQuests" />
<label label class="form-check-label" for="completeAllQuests">Complete All Quests?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="infiniteResources" />
<label label class="form-check-label" for="infiniteResources">Infinite Credits and Platinum?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockallShipFeatures" />
<label label class="form-check-label" for="unlockallShipFeatures">Unlock All Ship Features?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllShipDecorations" />
<label label class="form-check-label" for="unlockAllShipDecorations">Unlock All Ship Decorations?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllFlavourItems" />
<label label class="form-check-label" for="unlockAllFlavourItems">Unlock All Accessories?</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="unlockAllSkins" />
<label label class="form-check-label" for="unlockAllSkins">Unlock All Skins?</label>
</div>
<div class="form-check">
<label label class="form-check-label" for="spoofMasteryRank">Spoofed Mastery Rank (-1 to disable)</label>
<input class="form-control" id="spoofMasteryRank" type="number" min="-1" value="" />
</div>
<button class="btn btn-primary" type="submit">Save Settings</button>
</form>
</div>
</div>
<div data-route="/webui/inventory" data-title="Inventory | OpenWF WebUI">
<p id="refresh-note" class="mb-4">
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.
</p>
<div class="card mb-4">
<h5 class="card-header">Add Items</h5>
<form class="card-body input-group" onsubmit="doAcquireMiscItems();return false;">
@ -133,6 +199,10 @@
</div>
</div>
<div data-route="/webui/mods" data-title="Mods | OpenWF WebUI">
<p id="refresh-note" class="mb-4">
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.
</p>
<div class="row">
<div class="col-xxl-6">
<div class="card mb-4">

View File

@ -95,17 +95,15 @@ window.itemListPromise = new Promise(resolve => {
"/Lotus/Weapons/Tenno/Rifle/LotusRifle": { name: "Rifle" },
"/Lotus/Weapons/Tenno/Shotgun/LotusShotgun": { name: "Shotgun" },
// Missing in data sources
"/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" }
"/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" },
"/Lotus/Weapons/Tenno/Grimoire/TnGrimoire": { name: "Grimoire" }
};
for (const [type, items] of Object.entries(data)) {
if (type != "badItems") {
items.forEach(item => {
if (item.uniqueName in data.badItems) {
item.name += " (Imposter)";
} else if (
item.uniqueName.substr(0, 18) != "/Lotus/Types/Game/" &&
item.uniqueName.substr(0, 18) != "/Lotus/StoreItems/"
) {
} else if (item.uniqueName.substr(0, 18) != "/Lotus/Types/Game/") {
const option = document.createElement("option");
option.setAttribute("data-key", item.uniqueName);
option.value = item.name;
@ -618,3 +616,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)
})
})
}