Skip to content

Commit

Permalink
Merge pull request #16549 from Nexus-Mods/16545-fixed-updateset-initi…
Browse files Browse the repository at this point in the history
…alization

fixed UpdateSet initializing for non-FBLO games
  • Loading branch information
insomnious authored Oct 9, 2024
2 parents d80c9d9 + 0bf2bd5 commit 233b31a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/extensions/file_based_loadorder/UpdateSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export default class UpdateSet extends Set<number> {
private mApi: IExtensionApi;
private mModEntries: { [modId: number]: ILoadOrderEntryExt[] } = {};
private mInitialized = false;
constructor(api: IExtensionApi) {
private mIsFBLO: (gameId: string) => boolean;
constructor(api: IExtensionApi, isFBLO: (gameId: string) => boolean) {
super([]);
this.mApi = api;
this.mIsFBLO = isFBLO;
this.registerListeners();
}

Expand All @@ -46,8 +48,11 @@ export default class UpdateSet extends Set<number> {
return;
}

public init = (modEntries?: ILoadOrderEntryExt[]) => {
public init = (gameId: string, modEntries?: ILoadOrderEntryExt[]) => {
this.reset();
if (!this.mIsFBLO(gameId)) {
return;
}
this.mInitialized = true;
modEntries = !!modEntries && Array.isArray(modEntries) ? modEntries : this.genExtendedItemsFromState();
modEntries.forEach((iter: ILoadOrderEntryExt) => this.addNumericModId(iter));
Expand All @@ -64,6 +69,9 @@ export default class UpdateSet extends Set<number> {
return [];
}
const loadOrder = getSafe(state, ['persistent', 'loadOrder', profileId], []);
if (!loadOrder || !Array.isArray(loadOrder)) {
return [];
}
const filtered = loadOrder.reduce((acc, lo, idx) => {
acc.push({ ...lo, index: idx });
return acc;
Expand Down
7 changes: 5 additions & 2 deletions src/extensions/file_based_loadorder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ export default function init(context: IExtensionContext) {
);

context.once(() => {
updateSet = new UpdateSet(context.api);
updateSet = new UpdateSet(context.api, (gameId: string) => {
const gameEntry: ILoadOrderGameInfo = findGameEntry(gameId);
return gameEntry !== undefined;
});
context.api.onStateChange(['session', 'base', 'toolsRunning'],
(prev, current) => genToolsRunning(context.api, prev, current));

Expand Down Expand Up @@ -361,7 +364,7 @@ async function onWillRemoveMods(api: types.IExtensionApi,
return acc;
}, []);
if (!updateSet.isInitialized()) {
updateSet.init(filtered);
updateSet.init(gameId, filtered);
} else {
filtered.forEach(updateSet.addNumericModId);
}
Expand Down

0 comments on commit 233b31a

Please sign in to comment.