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

chore: get rid of some unecessary conditionals (#835)

a4c44e8b
Sainan <sainan@calamity.inc>
提交于

代码差异

15 个文件 +23 -39
Modified .eslintrc +1 -0
@@ -22,6 +22,7 @@
22 22 "@typescript-eslint/no-unsafe-assignment": "warn",
23 23 "@typescript-eslint/no-explicit-any": "warn",
24 24 "@typescript-eslint/no-loss-of-precision": "warn",
25 "@typescript-eslint/no-unnecessary-condition": "warn",
25 26 "no-case-declarations": "warn",
26 27 "prettier/prettier": "error",
27 28 "@typescript-eslint/semi": "error",
Modified src/controllers/api/claimCompletedRecipeController.ts +1 -3
@@ -26,9 +26,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
26 26 if (!accountId) throw new Error("no account id");
27 27
28 28 const inventory = await getInventory(accountId);
29 const pendingRecipe = inventory.PendingRecipes.find(
30 recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid
31 );
29 const pendingRecipe = inventory.PendingRecipes.id(claimCompletedRecipeRequest.RecipeIds[0].$oid);
32 30 if (!pendingRecipe) {
33 31 throw new Error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
34 32 }
Modified src/controllers/api/createGuildController.ts +0 -1
@@ -21,7 +21,6 @@ export const createGuildController: RequestHandler = async (req, res) => {
21 21 inventory.GuildId = guild._id;
22 22
23 23 // Give clan key (TODO: This should only be a blueprint)
24 inventory.LevelKeys ??= [];
25 24 inventory.LevelKeys.push({
26 25 ItemType: "/Lotus/Types/Keys/DojoKey",
27 26 ItemCount: 1
Modified src/controllers/api/findSessionsController.ts +3 -3
@@ -10,19 +10,19 @@ export const findSessionsController: RequestHandler = (_req, res) => {
10 10 logger.debug("Found ID");
11 11 const session = getSession(req.id);
12 12
13 if (session) res.json({ queryId: req.queryId, Sessions: session });
13 if (session.length) res.json({ queryId: req.queryId, Sessions: session });
14 14 else res.json({});
15 15 } else if (req.originalSessionId != undefined) {
16 16 logger.debug("Found OriginalSessionID");
17 17
18 18 const session = getSession(req.originalSessionId);
19 if (session) res.json({ queryId: req.queryId, Sessions: session });
19 if (session.length) res.json({ queryId: req.queryId, Sessions: session });
20 20 else res.json({});
21 21 } else {
22 22 logger.debug("Found SessionRequest");
23 23
24 24 const session = getSession(req);
25 if (session) res.json({ queryId: req.queryId, Sessions: session });
25 if (session.length) res.json({ queryId: req.queryId, Sessions: session });
26 26 else res.json({});
27 27 }
28 28 };
Modified src/controllers/api/focusController.ts +3 -3
@@ -70,7 +70,7 @@ export const focusController: RequestHandler = async (req, res) => {
70 70 cost += ExportFocusUpgrades[focusType].baseFocusPointCost;
71 71 inventory.FocusUpgrades.push({ ItemType: focusType, Level: 0 });
72 72 }
73 inventory.FocusXP[focusPolarity] -= cost;
73 inventory.FocusXP![focusPolarity] -= cost;
74 74 await inventory.save();
75 75 res.json({
76 76 FocusTypes: request.FocusTypes,
@@ -88,7 +88,7 @@ export const focusController: RequestHandler = async (req, res) => {
88 88 const focusUpgradeDb = inventory.FocusUpgrades.find(entry => entry.ItemType == focusUpgrade.ItemType)!;
89 89 focusUpgradeDb.Level = focusUpgrade.Level;
90 90 }
91 inventory.FocusXP[focusPolarity] -= cost;
91 inventory.FocusXP![focusPolarity] -= cost;
92 92 await inventory.save();
93 93 res.json({
94 94 FocusInfos: request.FocusInfos,
@@ -113,7 +113,7 @@ export const focusController: RequestHandler = async (req, res) => {
113 113 const request = JSON.parse(String(req.body)) as IUnbindUpgradeRequest;
114 114 const focusPolarity = focusTypeToPolarity(request.FocusTypes[0]);
115 115 const inventory = await getInventory(accountId);
116 inventory.FocusXP[focusPolarity] -= 750_000 * request.FocusTypes.length;
116 inventory.FocusXP![focusPolarity] -= 750_000 * request.FocusTypes.length;
117 117 addMiscItems(inventory, [
118 118 {
119 119 ItemType: "/Lotus/Types/Gameplay/Eidolon/Resources/SentientShards/SentientShardBrilliantItem",
Modified src/controllers/api/gildWeaponController.ts +0 -3
@@ -34,9 +34,6 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
34 34 data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
35 35
36 36 const inventory = await getInventory(accountId);
37 if (!inventory[data.Category]) {
38 throw new Error(`Category ${String(req.query.Category)} not found in inventory`);
39 }
40 37 const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
41 38 if (weaponIndex === -1) {
42 39 throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`);
Modified src/controllers/api/infestedFoundryController.ts +1 -1
@@ -239,7 +239,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
239 239 inventory.InfestedFoundry!.Slots!--;
240 240 }
241 241 inventory.InfestedFoundry!.ConsumedSuits ??= [];
242 inventory.InfestedFoundry!.ConsumedSuits?.push(consumedSuit);
242 inventory.InfestedFoundry!.ConsumedSuits.push(consumedSuit);
243 243 inventory.InfestedFoundry!.LastConsumedSuit = suit;
244 244 inventory.InfestedFoundry!.AbilityOverrideUnlockCooldown = new Date(
245 245 new Date().getTime() + 24 * 60 * 60 * 1000
Modified src/controllers/api/queueDojoComponentDestructionController.ts +4 -6
@@ -9,12 +9,10 @@ export const queueDojoComponentDestructionController: RequestHandler = async (re
9 9 guild.DojoComponents!.findIndex(x => x._id.toString() === componentId),
10 10 1
11 11 )[0];
12 if (component) {
13 const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
14 if (room) {
15 guild.DojoCapacity -= room.capacity;
16 guild.DojoEnergy -= room.energy;
17 }
12 const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
13 if (room) {
14 guild.DojoCapacity -= room.capacity;
15 guild.DojoEnergy -= room.energy;
18 16 }
19 17 await guild.save();
20 18 res.json({
Modified src/controllers/api/startRecipeController.ts +1 -0
@@ -75,6 +75,7 @@ export const startRecipeController: RequestHandler = async (req, res) => {
75 75 spectreLoadout.LongGuns = item.ItemType;
76 76 spectreLoadout.LongGunsModularParts = item.ModularParts;
77 77 } else {
78 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
78 79 console.assert(type == "/Lotus/Types/Game/LotusMeleeWeapon");
79 80 const item = inventory.Melee.id(oid)!;
80 81 spectreLoadout.Melee = item.ItemType;
Modified src/controllers/api/syndicateSacrificeController.ts +1 -1
@@ -22,7 +22,7 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp
22 22 InventoryChanges: {},
23 23 Level: data.SacrificeLevel,
24 24 LevelIncrease: level <= 0 ? 1 : level,
25 NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
25 NewEpisodeReward: syndicate.Tag == "RadioLegionIntermission9Syndicate"
26 26 };
27 27
28 28 const manifest = ExportSyndicates[data.AffiliationTag];
Modified src/controllers/stats/viewController.ts +0 -4
@@ -9,10 +9,6 @@ import { getInventory } from "@/src/services/inventoryService";
9 9 const viewController: RequestHandler = async (req, res) => {
10 10 const accountId = await getAccountIdForRequest(req);
11 11 const inventory = await getInventory(accountId, "XPInfo");
12 if (!inventory) {
13 res.status(400).json({ error: "inventory was undefined" });
14 return;
15 }
16 12
17 13 const responseJson: IStatsView = {};
18 14 responseJson.Weapons = [];
Modified src/services/itemDataService.ts +1 -7
@@ -50,13 +50,7 @@ export const getWeaponType = (weaponName: string): WeaponTypeInternal => {
50 50 throw new Error(`${weaponName} doesn't quack like a weapon`);
51 51 }
52 52
53 const weaponType = weaponInfo.productCategory;
54
55 if (!weaponType) {
56 throw new Error(`unknown weapon category for item ${weaponName}`);
57 }
58
59 return weaponType;
53 return weaponInfo.productCategory;
60 54 };
61 55
62 56 export const getRecipe = (uniqueName: string): IRecipe | undefined => {
Modified src/services/saveLoadoutService.ts +2 -2
Modified src/services/shipCustomizationsService.ts +3 -3
Modified src/types/inventoryTypes/inventoryTypes.ts +2 -2