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.
This commit is contained in:
omuretsu 2023-06-20 07:57:46 -04:00
parent 4b8a4d739b
commit aecdbe8e8f
2 changed files with 15 additions and 12 deletions

@ -70,9 +70,12 @@ export class Faction {
/** Initializes a Faction object from a JSON save state. */ /** Initializes a Faction object from a JSON save state. */
static fromJSON(value: IReviverValue): Faction { static fromJSON(value: IReviverValue): Faction {
const faction = Generic_fromJSON(Faction, value.data); 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. // Remove invalid augs from faction. Augs are repopulated with correct augs during any reset.
const augHelper = getEnumHelper("AugmentationName"); const augHelper = getEnumHelper("AugmentationName");
faction.augmentations = faction.augmentations.filter((augName) => augHelper.isMember(augName)); 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; return faction;
} }
} }

@ -37,18 +37,6 @@ export function initFactions(): void {
for (const name of Object.keys(FactionInfos)) { for (const name of Object.keys(FactionInfos)) {
resetFaction(new Faction(name)); 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. // All factions are added, this is a good place to add augs back to factions.
initCircadianModulator(); initCircadianModulator();
for (const aug of getRecordValues(Augmentations)) { 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);
}