improve some types

This commit is contained in:
Matej Voboril 2023-11-22 09:42:26 -06:00
parent e7245bbb68
commit 5101366ff2
No known key found for this signature in database
GPG Key ID: CD484F5C05A92AA8
4 changed files with 47 additions and 28 deletions

3
.gitignore vendored
View File

@ -5,3 +5,6 @@
/static/data/*.bin
yarn.lock
/tmp
# JetBrains/webstorm configs
.idea/

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
lts/iron

View File

@ -1,7 +1,12 @@
import { Inventory } from "@/src/models/inventoryModel";
import { RequestHandler } from "express";
import util from "util";
import { EquipmentCategories, ISaveLoadoutRequest } from "@/src/types/saveLoadoutTypes";
import {
EquipmentCategories,
ISaveLoadoutEntry,
ISaveLoadoutLoadoutEntry,
ISaveLoadoutRequest
} from "@/src/types/saveLoadoutTypes";
import { isObject } from "@/src/helpers/general";
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
@ -9,8 +14,11 @@ export const isObjectEmpty = (obj: Record<string, unknown>) => {
return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
};
type EquipmentChangeEntry = number | ISaveLoadoutEntry | ISaveLoadoutLoadoutEntry;
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequest) => {
for (const [equipmentName, equipment] of Object.entries(equipmentChanges)) {
for (const [equipmentName, eqp] of Object.entries(equipmentChanges)) {
const equipment = eqp as EquipmentChangeEntry;
//console.log(equipmentName);
if (!isObjectEmpty(equipment)) {
// non-empty is a change in loadout(or suit...)

View File

@ -1,30 +1,37 @@
export interface ISaveLoadoutRequest {
LoadOuts: { [key: string]: LoadOut };
LongGuns: { [key: string]: Config };
OperatorAmps: { [key: string]: Config };
Pistols: { [key: string]: Config };
Suits: { [key: string]: Config };
Melee: {};
Sentinels: {};
SentinelWeapons: {};
KubrowPets: {};
SpaceSuits: {};
SpaceGuns: {};
SpaceMelee: {};
Scoops: {};
SpecialItems: {};
MoaPets: {};
Hoverboards: {};
DataKnives: {};
MechSuits: {};
CrewShipHarnesses: {};
Horses: {};
DrifterMelee: {};
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;
UpgradeVer: number;
OperatorLoadOuts: {};
AdultOperatorLoadOuts: {};
KahlLoadOuts: {};
CrewShips: {};
OperatorLoadOuts: ISaveLoadoutEntry;
AdultOperatorLoadOuts: ISaveLoadoutEntry;
KahlLoadOuts: ISaveLoadoutEntry;
CrewShips: ISaveLoadoutEntry;
}
export interface ISaveLoadoutEntry {
[key: string]: Config;
}
export interface ISaveLoadoutLoadoutEntry {
[key: string]: LoadOut;
}
export interface Config {