From a670dbc3f7d00b8cdd8c8ff74e66d3c7d2d40a4a Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 28 May 2024 07:53:46 +0200 Subject: [PATCH] feat(webui): add Mods tab with "Add Riven" option --- src/routes/webui.ts | 3 ++ static/webui/index.html | 24 ++++++++++++++++ static/webui/script.js | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/src/routes/webui.ts b/src/routes/webui.ts index fce710e5..998953fc 100644 --- a/src/routes/webui.ts +++ b/src/routes/webui.ts @@ -21,6 +21,9 @@ webuiRouter.use("/webui", (req, res, next) => { webuiRouter.get("/webui/inventory", (_req, res) => { res.sendFile(path.join(rootDir, "static/webui/index.html")); }); +webuiRouter.get("/webui/mods", (_req, res) => { + res.sendFile(path.join(rootDir, "static/webui/index.html")); +}); // Serve static files webuiRouter.use("/webui", express.static(path.join(rootDir, "static/webui"))); diff --git a/static/webui/index.html b/static/webui/index.html index 3f7a736d..c8556dc3 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -52,6 +52,7 @@
@@ -116,6 +117,29 @@ +
+
+
Add Riven
+
+ + + + Need help with the fingerprint? +
+
+
diff --git a/static/webui/script.js b/static/webui/script.js index 8206d3ac..cf9d05fb 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -282,3 +282,66 @@ function doAcquireMiscItems() { $("#miscitem-name").on("input", () => { $("#miscitem-name").removeClass("is-invalid"); }); + +function doAcquireRiven() { + let fingerprint; + try { + fingerprint = JSON.parse($("#addriven-fingerprint").val()); + if (typeof fingerprint !== "object") { + fingerprint = JSON.parse(fingerprint); + } + } catch (e) {} + if ( + typeof fingerprint !== "object" || + !("compat" in fingerprint) || + !("pol" in fingerprint) || + !("buffs" in fingerprint) + ) { + $("#addriven-fingerprint").addClass("is-invalid").focus(); + return; + } + const uniqueName = "/Lotus/Upgrades/Mods/Randomized/" + $("#addriven-type").val(); + // Add riven type to inventory + $.post({ + url: "/api/missionInventoryUpdate.php?" + window.authz, + contentType: "text/plain", + data: JSON.stringify({ + RawUpgrades: [ + { + ItemType: uniqueName, + ItemCount: 1 + } + ] + }) + }).done(function () { + // Get riven's assigned id + $.get("/api/inventory.php?" + window.authz).done(data => { + for (const rawUpgrade of data.RawUpgrades) { + if (rawUpgrade.ItemType === uniqueName) { + // Add fingerprint to riven + $.post({ + url: "/api/artifacts.php?" + window.authz, + contentType: "text/plain", + data: JSON.stringify({ + Upgrade: { + ItemType: uniqueName, + UpgradeFingerprint: JSON.stringify(fingerprint), + ItemId: rawUpgrade.LastAdded + }, + LevelDiff: 0, + Cost: 0, + FusionPointCost: 0 + }) + }).done(function () { + alert("Successfully added."); + }); + break; + } + } + }); + }); +} + +$("#addriven-fingerprint").on("input", () => { + $("#addriven-fingerprint").removeClass("is-invalid"); +});