diff --git a/ui/raidboss/popup-text.ts b/ui/raidboss/popup-text.ts index 017c4f3744..705b2cd3b1 100644 --- a/ui/raidboss/popup-text.ts +++ b/ui/raidboss/popup-text.ts @@ -704,23 +704,26 @@ export class PopupText { this.triggerSets.push(...this.options.Triggers); // Eliminate any trigger sets with duplicate ids, allowing later ones to override earlier ones. - const uniqueById = new Map(); - const noIdList: typeof this.triggerSets = []; - for (const triggerSet of this.triggerSets) { - if (triggerSet.id === undefined) { - noIdList.push(triggerSet); - continue; - } - const existing = uniqueById.get(triggerSet.id); - if (existing !== undefined) { - console.log( - `Overriding trigger set id '${triggerSet.id}' from '${existing.filename}' with '${triggerSet.filename}'`, - ); + // Filter the list to keep the last instance of each ID while preserving order. + const lastVersionOfId = new Map(); + for (const set of this.triggerSets) { + if (set.id !== undefined) { + const existing = lastVersionOfId.get(set.id); + if (existing !== undefined) { + console.log( + `Overriding trigger set id '${set.id}' from '${existing.filename}' with '${set.filename}'`, + ); + } + lastVersionOfId.set(set.id, set); } - uniqueById.set(triggerSet.id, triggerSet); } - this.triggerSets = [...noIdList, ...uniqueById.values()]; - this.triggerSetsById = Object.fromEntries(uniqueById); + + this.triggerSets = this.triggerSets.filter((set) => { + if (set.id === undefined) + return true; + return lastVersionOfId.get(set.id) === set; + }); + this.triggerSetsById = Object.fromEntries(lastVersionOfId); } OnChangeZone(e: EventResponses['ChangeZone']): void {