import loadout presets
This commit is contained in:
parent
9c5310e418
commit
af065c5928
@ -1,15 +1,24 @@
|
|||||||
import { importInventory } from "@/src/services/importService";
|
import { importInventory, importLoadOutPresets } from "@/src/services/importService";
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
|
import { getLoadout } from "@/src/services/loadoutService";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
export const importController: RequestHandler = async (req, res) => {
|
export const importController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
const request = JSON.parse(String(req.body)) as IImportRequest;
|
const request = JSON.parse(String(req.body)) as IImportRequest;
|
||||||
|
|
||||||
|
const inventory = await getInventory(accountId);
|
||||||
importInventory(inventory, request.inventory);
|
importInventory(inventory, request.inventory);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|
||||||
|
if (request.inventory.LoadOutPresets) {
|
||||||
|
const loadout = await getLoadout(accountId);
|
||||||
|
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
|
||||||
|
await loadout.save();
|
||||||
|
}
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ import { IMongoDate } from "../types/commonTypes";
|
|||||||
import {
|
import {
|
||||||
equipmentKeys,
|
equipmentKeys,
|
||||||
IInventoryClient,
|
IInventoryClient,
|
||||||
|
ILoadoutConfigClient,
|
||||||
|
ILoadOutPresets,
|
||||||
ISlots,
|
ISlots,
|
||||||
IUpgradeClient,
|
IUpgradeClient,
|
||||||
IUpgradeDatabase,
|
IUpgradeDatabase,
|
||||||
@ -16,6 +18,7 @@ import {
|
|||||||
IWeaponSkinDatabase
|
IWeaponSkinDatabase
|
||||||
} from "../types/inventoryTypes/inventoryTypes";
|
} from "../types/inventoryTypes/inventoryTypes";
|
||||||
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
||||||
|
import { ILoadoutConfigDatabase, ILoadoutDatabase } from "../types/saveLoadoutTypes";
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
@ -137,3 +140,25 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
|
||||||
|
const { ItemId, ...rest } = client;
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
_id: new Types.ObjectId(client.ItemId.$oid)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPresets): void => {
|
||||||
|
db.NORMAL = client.NORMAL.map(convertLoadOutConfig);
|
||||||
|
db.SENTINEL = client.SENTINEL.map(convertLoadOutConfig);
|
||||||
|
db.ARCHWING = client.ARCHWING.map(convertLoadOutConfig);
|
||||||
|
db.NORMAL_PVP = client.NORMAL_PVP.map(convertLoadOutConfig);
|
||||||
|
db.LUNARO = client.LUNARO.map(convertLoadOutConfig);
|
||||||
|
db.OPERATOR = client.OPERATOR.map(convertLoadOutConfig);
|
||||||
|
db.KDRIVE = client.KDRIVE.map(convertLoadOutConfig);
|
||||||
|
db.DATAKNIFE = client.DATAKNIFE.map(convertLoadOutConfig);
|
||||||
|
db.MECH = client.MECH.map(convertLoadOutConfig);
|
||||||
|
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
|
||||||
|
db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
|
||||||
|
};
|
||||||
|
@ -210,7 +210,7 @@ export interface IInventoryClient extends IDailyAffiliations {
|
|||||||
Scoops: IEquipmentDatabase[];
|
Scoops: IEquipmentDatabase[];
|
||||||
TrainingRetriesLeft: number;
|
TrainingRetriesLeft: number;
|
||||||
LoadOutPresets: ILoadOutPresets;
|
LoadOutPresets: ILoadOutPresets;
|
||||||
CurrentLoadOutIds: Array<any[] | IOid>;
|
CurrentLoadOutIds: IOid[]; // we store it in the database using this representation as well :/
|
||||||
Missions: IMission[];
|
Missions: IMission[];
|
||||||
RandomUpgradesIdentified?: number;
|
RandomUpgradesIdentified?: number;
|
||||||
LastRegionPlayed: TSolarMapRegion;
|
LastRegionPlayed: TSolarMapRegion;
|
||||||
@ -667,7 +667,7 @@ export interface ILibraryPersonalProgress {
|
|||||||
Completed: boolean;
|
Completed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this needs to be checked against ILoadoutDatabase
|
// keep in sync with ILoadoutDatabase
|
||||||
export interface ILoadOutPresets {
|
export interface ILoadOutPresets {
|
||||||
NORMAL: ILoadoutConfigClient[];
|
NORMAL: ILoadoutConfigClient[];
|
||||||
NORMAL_PVP: ILoadoutConfigClient[];
|
NORMAL_PVP: ILoadoutConfigClient[];
|
||||||
@ -680,6 +680,7 @@ export interface ILoadOutPresets {
|
|||||||
DATAKNIFE: ILoadoutConfigClient[];
|
DATAKNIFE: ILoadoutConfigClient[];
|
||||||
MECH: ILoadoutConfigClient[];
|
MECH: ILoadoutConfigClient[];
|
||||||
OPERATOR_ADULT: ILoadoutConfigClient[];
|
OPERATOR_ADULT: ILoadoutConfigClient[];
|
||||||
|
DRIFTER: ILoadoutConfigClient[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum FocusSchool {
|
export enum FocusSchool {
|
||||||
|
@ -54,18 +54,19 @@ export interface IConfigEntry {
|
|||||||
|
|
||||||
export interface ILoadoutClient extends Omit<ILoadoutDatabase, "_id" | "loadoutOwnerId"> {}
|
export interface ILoadoutClient extends Omit<ILoadoutDatabase, "_id" | "loadoutOwnerId"> {}
|
||||||
|
|
||||||
|
// keep in sync with ILoadOutPresets
|
||||||
export interface ILoadoutDatabase {
|
export interface ILoadoutDatabase {
|
||||||
NORMAL: ILoadoutEntry;
|
NORMAL: ILoadoutConfigDatabase[];
|
||||||
SENTINEL: ILoadoutEntry;
|
SENTINEL: ILoadoutConfigDatabase[];
|
||||||
ARCHWING: ILoadoutEntry;
|
ARCHWING: ILoadoutConfigDatabase[];
|
||||||
NORMAL_PVP: ILoadoutEntry;
|
NORMAL_PVP: ILoadoutConfigDatabase[];
|
||||||
LUNARO: ILoadoutEntry;
|
LUNARO: ILoadoutConfigDatabase[];
|
||||||
OPERATOR: ILoadoutEntry;
|
OPERATOR: ILoadoutConfigDatabase[];
|
||||||
KDRIVE: ILoadoutEntry;
|
KDRIVE: ILoadoutConfigDatabase[];
|
||||||
DATAKNIFE: ILoadoutEntry;
|
DATAKNIFE: ILoadoutConfigDatabase[];
|
||||||
MECH: ILoadoutEntry;
|
MECH: ILoadoutConfigDatabase[];
|
||||||
OPERATOR_ADULT: ILoadoutEntry;
|
OPERATOR_ADULT: ILoadoutConfigDatabase[];
|
||||||
DRIFTER: ILoadoutEntry;
|
DRIFTER: ILoadoutConfigDatabase[];
|
||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
loadoutOwnerId: Types.ObjectId;
|
loadoutOwnerId: Types.ObjectId;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user