From 7c59d4fe3f31cc99ed541e90a61ee02757df0481 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 9 Feb 2025 07:17:42 -0800 Subject: [PATCH] feat(webui): currencies (#931) Closes #854 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/931 --- .../custom/addCurrencyController.ts | 17 +++++++ src/routes/custom.ts | 4 +- static/webui/index.html | 50 +++++++++++++++++++ static/webui/script.js | 22 ++++++++ static/webui/translations/en.js | 7 ++- static/webui/translations/ru.js | 5 ++ 6 files changed, 103 insertions(+), 2 deletions(-) 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 000000000..63dedb6f2 --- /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 3ada98303..ad2ea0697 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 08995f54b..8e2843621 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 476c3c6a4..a7afa25da 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 2087b210c..3b8d261bc 100644 --- a/static/webui/translations/en.js +++ b/static/webui/translations/en.js @@ -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`, diff --git a/static/webui/translations/ru.js b/static/webui/translations/ru.js index 973109976..e6e0c95fd 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: `Добавить Мод Разлома`,