Skip to content

Commit

Permalink
Merge pull request #16530 from Nexus-Mods/fblo_updateset_fixed_initia…
Browse files Browse the repository at this point in the history
…lization

fixed UpdateSet not resetting correctly on gameMode switch
  • Loading branch information
insomnious authored Oct 7, 2024
2 parents b3c2a81 + 8b0da6c commit 026ed8c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/extensions/file_based_loadorder/UpdateSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class UpdateSet extends Set<number> {
constructor(api: IExtensionApi) {
super([]);
this.mApi = api;
this.init();
this.registerListeners();
}

public addNumericModId = (lo: ILoadOrderEntryExt) => {
Expand Down Expand Up @@ -48,9 +48,8 @@ export default class UpdateSet extends Set<number> {

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));
}

Expand All @@ -73,19 +72,19 @@ export default class UpdateSet extends Set<number> {
};

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;
Expand Down

0 comments on commit 026ed8c

Please sign in to comment.