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

feat: import (#831)

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

代码差异

18 个文件 +450 -98
Modified src/controllers/api/arcaneCommonController.ts +1 -1
@@ -44,7 +44,7 @@ export const arcaneCommonController: RequestHandler = async (req, res) => {
44 44 ItemType: json.arcane.ItemType,
45 45 UpgradeFingerprint: JSON.stringify({ lvl: json.newRank })
46 46 });
47 upgradeId = inventory.Upgrades[newLength - 1]._id!.toString();
47 upgradeId = inventory.Upgrades[newLength - 1]._id.toString();
48 48 }
49 49
50 50 // Remove RawUpgrades
Modified src/controllers/api/artifactsController.ts +4 -4
@@ -1,7 +1,7 @@
1 1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { RequestHandler } from "express";
4 import { ICrewShipSalvagedWeaponSkin } from "@/src/types/inventoryTypes/inventoryTypes";
4 import { IInventoryClient, IUpgradeClient } from "@/src/types/inventoryTypes/inventoryTypes";
5 5 import { addMods, getInventory } from "@/src/services/inventoryService";
6 6 import { config } from "@/src/services/configService";
7 7
@@ -20,7 +20,7 @@ export const artifactsController: RequestHandler = async (req, res) => {
20 20 parsedUpgradeFingerprint.lvl += LevelDiff;
21 21 const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint);
22 22
23 let itemIndex = Upgrades.findIndex(upgrade => upgrade._id?.equals(ItemId!.$oid));
23 let itemIndex = Upgrades.findIndex(upgrade => upgrade._id.equals(ItemId.$oid));
24 24
25 25 if (itemIndex !== -1) {
26 26 Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint;
@@ -58,7 +58,7 @@ export const artifactsController: RequestHandler = async (req, res) => {
58 58 }
59 59
60 60 const changedInventory = await inventory.save();
61 const itemId = changedInventory.toJSON().Upgrades[itemIndex]?.ItemId?.$oid;
61 const itemId = changedInventory.toJSON<IInventoryClient>().Upgrades[itemIndex].ItemId.$oid;
62 62
63 63 if (!itemId) {
64 64 throw new Error("Item Id not found in upgradeMod");
@@ -68,7 +68,7 @@ export const artifactsController: RequestHandler = async (req, res) => {
68 68 };
69 69
70 70 interface IArtifactsRequest {
71 Upgrade: ICrewShipSalvagedWeaponSkin;
71 Upgrade: IUpgradeClient;
72 72 LevelDiff: number;
73 73 Cost: number;
74 74 FusionPointCost: number;
Modified src/controllers/api/getShipController.ts +1 -11
@@ -4,10 +4,10 @@ import allShipFeatures from "@/static/fixed_responses/allShipFeatures.json";
4 4 import { getAccountIdForRequest } from "@/src/services/loginService";
5 5 import { getPersonalRooms } from "@/src/services/personalRoomsService";
6 6 import { getShip } from "@/src/services/shipService";
7 import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
8 7 import { toOid } from "@/src/helpers/inventoryHelpers";
9 8 import { IGetShipResponse } from "@/src/types/shipTypes";
10 9 import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
10 import { getLoadout } from "@/src/services/loadoutService";
11 11
12 12 export const getShipController: RequestHandler = async (req, res) => {
13 13 const accountId = await getAccountIdForRequest(req);
@@ -38,13 +38,3 @@ export const getShipController: RequestHandler = async (req, res) => {
38 38
39 39 res.json(getShipResponse);
40 40 };
41
42 export const getLoadout = async (accountId: string) => {
43 const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
44
45 if (!loadout) {
46 throw new Error(`loadout not found for account ${accountId}`);
47 }
48
49 return loadout;
50 };
Modified src/controllers/api/infestedFoundryController.ts +2 -2
@@ -6,7 +6,7 @@ import { IOid } from "@/src/types/commonTypes";
6 6 import {
7 7 IConsumedSuit,
8 8 IHelminthFoodRecord,
9 IInfestedFoundry,
9 IInfestedFoundryDatabase,
10 10 IMiscItem,
11 11 ITypeCount
12 12 } from "@/src/types/inventoryTypes/inventoryTypes";
@@ -356,7 +356,7 @@ interface IHelminthFeedRequest {
356 356 }[];
357 357 }
358 358
359 export const addInfestedFoundryXP = (infestedFoundry: IInfestedFoundry, delta: number): ITypeCount[] => {
359 export const addInfestedFoundryXP = (infestedFoundry: IInfestedFoundryDatabase, delta: number): ITypeCount[] => {
360 360 const recipeChanges: ITypeCount[] = [];
361 361 infestedFoundry.XP ??= 0;
362 362 const prevXP = infestedFoundry.XP;
Modified src/controllers/api/inventoryController.ts +5 -4
@@ -4,7 +4,7 @@ import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
4 4 import { config } from "@/src/services/configService";
5 5 import allDialogue from "@/static/fixed_responses/allDialogue.json";
6 6 import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
7 import { IInventoryResponse, IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
7 import { IInventoryClient, IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
8 8 import { IPolarity, ArtifactPolarity, EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
9 9 import {
10 10 ExportCustoms,
@@ -55,7 +55,7 @@ export const inventoryController: RequestHandler = async (request, response) =>
55 55 const inventoryWithLoadOutPresetsAndShips = await inventoryWithLoadOutPresets.populate<{ Ships: IShipInventory }>(
56 56 "Ships"
57 57 );
58 const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryResponse>();
58 const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryClient>();
59 59
60 60 if (config.infiniteCredits) {
61 61 inventoryResponse.RegularCredits = 999999999;
@@ -147,8 +147,9 @@ export const inventoryController: RequestHandler = async (request, response) =>
147 147 }
148 148
149 149 if (config.unlockAllSkins) {
150 inventoryResponse.WeaponSkins = [];
151 for (const uniqueName in ExportCustoms) {
150 const missingWeaponSkins = new Set(Object.keys(ExportCustoms));
151 inventoryResponse.WeaponSkins.forEach(x => missingWeaponSkins.delete(x.ItemType));
152 for (const uniqueName of missingWeaponSkins) {
152 153 inventoryResponse.WeaponSkins.push({
153 154 ItemId: {
154 155 $oid: "ca70ca70ca70ca70" + catBreadHash(uniqueName).toString(16).padStart(8, "0")
Modified src/controllers/api/upgradesController.ts +2 -2
@@ -6,7 +6,7 @@ import {
6 6 EquipmentFeatures,
7 7 IAbilityOverride
8 8 } from "@/src/types/inventoryTypes/commonInventoryTypes";
9 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
9 import { IInventoryClient, IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
10 10 import { getAccountIdForRequest } from "@/src/services/loginService";
11 11 import { addMiscItems, addRecipes, getInventory, updateCurrency } from "@/src/services/inventoryService";
12 12 import { getRecipeByResult } from "@/src/services/itemDataService";
@@ -62,7 +62,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
62 62 addRecipes(inventory, recipeChanges);
63 63
64 64 inventoryChanges.Recipes = recipeChanges;
65 inventoryChanges.InfestedFoundry = inventory.toJSON().InfestedFoundry;
65 inventoryChanges.InfestedFoundry = inventory.toJSON<IInventoryClient>().InfestedFoundry;
66 66 } else
67 67 switch (operation.UpgradeRequirement) {
68 68 case "/Lotus/Types/Items/MiscItems/OrokinReactor":
Modified src/controllers/custom/getItemListsController.ts +8 -0
@@ -2,6 +2,7 @@ import { RequestHandler } from "express";
2 2 import { getDict, getItemName, getString } from "@/src/services/itemDataService";
3 3 import {
4 4 ExportArcanes,
5 ExportAvionics,
5 6 ExportGear,
6 7 ExportRecipes,
7 8 ExportResources,
@@ -137,6 +138,13 @@ const getItemListsController: RequestHandler = (req, response) => {
137 138 badItems[uniqueName] = true;
138 139 }
139 140 }
141 for (const [uniqueName, upgrade] of Object.entries(ExportAvionics)) {
142 res.mods.push({
143 uniqueName,
144 name: getString(upgrade.name, lang),
145 fusionLimit: upgrade.fusionLimit
146 });
147 }
140 148 for (const [uniqueName, arcane] of Object.entries(ExportArcanes)) {
141 149 res.mods.push({
142 150 uniqueName,
Added src/controllers/custom/importController.ts +27 -0
@@ -0,0 +1,27 @@
1 import { importInventory, importLoadOutPresets } from "@/src/services/importService";
2 import { getInventory } from "@/src/services/inventoryService";
3 import { getLoadout } from "@/src/services/loadoutService";
4 import { getAccountIdForRequest } from "@/src/services/loginService";
5 import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
6 import { RequestHandler } from "express";
7
8 export const importController: RequestHandler = async (req, res) => {
9 const accountId = await getAccountIdForRequest(req);
10 const request = JSON.parse(String(req.body)) as IImportRequest;
11
12 const inventory = await getInventory(accountId);
13 importInventory(inventory, request.inventory);
14 await inventory.save();
15
16 if (request.inventory.LoadOutPresets) {
17 const loadout = await getLoadout(accountId);
18 importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
19 await loadout.save();
20 }
21
22 res.end();
23 };
24
25 interface IImportRequest {
26 inventory: Partial<IInventoryClient>;
27 }
Modified src/models/inventoryModels/inventoryModel.ts +19 -20
@@ -2,11 +2,10 @@ import { Document, Model, Schema, Types, model } from "mongoose";
2 2 import {
3 3 IFlavourItem,
4 4 IRawUpgrade,
5 ICrewShipSalvagedWeaponSkin,
6 5 IMiscItem,
7 6 IInventoryDatabase,
8 7 IBooster,
9 IInventoryResponse,
8 IInventoryClient,
10 9 ISlots,
11 10 IMailbox,
12 11 IDuviriInfo,
@@ -14,7 +13,7 @@ import {
14 13 IPendingRecipeResponse,
15 14 ITypeCount,
16 15 IFocusXP,
17 IFocusUpgrades,
16 IFocusUpgrade,
18 17 ITypeXPItem,
19 18 IChallengeProgress,
20 19 IStepSequencer,
@@ -24,7 +23,7 @@ import {
24 23 ISeasonChallenge,
25 24 IPlayerSkills,
26 25 ISettings,
27 IInfestedFoundry,
26 IInfestedFoundryDatabase,
28 27 IHelminthResource,
29 28 IConsumedSuit,
30 29 IQuestProgress,
@@ -43,7 +42,6 @@ import {
43 42 ICrewShipCustomization,
44 43 ICrewShipWeapon,
45 44 ICrewShipMembersClient,
46 ICrewShip,
47 45 ICrewShipPilotWeapon,
48 46 IShipExterior,
49 47 IHelminthFoodRecord,
@@ -52,7 +50,9 @@ import {
52 50 IDialogueDatabase,
53 51 IDialogueGift,
54 52 ICompletedDialogue,
55 IDialogueClient
53 IDialogueClient,
54 IUpgradeDatabase,
55 ICrewShipDatabase
56 56 } from "../../types/inventoryTypes/inventoryTypes";
57 57 import { IOid } from "../../types/commonTypes";
58 58 import {
@@ -62,7 +62,6 @@ import {
62 62 IOperatorConfigDatabase,
63 63 IPolarity,
64 64 IEquipmentDatabase,
65 IOperatorConfigClient,
66 65 IArchonCrystalUpgrade
67 66 } from "@/src/types/inventoryTypes/commonInventoryTypes";
68 67 import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
@@ -81,7 +80,7 @@ const focusXPSchema = new Schema<IFocusXP>(
81 80 { _id: false }
82 81 );
83 82
84 const focusUpgradesSchema = new Schema<IFocusUpgrades>(
83 const focusUpgradeSchema = new Schema<IFocusUpgrade>(
85 84 {
86 85 ItemType: String,
87 86 Level: Number,
@@ -288,7 +287,7 @@ RawUpgrades.set("toJSON", {
288 287 }
289 288 });
290 289
291 const upgradesSchema = new Schema<ICrewShipSalvagedWeaponSkin>(
290 const upgradeSchema = new Schema<IUpgradeDatabase>(
292 291 {
293 292 UpgradeFingerprint: String,
294 293 PendingRerollFingerprint: { type: String, required: false },
@@ -297,11 +296,11 @@ const upgradesSchema = new Schema<ICrewShipSalvagedWeaponSkin>(
297 296 { id: false }
298 297 );
299 298
300 upgradesSchema.virtual("ItemId").get(function () {
299 upgradeSchema.virtual("ItemId").get(function () {
301 300 return toOid(this._id);
302 301 });
303 302
304 upgradesSchema.set("toJSON", {
303 upgradeSchema.set("toJSON", {
305 304 virtuals: true,
306 305 transform(_document, returnedObject) {
307 306 delete returnedObject._id;
@@ -493,7 +492,7 @@ const helminthResourceSchema = new Schema<IHelminthResource>(
493 492 { _id: false }
494 493 );
495 494
496 const infestedFoundrySchema = new Schema<IInfestedFoundry>(
495 const infestedFoundrySchema = new Schema<IInfestedFoundryDatabase>(
497 496 {
498 497 Name: String,
499 498 Resources: { type: [helminthResourceSchema], default: undefined },
@@ -695,7 +694,7 @@ crewShipMembersSchema.set("toJSON", {
695 694 }
696 695 });
697 696
698 const crewShipSchema = new Schema<ICrewShip>({
697 const crewShipSchema = new Schema<ICrewShipDatabase>({
699 698 ItemType: { type: String, required: true },
700 699 Configs: { type: [ItemConfigSchema], default: [] },
701 700 Weapon: { type: crewShipWeaponSchema, default: undefined },
@@ -837,7 +836,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
837 836 //Curent active like Active school focuses is = "Zenurik"
838 837 FocusAbility: String,
839 838 //The treeways of the Focus school.(Active and passive Ability)
840 FocusUpgrades: [focusUpgradesSchema],
839 FocusUpgrades: [focusUpgradeSchema],
841 840
842 841 //Achievement
843 842 ChallengeProgress: [challengeProgressSchema],
@@ -848,7 +847,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
848 847 //Non Upgrade Mods Example:I have 999 item WeaponElectricityDamageMod (only "ItemCount"+"ItemType")
849 848 RawUpgrades: [RawUpgrades],
850 849 //Upgrade Mods\Riven\Arcane Example:"UpgradeFingerprint"+"ItemType"+""
851 Upgrades: [upgradesSchema],
850 Upgrades: [upgradeSchema],
852 851
853 852 //Warframe
854 853 Suits: [EquipmentSchema],
@@ -1142,7 +1141,7 @@ inventorySchema.set("toJSON", {
1142 1141 delete returnedObject.accountOwnerId;
1143 1142
1144 1143 const inventoryDatabase = returnedObject as IInventoryDatabase;
1145 const inventoryResponse = returnedObject as IInventoryResponse;
1144 const inventoryResponse = returnedObject as IInventoryClient;
1146 1145
1147 1146 inventoryResponse.TrainingDate = toMongoDate(inventoryDatabase.TrainingDate);
1148 1147 inventoryResponse.Created = toMongoDate(inventoryDatabase.Created);
@@ -1164,12 +1163,12 @@ type InventoryDocumentProps = {
1164 1163 OperatorAmps: Types.DocumentArray<IEquipmentDatabase>;
1165 1164 FlavourItems: Types.DocumentArray<IFlavourItem>;
1166 1165 RawUpgrades: Types.DocumentArray<IRawUpgrade>;
1167 Upgrades: Types.DocumentArray<ICrewShipSalvagedWeaponSkin>;
1166 Upgrades: Types.DocumentArray<IUpgradeDatabase>;
1168 1167 MiscItems: Types.DocumentArray<IMiscItem>;
1169 1168 Boosters: Types.DocumentArray<IBooster>;
1170 OperatorLoadOuts: Types.DocumentArray<IOperatorConfigClient>;
1169 OperatorLoadOuts: Types.DocumentArray<IOperatorConfigDatabase>;
1171 1170 SpecialItems: Types.DocumentArray<IEquipmentDatabase>;
1172 AdultOperatorLoadOuts: Types.DocumentArray<IOperatorConfigClient>; //TODO: this should still contain _id
1171 AdultOperatorLoadOuts: Types.DocumentArray<IOperatorConfigDatabase>;
1173 1172 MechSuits: Types.DocumentArray<IEquipmentDatabase>;
1174 1173 Scoops: Types.DocumentArray<IEquipmentDatabase>;
1175 1174 DataKnives: Types.DocumentArray<IEquipmentDatabase>;
@@ -1185,7 +1184,7 @@ type InventoryDocumentProps = {
1185 1184 Hoverboards: Types.DocumentArray<IEquipmentDatabase>;
1186 1185 MoaPets: Types.DocumentArray<IEquipmentDatabase>;
1187 1186 WeaponSkins: Types.DocumentArray<IWeaponSkinDatabase>;
1188 CrewShips: Types.DocumentArray<ICrewShip>;
1187 CrewShips: Types.DocumentArray<ICrewShipDatabase>;
1189 1188 CrewShipHarnesses: Types.DocumentArray<IEquipmentDatabase>;
1190 1189 };
1191 1190
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 { importController } from "@/src/controllers/custom/importController";
12 13
13 14 import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
14 15 import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
@@ -24,6 +25,7 @@ customRouter.get("/renameAccount", renameAccountController);
24 25
25 26 customRouter.post("/createAccount", createAccountController);
26 27 customRouter.post("/addItems", addItemsController);
28 customRouter.post("/import", importController);
27 29
28 30 customRouter.get("/config", getConfigDataController);
29 31 customRouter.post("/config", updateConfigDataController);
Modified src/routes/webui.ts +3 -0
@@ -34,6 +34,9 @@ webuiRouter.get("/webui/settings", (_req, res) => {
34 34 webuiRouter.get("/webui/cheats", (_req, res) => {
35 35 res.sendFile(path.join(rootDir, "static/webui/index.html"));
36 36 });
37 webuiRouter.get("/webui/import", (_req, res) => {
38 res.sendFile(path.join(rootDir, "static/webui/index.html"));
39 });
37 40
38 41 // Serve static files
39 42 webuiRouter.use("/webui", express.static(path.join(rootDir, "static/webui")));
Added src/services/importService.ts +247 -0
@@ -0,0 +1,247 @@
1 import { Types } from "mongoose";
2 import {
3 IEquipmentClient,
4 IEquipmentDatabase,
5 IOperatorConfigClient,
6 IOperatorConfigDatabase
7 } from "../types/inventoryTypes/commonInventoryTypes";
8 import { IMongoDate } from "../types/commonTypes";
9 import {
10 equipmentKeys,
11 ICrewShipClient,
12 ICrewShipDatabase,
13 ICrewShipMembersClient,
14 ICrewShipMembersDatabase,
15 IDialogueClient,
16 IDialogueDatabase,
17 IDialogueHistoryClient,
18 IDialogueHistoryDatabase,
19 IInfestedFoundryClient,
20 IInfestedFoundryDatabase,
21 IInventoryClient,
22 ILoadoutConfigClient,
23 ILoadOutPresets,
24 ISlots,
25 IUpgradeClient,
26 IUpgradeDatabase,
27 IWeaponSkinClient,
28 IWeaponSkinDatabase
29 } from "../types/inventoryTypes/inventoryTypes";
30 import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
31 import { ILoadoutConfigDatabase, ILoadoutDatabase } from "../types/saveLoadoutTypes";
32
33 const convertDate = (value: IMongoDate): Date => {
34 return new Date(parseInt(value.$date.$numberLong));
35 };
36
37 const convertOptionalDate = (value: IMongoDate | undefined): Date | undefined => {
38 return value ? convertDate(value) : undefined;
39 };
40
41 const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
42 const { ItemId, ...rest } = client;
43 return {
44 ...rest,
45 _id: new Types.ObjectId(ItemId.$oid),
46 InfestationDate: convertOptionalDate(client.InfestationDate),
47 Expiry: convertOptionalDate(client.Expiry),
48 UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry)
49 };
50 };
51
52 const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
53 const { ItemId, ...rest } = client;
54 return {
55 ...rest,
56 _id: new Types.ObjectId(ItemId.$oid)
57 };
58 };
59
60 const convertUpgrade = (client: IUpgradeClient): IUpgradeDatabase => {
61 const { ItemId, ...rest } = client;
62 return {
63 ...rest,
64 _id: new Types.ObjectId(ItemId.$oid)
65 };
66 };
67
68 const convertOperatorConfig = (client: IOperatorConfigClient): IOperatorConfigDatabase => {
69 const { ItemId, ...rest } = client;
70 return {
71 ...rest,
72 _id: new Types.ObjectId(ItemId.$oid)
73 };
74 };
75
76 const replaceArray = <T>(arr: T[], replacement: T[]): void => {
77 arr.splice(0, arr.length);
78 replacement.forEach(x => {
79 arr.push(x);
80 });
81 };
82
83 const replaceSlots = (db: ISlots, client: ISlots): void => {
84 db.Extra = client.Extra;
85 db.Slots = client.Slots;
86 };
87
88 const convertCrewShipMembers = (client: ICrewShipMembersClient): ICrewShipMembersDatabase => {
89 return {
90 SLOT_A: client.SLOT_A ? new Types.ObjectId(client.SLOT_A.ItemId.$oid) : undefined,
91 SLOT_B: client.SLOT_B ? new Types.ObjectId(client.SLOT_B.ItemId.$oid) : undefined,
92 SLOT_C: client.SLOT_C ? new Types.ObjectId(client.SLOT_C.ItemId.$oid) : undefined
93 };
94 };
95
96 const convertCrewShip = (client: ICrewShipClient): ICrewShipDatabase => {
97 const { ItemId, ...rest } = client;
98 return {
99 ...rest,
100 _id: new Types.ObjectId(ItemId.$oid),
101 CrewMembers: client.CrewMembers ? convertCrewShipMembers(client.CrewMembers) : undefined
102 };
103 };
104
105 const convertInfestedFoundry = (client: IInfestedFoundryClient): IInfestedFoundryDatabase => {
106 return {
107 ...client,
108 LastConsumedSuit: client.LastConsumedSuit ? convertEquipment(client.LastConsumedSuit) : undefined,
109 AbilityOverrideUnlockCooldown: convertOptionalDate(client.AbilityOverrideUnlockCooldown)
110 };
111 };
112
113 const convertDialogue = (client: IDialogueClient): IDialogueDatabase => {
114 return {
115 ...client,
116 AvailableDate: convertDate(client.AvailableDate),
117 AvailableGiftDate: convertDate(client.AvailableGiftDate),
118 RankUpExpiry: convertDate(client.RankUpExpiry),
119 BountyChemExpiry: convertDate(client.BountyChemExpiry)
120 };
121 };
122
123 const convertDialogueHistory = (client: IDialogueHistoryClient): IDialogueHistoryDatabase => {
124 return {
125 YearIteration: client.YearIteration,
126 Dialogues: client.Dialogues ? client.Dialogues.map(convertDialogue) : undefined
127 };
128 };
129
130 export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
131 for (const key of equipmentKeys) {
132 if (client[key]) {
133 replaceArray<IEquipmentDatabase>(db[key], client[key].map(convertEquipment));
134 }
135 }
136 if (client.WeaponSkins) {
137 replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
138 }
139 if (client.Upgrades) {
140 replaceArray<IUpgradeDatabase>(db.Upgrades, client.Upgrades.map(convertUpgrade));
141 }
142 for (const key of ["RawUpgrades", "MiscItems"] as const) {
143 if (client[key]) {
144 db[key].splice(0, db[key].length);
145 client[key].forEach(x => {
146 db[key].push({
147 ItemType: x.ItemType,
148 ItemCount: x.ItemCount
149 });
150 });
151 }
152 }
153 for (const key of ["OperatorLoadOuts", "AdultOperatorLoadOuts"] as const) {
154 if (client[key]) {
155 replaceArray<IOperatorConfigDatabase>(db[key], client[key].map(convertOperatorConfig));
156 }
157 }
158 for (const key of [
159 "SuitBin",
160 "WeaponBin",
161 "SentinelBin",
162 "SpaceSuitBin",
163 "SpaceWeaponBin",
164 "PvpBonusLoadoutBin",
165 "PveBonusLoadoutBin",
166 "RandomModBin",
167 "MechBin",
168 "CrewMemberBin",
169 "OperatorAmpBin",
170 "CrewShipSalvageBin"
171 ] as const) {
172 if (client[key]) {
173 replaceSlots(db[key], client[key]);
174 }
175 }
176 if (client.UseAdultOperatorLoadout) {
177 db.UseAdultOperatorLoadout = client.UseAdultOperatorLoadout;
178 }
179 for (const key of [
180 "PlayerLevel",
181 "RegularCredits",
182 "PremiumCredits",
183 "PremiumCreditsFree",
184 "FusionPoints",
185 "PrimeTokens"
186 ] as const) {
187 if (client[key]) {
188 db[key] = client[key];
189 }
190 }
191 for (const key of ["ThemeStyle", "ThemeBackground", "ThemeSounds", "EquippedInstrument", "FocusAbility"] as const) {
192 if (client[key]) {
193 db[key] = client[key];
194 }
195 }
196 for (const key of ["EquippedGear", "EquippedEmotes", "NodeIntrosCompleted"] as const) {
197 if (client[key]) {
198 db[key] = client[key];
199 }
200 }
201 if (client.XPInfo) {
202 db.XPInfo = client.XPInfo;
203 }
204 if (client.CurrentLoadOutIds) {
205 db.CurrentLoadOutIds = client.CurrentLoadOutIds;
206 }
207 if (client.Affiliations) {
208 db.Affiliations = client.Affiliations;
209 }
210 if (client.FusionTreasures) {
211 db.FusionTreasures = client.FusionTreasures;
212 }
213 if (client.FocusUpgrades) {
214 db.FocusUpgrades = client.FocusUpgrades;
215 }
216 if (client.CrewShips) {
217 replaceArray<ICrewShipDatabase>(db.CrewShips, client.CrewShips.map(convertCrewShip));
218 }
219 if (client.InfestedFoundry) {
220 db.InfestedFoundry = convertInfestedFoundry(client.InfestedFoundry);
221 }
222 if (client.DialogueHistory) {
223 db.DialogueHistory = convertDialogueHistory(client.DialogueHistory);
224 }
225 };
226
227 const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
228 const { ItemId, ...rest } = client;
229 return {
230 ...rest,
231 _id: new Types.ObjectId(ItemId.$oid)
232 };
233 };
234
235 export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPresets): void => {
236 db.NORMAL = client.NORMAL.map(convertLoadOutConfig);
237 db.SENTINEL = client.SENTINEL.map(convertLoadOutConfig);
238 db.ARCHWING = client.ARCHWING.map(convertLoadOutConfig);
239 db.NORMAL_PVP = client.NORMAL_PVP.map(convertLoadOutConfig);
240 db.LUNARO = client.LUNARO.map(convertLoadOutConfig);
241 db.OPERATOR = client.OPERATOR.map(convertLoadOutConfig);
242 db.KDRIVE = client.KDRIVE.map(convertLoadOutConfig);
243 db.DATAKNIFE = client.DATAKNIFE.map(convertLoadOutConfig);
244 db.MECH = client.MECH.map(convertLoadOutConfig);
245 db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
246 db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
247 };
Modified src/types/inventoryTypes/commonInventoryTypes.ts +6 -3
Modified src/types/inventoryTypes/inventoryTypes.ts +79 -36
Modified src/types/purchaseTypes.ts +3 -3
Modified src/types/saveLoadoutTypes.ts +12 -11
Modified static/webui/index.html +8 -0
Modified static/webui/script.js +21 -1