From 857bd738fae2eef283a115124c3df16b875b4459 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 8 Feb 2025 22:46:39 +0100 Subject: [PATCH] feat(webui): add currencies --- .../custom/addCurrencyController.ts | 17 +++++++ src/routes/custom.ts | 4 +- static/webui/index.html | 50 +++++++++++++++++++ static/webui/script.js | 22 ++++++++ static/webui/translations/en.js | 5 ++ static/webui/translations/ru.js | 5 ++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/controllers/custom/addCurrencyController.ts diff --git a/src/controllers/custom/addCurrencyController.ts b/src/controllers/custom/addCurrencyController.ts new file mode 100644 index 00000000..63dedb6f --- /dev/null +++ b/src/controllers/custom/addCurrencyController.ts @@ -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; +} diff --git a/src/routes/custom.ts b/src/routes/custom.ts index 3ada9830..ad2ea069 100644 --- a/src/routes/custom.ts +++ b/src/routes/custom.ts @@ -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); diff --git a/static/webui/index.html b/static/webui/index.html index 08995f54..8e284362 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -94,6 +94,56 @@ +
+
+
+
+
+

+
+ + +
+
+
+
+
+
+
+
+

+
+ + +
+
+
+
+
+
+
+
+

+
+ + +
+
+
+
+
+
+
+
+

+
+ + +
+
+
+
+
diff --git a/static/webui/script.js b/static/webui/script.js index 476c3c6a..a7afa25d 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -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(); + }); +} diff --git a/static/webui/translations/en.js b/static/webui/translations/en.js index 1c916415..3b8d261b 100644 --- a/static/webui/translations/en.js +++ b/static/webui/translations/en.js @@ -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`, diff --git a/static/webui/translations/ru.js b/static/webui/translations/ru.js index 97310997..e6e0c95f 100644 --- a/static/webui/translations/ru.js +++ b/static/webui/translations/ru.js @@ -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: `Добавить Мод Разлома`,