From 8b0da6cd6b121edd5c40b812ab6410d557f204af Mon Sep 17 00:00:00 2001 From: IDCs Date: Mon, 7 Oct 2024 08:34:46 +0100 Subject: [PATCH] fixed UpdateSet not resetting correctly on gameMode switch --- src/extensions/file_based_loadorder/UpdateSet.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/extensions/file_based_loadorder/UpdateSet.ts b/src/extensions/file_based_loadorder/UpdateSet.ts index 55f91f9b0..ddab98bbf 100644 --- a/src/extensions/file_based_loadorder/UpdateSet.ts +++ b/src/extensions/file_based_loadorder/UpdateSet.ts @@ -20,7 +20,7 @@ export default class UpdateSet extends Set { constructor(api: IExtensionApi) { super([]); this.mApi = api; - this.init(); + this.registerListeners(); } public addNumericModId = (lo: ILoadOrderEntryExt) => { @@ -48,9 +48,8 @@ export default class UpdateSet extends Set { public init = (modEntries?: ILoadOrderEntryExt[]) => { this.reset(); - this.registerListeners(); this.mInitialized = true; - modEntries = modEntries !== undefined ? modEntries : this.genExtendedItemsFromState(); + modEntries = !!modEntries && Array.isArray(modEntries) ? modEntries : this.genExtendedItemsFromState(); modEntries.forEach((iter: ILoadOrderEntryExt) => this.addNumericModId(iter)); } @@ -76,19 +75,19 @@ export default class UpdateSet extends Set { }; private registerListeners = () => { - this.mApi.events.on('gamemode-activated', this.reset); + this.mApi.events.on('gamemode-activated', this.init); } private removeListeners = () => { - this.mApi.events.removeListener('gamemode-activated', this.reset); + this.mApi.events.removeListener('gamemode-activated', this.init); } public destroy = () => { + this.removeListeners(); this.reset(); } private reset = () => { - this.removeListeners(); super.clear(); this.mModEntries = []; this.mInitialized = false;