From aecdbe8e8f8ee5b4b7d270d3e650f672df2072a1 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Tue, 20 Jun 2023 07:57:46 -0400 Subject: [PATCH] Fix bad aug reinitialization point This is just a quick fix. Also added some savegame fix code that will soon be removed once the better fix is in. --- src/Faction/Faction.ts | 3 +++ src/Faction/Factions.ts | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Faction/Faction.ts b/src/Faction/Faction.ts index b303340a6..b4ea4e5ff 100644 --- a/src/Faction/Faction.ts +++ b/src/Faction/Faction.ts @@ -70,9 +70,12 @@ export class Faction { /** Initializes a Faction object from a JSON save state. */ static fromJSON(value: IReviverValue): Faction { const faction = Generic_fromJSON(Faction, value.data); + if (!Array.isArray(faction.augmentations)) faction.augmentations = []; // Remove invalid augs from faction. Augs are repopulated with correct augs during any reset. const augHelper = getEnumHelper("AugmentationName"); faction.augmentations = faction.augmentations.filter((augName) => augHelper.isMember(augName)); + // Fix broken saves, this will soon be removed when better fix is implemented + faction.augmentations = [...new Set(faction.augmentations)]; return faction; } } diff --git a/src/Faction/Factions.ts b/src/Faction/Factions.ts index 49660d904..d9ad0d931 100644 --- a/src/Faction/Factions.ts +++ b/src/Faction/Factions.ts @@ -37,18 +37,6 @@ export function initFactions(): void { for (const name of Object.keys(FactionInfos)) { resetFaction(new Faction(name)); } -} - -//Resets a faction during (re-)initialization. Saves the favor in the new -//Faction object and deletes the old Faction Object from "Factions". Then -//reinserts the new Faction object -function resetFaction(newFactionObject: Faction): void { - const factionName: string = newFactionObject.name; - if (factionExists(factionName)) { - newFactionObject.favor = Factions[factionName].favor; - delete Factions[factionName]; - } - AddToFactions(newFactionObject); // All factions are added, this is a good place to add augs back to factions. initCircadianModulator(); for (const aug of getRecordValues(Augmentations)) { @@ -62,3 +50,15 @@ function resetFaction(newFactionObject: Faction): void { } } } + +//Resets a faction during (re-)initialization. Saves the favor in the new +//Faction object and deletes the old Faction Object from "Factions". Then +//reinserts the new Faction object +function resetFaction(newFactionObject: Faction): void { + const factionName: string = newFactionObject.name; + if (factionExists(factionName)) { + newFactionObject.favor = Factions[factionName].favor; + delete Factions[factionName]; + } + AddToFactions(newFactionObject); +}