From fe482127ab87fe920721996e001241205242ac31 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 7 Dec 2024 11:41:51 +0000 Subject: [PATCH] Added null protection to `addHideoutEliteSlots()` when profile lacks a generator --- project/src/services/ProfileFixerService.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index 5dc7e4d6..61a58c45 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -345,12 +345,11 @@ export class ProfileFixerService { /** * Initial release of SPT 3.10 used an incorrect favorites structure, reformat * the structure to the correct MongoID array structure - * @param pmcProfile + * @param pmcProfile */ protected fixFavorites(pmcProfile: IPmcData): void { const favoritesAsAny = pmcProfile.Inventory?.favoriteItems as any; - if (favoritesAsAny) - { + if (favoritesAsAny) { const correctedFavorites = favoritesAsAny.map((favorite) => { return favorite._id ?? favorite; }); @@ -367,12 +366,15 @@ export class ProfileFixerService { protected addHideoutEliteSlots(pmcProfile: IPmcData): void { const globals = this.databaseService.getGlobals(); - const genSlots = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.GENERATOR).slots.length; - const extraGenSlots = globals.config.SkillsSettings.HideoutManagement.EliteSlots.Generator.Slots; + const generator = pmcProfile.Hideout.Areas.find((area) => area.type === HideoutAreas.GENERATOR); + if (generator) { + const genSlots = generator.slots.length; + const extraGenSlots = globals.config.SkillsSettings.HideoutManagement.EliteSlots.Generator.Slots; - if (genSlots < 6 + extraGenSlots) { - this.logger.debug("Updating generator area slots to a size of 6 + hideout management skill"); - this.addEmptyObjectsToHideoutAreaSlots(HideoutAreas.GENERATOR, 6 + extraGenSlots, pmcProfile); + if (genSlots < 6 + extraGenSlots) { + this.logger.debug("Updating generator area slots to a size of 6 + hideout management skill"); + this.addEmptyObjectsToHideoutAreaSlots(HideoutAreas.GENERATOR, 6 + extraGenSlots, pmcProfile); + } } const waterCollSlots = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.WATER_COLLECTOR).slots