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 {
|
||||
EquipmentCategories,
|
||||
ISaveLoadoutEntry,
|
||||
ISaveLoadoutLoadoutEntry,
|
||||
ISaveLoadoutRequest
|
||||
IConfigEntry,
|
||||
ILoadout,
|
||||
ISaveLoadoutRequest,
|
||||
ISaveLoadoutRequestNoUpgradeVer
|
||||
} from "@/src/types/saveLoadoutTypes";
|
||||
import { isObject } from "@/src/helpers/general";
|
||||
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
|
||||
|
||||
export const isObjectEmpty = (obj: Record<string, unknown>) => {
|
||||
return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
|
||||
};
|
||||
|
||||
type EquipmentChangeEntry = number | ISaveLoadoutEntry | ISaveLoadoutLoadoutEntry;
|
||||
type EquipmentChangeEntry = IConfigEntry | ILoadout;
|
||||
|
||||
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequest) => {
|
||||
for (const [equipmentName, eqp] of Object.entries(equipmentChanges)) {
|
||||
const equipment = eqp as EquipmentChangeEntry;
|
||||
//console.log(equipmentName);
|
||||
if (!isObjectEmpty(equipment)) {
|
||||
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequestNoUpgradeVer) => {
|
||||
for (const [_equipmentName, _equipment] of Object.entries(equipmentChanges)) {
|
||||
const equipment = _equipment as ISaveLoadoutRequestNoUpgradeVer[keyof ISaveLoadoutRequestNoUpgradeVer];
|
||||
const equipmentName = _equipmentName as keyof ISaveLoadoutRequestNoUpgradeVer;
|
||||
|
||||
if (isObjectEmpty(equipment)) {
|
||||
continue;
|
||||
}
|
||||
// non-empty is a change in loadout(or suit...)
|
||||
|
||||
switch (equipmentName) {
|
||||
case "LoadOuts": {
|
||||
console.log("loadout received");
|
||||
for (const [loadoutName, loadout] of Object.entries(equipment)) {
|
||||
const _loadout = equipment as unknown as ILoadout;
|
||||
|
||||
for (const [loadoutName, loadout] of Object.entries(_loadout)) {
|
||||
console.log(loadoutName, loadout);
|
||||
//if (!isObjectEmpty(loadout))
|
||||
//const loadout = _loadout as ILoadoutEntry;
|
||||
|
||||
// console.log(loadoutName, loadout);
|
||||
// if (isObjectEmpty(loadout)) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
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);
|
||||
// if (isObjectEmpty(innerObjects)) {
|
||||
@ -57,7 +95,7 @@ const saveLoadoutController: RequestHandler = async (req, res) => {
|
||||
// console.log(util.inspect(body, { showHidden: false, depth: null, colors: true }));
|
||||
|
||||
const { UpgradeVer, ...equipmentChanges } = body;
|
||||
handleInventoryItemConfigChange(body);
|
||||
handleInventoryItemConfigChange(equipmentChanges);
|
||||
|
||||
res.status(200).end();
|
||||
};
|
||||
|
@ -1,37 +1,72 @@
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
|
||||
export interface ISaveLoadoutRequest {
|
||||
LoadOuts: ISaveLoadoutLoadoutEntry;
|
||||
LongGuns: ISaveLoadoutEntry;
|
||||
OperatorAmps: ISaveLoadoutEntry;
|
||||
Pistols: ISaveLoadoutEntry;
|
||||
Suits: ISaveLoadoutEntry;
|
||||
Melee: ISaveLoadoutEntry;
|
||||
Sentinels: ISaveLoadoutEntry;
|
||||
SentinelWeapons: ISaveLoadoutEntry;
|
||||
KubrowPets: ISaveLoadoutEntry;
|
||||
SpaceSuits: ISaveLoadoutEntry;
|
||||
SpaceGuns: ISaveLoadoutEntry;
|
||||
SpaceMelee: ISaveLoadoutEntry;
|
||||
Scoops: ISaveLoadoutEntry;
|
||||
SpecialItems: ISaveLoadoutEntry;
|
||||
MoaPets: ISaveLoadoutEntry;
|
||||
Hoverboards: ISaveLoadoutEntry;
|
||||
DataKnives: ISaveLoadoutEntry;
|
||||
MechSuits: ISaveLoadoutEntry;
|
||||
CrewShipHarnesses: ISaveLoadoutEntry;
|
||||
Horses: ISaveLoadoutEntry;
|
||||
DrifterMelee: ISaveLoadoutEntry;
|
||||
LoadOuts: ILoadout;
|
||||
LongGuns: IConfigEntry;
|
||||
OperatorAmps: IConfigEntry;
|
||||
Pistols: IConfigEntry;
|
||||
Suits: IConfigEntry;
|
||||
Melee: IConfigEntry;
|
||||
Sentinels: IConfigEntry;
|
||||
SentinelWeapons: IConfigEntry;
|
||||
KubrowPets: IConfigEntry;
|
||||
SpaceSuits: IConfigEntry;
|
||||
SpaceGuns: IConfigEntry;
|
||||
SpaceMelee: IConfigEntry;
|
||||
Scoops: IConfigEntry;
|
||||
SpecialItems: IConfigEntry;
|
||||
MoaPets: IConfigEntry;
|
||||
Hoverboards: IConfigEntry;
|
||||
DataKnives: IConfigEntry;
|
||||
MechSuits: IConfigEntry;
|
||||
CrewShipHarnesses: IConfigEntry;
|
||||
Horses: IConfigEntry;
|
||||
DrifterMelee: IConfigEntry;
|
||||
UpgradeVer: number;
|
||||
OperatorLoadOuts: ISaveLoadoutEntry;
|
||||
AdultOperatorLoadOuts: ISaveLoadoutEntry;
|
||||
KahlLoadOuts: ISaveLoadoutEntry;
|
||||
CrewShips: ISaveLoadoutEntry;
|
||||
OperatorLoadOuts: IConfigEntry;
|
||||
AdultOperatorLoadOuts: IConfigEntry;
|
||||
KahlLoadOuts: IConfigEntry;
|
||||
CrewShips: IConfigEntry;
|
||||
}
|
||||
|
||||
export interface ISaveLoadoutEntry {
|
||||
export interface ISaveLoadoutRequestNoUpgradeVer extends Omit<ISaveLoadoutRequest, "UpgradeVer"> {}
|
||||
|
||||
export interface IConfigEntry {
|
||||
[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 {
|
||||
@ -76,36 +111,8 @@ export interface Col {
|
||||
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 =
|
||||
| { LoadOuts: { [key in keyof LoadOuts]: LoadOut } }
|
||||
| { LoadOuts: { [key in keyof ILoadout]: LoadOut } }
|
||||
| { LongGuns: Config }
|
||||
| { OperatorAmps: Config } // Replace 'any' with the actual type
|
||||
| { Pistols: Config } // Replace 'any' with the actual type
|
||||
|
Loading…
x
Reference in New Issue
Block a user