feat(webui): currencies (#931)

Closes #854

Reviewed-on: OpenWF/SpaceNinjaServer#931
This commit is contained in:
Sainan 2025-02-09 07:17:42 -08:00
parent 4504b95977
commit 7c59d4fe3f
6 changed files with 103 additions and 2 deletions

View File

@ -0,0 +1,17 @@
import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory } from "@/src/services/inventoryService";
export const addCurrencyController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = req.body as IAddCurrencyRequest;
inventory[request.currency] += request.delta;
await inventory.save();
res.end();
};
interface IAddCurrencyRequest {
currency: "RegularCredits" | "PremiumCredits" | "FusionPoints" | "PrimeTokens";
delta: number;
}

View File

@ -8,13 +8,14 @@ import { deleteAccountController } from "@/src/controllers/custom/deleteAccountC
import { renameAccountController } from "@/src/controllers/custom/renameAccountController";
import { createAccountController } from "@/src/controllers/custom/createAccountController";
import { createMessageController } from "@/src/controllers/custom/createMessageController";
import { addCurrencyController } from "../controllers/custom/addCurrencyController";
import { addItemsController } from "@/src/controllers/custom/addItemsController";
import { addXpController } from "@/src/controllers/custom/addXpController";
import { importController } from "@/src/controllers/custom/importController";
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
import { createMessageController } from "@/src/controllers/custom/createMessageController";
const customRouter = express.Router();
@ -27,6 +28,7 @@ customRouter.get("/renameAccount", renameAccountController);
customRouter.post("/createAccount", createAccountController);
customRouter.post("/createMessage", createMessageController);
customRouter.post("/addCurrency", addCurrencyController);
customRouter.post("/addItems", addItemsController);
customRouter.post("/addXp", addXpController);
customRouter.post("/import", importController);

View File

@ -94,6 +94,56 @@
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
<div class="row g-3">
<div class="col-md-3">
<div class="card mb-3">
<h5 class="card-header" data-loc="currency_RegularCredits"></h5>
<div class="card-body">
<p class="card-text" id="RegularCredits-owned"></p>
<form class="input-group" onsubmit="doAddCurrency('RegularCredits');return false;">
<input class="form-control" id="RegularCredits-delta" type="number" value="1000000" step="1000000" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card mb-3">
<h5 class="card-header" data-loc="currency_PremiumCredits"></h5>
<div class="card-body">
<p class="card-text" id="PremiumCredits-owned"></p>
<form class="input-group" onsubmit="doAddCurrency('PremiumCredits');return false;">
<input class="form-control" id="PremiumCredits-delta" type="number" value="100" step="100" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card mb-3">
<h5 class="card-header" data-loc="currency_FusionPoints"></h5>
<div class="card-body">
<p class="card-text" id="FusionPoints-owned"></p>
<form class="input-group" onsubmit="doAddCurrency('FusionPoints');return false;">
<input class="form-control" id="FusionPoints-delta" type="number" value="1000" step="1000" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card mb-3">
<h5 class="card-header" data-loc="currency_PrimeTokens"></h5>
<div class="card-body">
<p class="card-text" id="PrimeTokens-owned"></p>
<form class="input-group" onsubmit="doAddCurrency('PrimeTokens');return false;">
<input class="form-control" id="PrimeTokens-delta" type="number" value="1" step="1" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-lg-6">
<div class="card mb-3" style="height: 400px;">

View File

@ -227,6 +227,15 @@ function updateInventory() {
window.didInitialInventoryUpdate = true;
// Populate inventory route
[
"RegularCredits",
"PremiumCredits",
"FusionPoints",
"PrimeTokens"
].forEach(currency => {
document.getElementById(currency + "-owned").textContent = loc("currency_owned").split("|COUNT|").join(data[currency].toLocaleString());
});
[
"Suits",
"SpaceSuits",
@ -1116,3 +1125,16 @@ function doChangeSupportedSyndicate() {
});
});
}
function doAddCurrency(currency) {
$.post({
url: "/custom/addCurrency?" + window.authz,
contentType: "application/json",
data: JSON.stringify({
currency,
delta: document.getElementById(currency + "-delta").valueAsNumber
})
}).then(function () {
updateInventory();
});
}

View File

@ -1,5 +1,5 @@
dict = {
general_inventoryUpdateNote: `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.`,
general_inventoryUpdateNote: `Note: Changes made here will only be applied in-game when the game syncs the inventory. Visiting the navigation should be the easiest way to trigger that.`,
general_addButton: `Add`,
general_bulkActions: `Bulk Actions`,
code_nonValidAuthz: `Your credentials are no longer valid.`,
@ -72,6 +72,11 @@ dict = {
inventory_bulkRankUpSpaceWeapons: `Max Rank All Archwing Weapons`,
inventory_bulkRankUpSentinels: `Max Rank All Sentinels`,
inventory_bulkRankUpSentinelWeapons: `Max Rank All Sentinel Weapons`,
currency_RegularCredits: `Credits`,
currency_PremiumCredits: `Platinum`,
currency_FusionPoints: `Endo`,
currency_PrimeTokens: `Regal Aya`,
currency_owned: `You have |COUNT|.`,
powersuit_archonShardsLabel: `Archon Shard Slots`,
powersuit_archonShardsDescription: `You can use these unlimited slots to apply a wide range of upgrades`,
mods_addRiven: `Add Riven`,

View File

@ -73,6 +73,11 @@ dict = {
inventory_bulkRankUpSpaceWeapons: `Максимальный ранг всего оружия арчвингов`,
inventory_bulkRankUpSentinels: `Максимальный ранг всех стражей`,
inventory_bulkRankUpSentinelWeapons: `Максимальный ранг всего оружия стражей`,
currency_RegularCredits: `[UNTRANSLATED] Credits`,
currency_PremiumCredits: `[UNTRANSLATED] Platinum`,
currency_FusionPoints: `[UNTRANSLATED] Endo`,
currency_PrimeTokens: `[UNTRANSLATED] Regal Aya`,
currency_owned: `[UNTRANSLATED] You have |COUNT|.`,
powersuit_archonShardsLabel: `Ячейки осколков архонта`,
powersuit_archonShardsDescription: `Вы можете использовать эти неограниченные ячейки для установки множества улучшений.`,
mods_addRiven: `Добавить Мод Разлома`,