From 3289f76cd0283848f7d54b274976b412138d23bc Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 25 Sep 2021 17:29:51 -0400 Subject: [PATCH] safeguards --- src/Faction/Factions.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Faction/Factions.ts b/src/Faction/Factions.ts index 7e0aa7a47..9fa6f3c52 100644 --- a/src/Faction/Factions.ts +++ b/src/Faction/Factions.ts @@ -13,6 +13,15 @@ export let Factions: IMap = {}; export function loadFactions(saveString: string): void { Factions = JSON.parse(saveString, Reviver); + // safety check for when we load older save file that don't have newer factions + for (const faction of Object.keys(Factions)) { + try { + Factions[faction].getInfo(); + } catch (err) { + console.error("deleting " + faction); + delete Factions[faction]; + } + } } export function AddToFactions(faction: Faction): void {