god TS sucks.
This commit is contained in:
parent
5101366ff2
commit
8df3030953
@ -3,45 +3,83 @@ import { RequestHandler } from "express";
|
|||||||
import util from "util";
|
import util from "util";
|
||||||
import {
|
import {
|
||||||
EquipmentCategories,
|
EquipmentCategories,
|
||||||
ISaveLoadoutEntry,
|
IConfigEntry,
|
||||||
ISaveLoadoutLoadoutEntry,
|
ILoadout,
|
||||||
ISaveLoadoutRequest
|
ISaveLoadoutRequest,
|
||||||
|
ISaveLoadoutRequestNoUpgradeVer
|
||||||
} from "@/src/types/saveLoadoutTypes";
|
} from "@/src/types/saveLoadoutTypes";
|
||||||
import { isObject } from "@/src/helpers/general";
|
|
||||||
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
|
|
||||||
|
|
||||||
export const isObjectEmpty = (obj: Record<string, unknown>) => {
|
export const isObjectEmpty = (obj: Record<string, unknown>) => {
|
||||||
return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
|
return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
|
||||||
};
|
};
|
||||||
|
|
||||||
type EquipmentChangeEntry = number | ISaveLoadoutEntry | ISaveLoadoutLoadoutEntry;
|
type EquipmentChangeEntry = IConfigEntry | ILoadout;
|
||||||
|
|
||||||
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequest) => {
|
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequestNoUpgradeVer) => {
|
||||||
for (const [equipmentName, eqp] of Object.entries(equipmentChanges)) {
|
for (const [_equipmentName, _equipment] of Object.entries(equipmentChanges)) {
|
||||||
const equipment = eqp as EquipmentChangeEntry;
|
const equipment = _equipment as ISaveLoadoutRequestNoUpgradeVer[keyof ISaveLoadoutRequestNoUpgradeVer];
|
||||||
//console.log(equipmentName);
|
const equipmentName = _equipmentName as keyof ISaveLoadoutRequestNoUpgradeVer;
|
||||||
if (!isObjectEmpty(equipment)) {
|
|
||||||
// non-empty is a change in loadout(or suit...)
|
|
||||||
|
|
||||||
switch (equipmentName) {
|
if (isObjectEmpty(equipment)) {
|
||||||
case "LoadOuts": {
|
continue;
|
||||||
console.log("loadout received");
|
|
||||||
for (const [loadoutName, loadout] of Object.entries(equipment)) {
|
|
||||||
console.log(loadoutName, loadout);
|
|
||||||
//if (!isObjectEmpty(loadout))
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
console.log("category not implemented", equipmentName);
|
|
||||||
}
|
|
||||||
// Object.keys(value).forEach(element => {
|
|
||||||
// console.log("name of inner objects keys", element);
|
|
||||||
// });
|
|
||||||
// for (const innerValue of Object.values(value)) {
|
|
||||||
// console.log(innerValue);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
// non-empty is a change in loadout(or suit...)
|
||||||
|
|
||||||
|
switch (equipmentName) {
|
||||||
|
case "LoadOuts": {
|
||||||
|
console.log("loadout received");
|
||||||
|
const _loadout = equipment as unknown as ILoadout;
|
||||||
|
|
||||||
|
for (const [loadoutName, loadout] of Object.entries(_loadout)) {
|
||||||
|
console.log(loadoutName, loadout);
|
||||||
|
//const loadout = _loadout as ILoadoutEntry;
|
||||||
|
|
||||||
|
// console.log(loadoutName, loadout);
|
||||||
|
// if (isObjectEmpty(loadout)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "LongGuns": {
|
||||||
|
const longGun = equipment as IConfigEntry;
|
||||||
|
// longGun["key"].PvpUpgrades;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "OperatorAmps":
|
||||||
|
case "Pistols":
|
||||||
|
case "Suits":
|
||||||
|
case "Melee":
|
||||||
|
case "Sentinels":
|
||||||
|
case "SentinelWeapons":
|
||||||
|
case "KubrowPets":
|
||||||
|
case "SpaceSuits":
|
||||||
|
case "SpaceGuns":
|
||||||
|
case "SpaceMelee":
|
||||||
|
case "Scoops":
|
||||||
|
case "SpecialItems":
|
||||||
|
case "MoaPets":
|
||||||
|
case "Hoverboards":
|
||||||
|
case "DataKnives":
|
||||||
|
case "MechSuits":
|
||||||
|
case "CrewShipHarnesses":
|
||||||
|
case "Horses":
|
||||||
|
case "DrifterMelee":
|
||||||
|
case "OperatorLoadOuts":
|
||||||
|
case "AdultOperatorLoadOuts":
|
||||||
|
case "KahlLoadOuts":
|
||||||
|
case "CrewShips":
|
||||||
|
|
||||||
|
default: {
|
||||||
|
console.log("category not implemented", equipmentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Object.keys(value).forEach(element => {
|
||||||
|
// console.log("name of inner objects keys", element);
|
||||||
|
// });
|
||||||
|
// for (const innerValue of Object.values(value)) {
|
||||||
|
// console.log(innerValue);
|
||||||
|
// }
|
||||||
|
|
||||||
// console.log(innerObjects);
|
// console.log(innerObjects);
|
||||||
// if (isObjectEmpty(innerObjects)) {
|
// if (isObjectEmpty(innerObjects)) {
|
||||||
@ -57,7 +95,7 @@ const saveLoadoutController: RequestHandler = async (req, res) => {
|
|||||||
// console.log(util.inspect(body, { showHidden: false, depth: null, colors: true }));
|
// console.log(util.inspect(body, { showHidden: false, depth: null, colors: true }));
|
||||||
|
|
||||||
const { UpgradeVer, ...equipmentChanges } = body;
|
const { UpgradeVer, ...equipmentChanges } = body;
|
||||||
handleInventoryItemConfigChange(body);
|
handleInventoryItemConfigChange(equipmentChanges);
|
||||||
|
|
||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
};
|
};
|
||||||
|
@ -1,37 +1,72 @@
|
|||||||
|
import { IOid } from "@/src/types/commonTypes";
|
||||||
|
|
||||||
export interface ISaveLoadoutRequest {
|
export interface ISaveLoadoutRequest {
|
||||||
LoadOuts: ISaveLoadoutLoadoutEntry;
|
LoadOuts: ILoadout;
|
||||||
LongGuns: ISaveLoadoutEntry;
|
LongGuns: IConfigEntry;
|
||||||
OperatorAmps: ISaveLoadoutEntry;
|
OperatorAmps: IConfigEntry;
|
||||||
Pistols: ISaveLoadoutEntry;
|
Pistols: IConfigEntry;
|
||||||
Suits: ISaveLoadoutEntry;
|
Suits: IConfigEntry;
|
||||||
Melee: ISaveLoadoutEntry;
|
Melee: IConfigEntry;
|
||||||
Sentinels: ISaveLoadoutEntry;
|
Sentinels: IConfigEntry;
|
||||||
SentinelWeapons: ISaveLoadoutEntry;
|
SentinelWeapons: IConfigEntry;
|
||||||
KubrowPets: ISaveLoadoutEntry;
|
KubrowPets: IConfigEntry;
|
||||||
SpaceSuits: ISaveLoadoutEntry;
|
SpaceSuits: IConfigEntry;
|
||||||
SpaceGuns: ISaveLoadoutEntry;
|
SpaceGuns: IConfigEntry;
|
||||||
SpaceMelee: ISaveLoadoutEntry;
|
SpaceMelee: IConfigEntry;
|
||||||
Scoops: ISaveLoadoutEntry;
|
Scoops: IConfigEntry;
|
||||||
SpecialItems: ISaveLoadoutEntry;
|
SpecialItems: IConfigEntry;
|
||||||
MoaPets: ISaveLoadoutEntry;
|
MoaPets: IConfigEntry;
|
||||||
Hoverboards: ISaveLoadoutEntry;
|
Hoverboards: IConfigEntry;
|
||||||
DataKnives: ISaveLoadoutEntry;
|
DataKnives: IConfigEntry;
|
||||||
MechSuits: ISaveLoadoutEntry;
|
MechSuits: IConfigEntry;
|
||||||
CrewShipHarnesses: ISaveLoadoutEntry;
|
CrewShipHarnesses: IConfigEntry;
|
||||||
Horses: ISaveLoadoutEntry;
|
Horses: IConfigEntry;
|
||||||
DrifterMelee: ISaveLoadoutEntry;
|
DrifterMelee: IConfigEntry;
|
||||||
UpgradeVer: number;
|
UpgradeVer: number;
|
||||||
OperatorLoadOuts: ISaveLoadoutEntry;
|
OperatorLoadOuts: IConfigEntry;
|
||||||
AdultOperatorLoadOuts: ISaveLoadoutEntry;
|
AdultOperatorLoadOuts: IConfigEntry;
|
||||||
KahlLoadOuts: ISaveLoadoutEntry;
|
KahlLoadOuts: IConfigEntry;
|
||||||
CrewShips: ISaveLoadoutEntry;
|
CrewShips: IConfigEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaveLoadoutEntry {
|
export interface ISaveLoadoutRequestNoUpgradeVer extends Omit<ISaveLoadoutRequest, "UpgradeVer"> {}
|
||||||
|
|
||||||
|
export interface IConfigEntry {
|
||||||
[key: string]: Config;
|
[key: string]: Config;
|
||||||
}
|
}
|
||||||
export interface ISaveLoadoutLoadoutEntry {
|
|
||||||
[key: string]: LoadOut;
|
export interface ILoadout {
|
||||||
|
NORMAL: ILoadoutKey;
|
||||||
|
SENTINEL: ILoadoutKey;
|
||||||
|
ARCHWING: ILoadoutKey;
|
||||||
|
NORMAL_PVP: ILoadoutKey;
|
||||||
|
LUNARO: ILoadoutKey;
|
||||||
|
OPERATOR: ILoadoutKey;
|
||||||
|
KDRIVE: ILoadoutKey;
|
||||||
|
DATAKNIFE: ILoadoutKey;
|
||||||
|
MECH: ILoadoutKey;
|
||||||
|
OPERATOR_ADULT: ILoadoutKey;
|
||||||
|
DRIFTER: ILoadoutKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ILoadoutKey {
|
||||||
|
[key: string]: ItemConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ItemConfig {
|
||||||
|
ItemId: IOid;
|
||||||
|
PresetIcon: string;
|
||||||
|
Favorite: boolean;
|
||||||
|
s: M;
|
||||||
|
p: M;
|
||||||
|
l: M;
|
||||||
|
m: M;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface M {
|
||||||
|
ItemId: IOid;
|
||||||
|
mod: number;
|
||||||
|
cus: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
@ -76,36 +111,8 @@ export interface Col {
|
|||||||
e1?: number;
|
e1?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoadOuts {
|
|
||||||
NORMAL: LoadOut;
|
|
||||||
SENTINEL: LoadOut;
|
|
||||||
ARCHWING: LoadOut;
|
|
||||||
NORMAL_PVP: LoadOut;
|
|
||||||
LUNARO: LoadOut;
|
|
||||||
OPERATOR: LoadOut;
|
|
||||||
KDRIVE: LoadOut;
|
|
||||||
DATAKNIFE: LoadOut;
|
|
||||||
MECH: LoadOut;
|
|
||||||
OPERATOR_ADULT: LoadOut;
|
|
||||||
DRIFTER: LoadOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
type LoadOut = {
|
|
||||||
Upgrades: Config[];
|
|
||||||
PvpUpgrades: Config[];
|
|
||||||
Skins: string[];
|
|
||||||
pricol: { [key: string]: number };
|
|
||||||
attcol: Config;
|
|
||||||
sigcol: Config;
|
|
||||||
eyecol: Config;
|
|
||||||
facial: Config;
|
|
||||||
cloth: Config;
|
|
||||||
syancol: Config;
|
|
||||||
Songs: Config[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type EquipmentCategories =
|
export type EquipmentCategories =
|
||||||
| { LoadOuts: { [key in keyof LoadOuts]: LoadOut } }
|
| { LoadOuts: { [key in keyof ILoadout]: LoadOut } }
|
||||||
| { LongGuns: Config }
|
| { LongGuns: Config }
|
||||||
| { OperatorAmps: Config } // Replace 'any' with the actual type
|
| { OperatorAmps: Config } // Replace 'any' with the actual type
|
||||||
| { Pistols: Config } // Replace 'any' with the actual type
|
| { Pistols: Config } // Replace 'any' with the actual type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user