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 /static/data/*.bin
yarn.lock yarn.lock
/tmp /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 { Inventory } from "@/src/models/inventoryModel";
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import util from "util"; 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 { isObject } from "@/src/helpers/general";
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes"; 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; return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
}; };
type EquipmentChangeEntry = number | ISaveLoadoutEntry | ISaveLoadoutLoadoutEntry;
export const handleInventoryItemConfigChange = (equipmentChanges: ISaveLoadoutRequest) => { 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); //console.log(equipmentName);
if (!isObjectEmpty(equipment)) { if (!isObjectEmpty(equipment)) {
// non-empty is a change in loadout(or suit...) // non-empty is a change in loadout(or suit...)

View File

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