XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

fix(webui): max rank (#859)

3cd66391
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +27 -8
Added src/controllers/custom/addXpController.ts +20 -0
@@ -0,0 +1,20 @@
1 import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
4 import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
5 import { RequestHandler } from "express";
6
7 export const addXpController: RequestHandler = async (req, res) => {
8 const accountId = await getAccountIdForRequest(req);
9 const inventory = await getInventory(accountId);
10 const request = req.body as IAddXpRequest;
11 for (const [category, gear] of Object.entries(request)) {
12 addGearExpByCategory(inventory, gear, category as TEquipmentKey);
13 }
14 await inventory.save();
15 res.end();
16 };
17
18 type IAddXpRequest = {
19 [_ in TEquipmentKey]: IEquipmentClient[];
20 };
Modified src/routes/custom.ts +2 -0
@@ -9,6 +9,7 @@ import { renameAccountController } from "@/src/controllers/custom/renameAccountC
9 9
10 10 import { createAccountController } from "@/src/controllers/custom/createAccountController";
11 11 import { addItemsController } from "@/src/controllers/custom/addItemsController";
12 import { addXpController } from "@/src/controllers/custom/addXpController";
12 13 import { importController } from "@/src/controllers/custom/importController";
13 14
14 15 import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
@@ -25,6 +26,7 @@ customRouter.get("/renameAccount", renameAccountController);
25 26
26 27 customRouter.post("/createAccount", createAccountController);
27 28 customRouter.post("/addItems", addItemsController);
29 customRouter.post("/addXp", addXpController);
28 30 customRouter.post("/import", importController);
29 31
30 32 customRouter.get("/config", getConfigDataController);
Modified static/webui/script.js +5 -8
@@ -249,10 +249,7 @@ function updateInventory() {
249 249 maxXP /= 2;
250 250 }
251 251
252 if (
253 item.XP < maxXP &&
254 category != "MechSuits" // missionInventoryUpdate currently doesn't handle this category
255 ) {
252 if (item.XP < maxXP) {
256 253 const a = document.createElement("a");
257 254 a.href = "#";
258 255 a.onclick = function (event) {
@@ -645,8 +642,8 @@ function addGearExp(category, oid, xp) {
645 642 ];
646 643 revalidateAuthz(() => {
647 644 $.post({
648 url: "/api/missionInventoryUpdate.php?" + window.authz,
649 contentType: "text/plain",
645 url: "/custom/addXp?" + window.authz,
646 contentType: "application/json",
650 647 data: JSON.stringify(data)
651 648 }).done(function () {
652 649 if (category != "SpecialItems") {
@@ -659,8 +656,8 @@ function addGearExp(category, oid, xp) {
659 656 function sendBatchGearExp(data) {
660 657 revalidateAuthz(() => {
661 658 $.post({
662 url: "/api/missionInventoryUpdate.php?" + window.authz,
663 contentType: "text/plain",
659 url: "/custom/addXp?" + window.authz,
660 contentType: "application/json",
664 661 data: JSON.stringify(data)
665 662 }).done(() => {
666 663 updateInventory();