Skip to content

Commit

Permalink
raidboss/config: add per triggerset default output options (#5703)
Browse files Browse the repository at this point in the history
Every once in a while people ask for ways to override or disable a
particular trigger set, so here you go.

If a trigger gets overridden from another trigger set, the overriding
trigger set's options get used instead. This is probably not what people
want, but it's consistent.
  • Loading branch information
quisquous authored Jul 19, 2023
1 parent 202cdda commit 60b7179
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 88 deletions.
10 changes: 10 additions & 0 deletions types/trigger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type ResponseField<Data extends RaidbossData, MatchType extends NetAnyMat
| ResponseFunc<Data, MatchType>
| ResponseOutput<Data, MatchType>;

// Config UI options that apply to an individual trigger (by id).
export type TriggerAutoConfig = {
Output?: Output;
Duration?: number;
Expand All @@ -99,6 +100,15 @@ export type TriggerAutoConfig = {
SpokenAlertsEnabled?: boolean;
};

// Config UI options that apply to an entire trigger set.
// TODO: this doesn't apply to literal timeline alerts (not timeline triggers but
// ancient timeline code that specifies alerts directly).
export type TriggerSetAutoConfig = {
TextAlertsEnabled?: boolean;
SoundAlertsEnabled?: boolean;
SpokenAlertsEnabled?: boolean;
};

// Note: functions like run or preRun need to be defined as void-only as (confusingly)
// it is not possible to assign `(d: Data) => boolean` to a void | undefined, only to void.
export type TriggerField<Data extends RaidbossData, MatchType extends NetAnyMatches, Return> =
Expand Down
31 changes: 22 additions & 9 deletions ui/raidboss/popup-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
TriggerAutoConfig,
TriggerField,
TriggerOutput,
TriggerSetAutoConfig,
} from '../../types/trigger';

import AutoplayHelper from './autoplay_helper';
Expand Down Expand Up @@ -70,6 +71,7 @@ export type ProcessedTrigger = LooseTrigger & {
localRegex?: RegExp;
localNetRegex?: RegExp;
output?: Output;
triggerSetAutoConfig?: Readonly<TriggerSetAutoConfig>;
};

type ProcessedTimelineTrigger = ProcessedTrigger & {
Expand Down Expand Up @@ -729,6 +731,10 @@ export class PopupText {
console.log('Loading user triggers for zone');
}

const triggerSetAutoConfig = set.id !== undefined
? this.options.PerTriggerSetAutoConfig[set.id]
: undefined;

const loadThisSet = set.id === undefined ? [] : [set.id];
for (const id of [...loadThisSet, ...set.loadConfigs ?? []]) {
// In case a trigger set id changes and somebody wants to refer to
Expand Down Expand Up @@ -774,6 +780,11 @@ export class PopupText {
trigger.filename = setFilename;
const id = trigger.id ?? `${setFilename} trigger[${index}]`;

// Store trigger set options with the trigger itself,
// as it may get overridden by a trigger with the same
// id from a different trigger set.
trigger.triggerSetAutoConfig = triggerSetAutoConfig;

this.ProcessTrigger(trigger);
orderedTriggers.push(trigger);

Expand Down Expand Up @@ -867,6 +878,7 @@ export class PopupText {
// Timeline triggers are never translated.
this.ProcessTrigger(trigger);
trigger.isTimelineTrigger = true;
trigger.triggerSetAutoConfig = triggerSetAutoConfig;
orderedTriggers.push(trigger);
}
}
Expand Down Expand Up @@ -1198,21 +1210,22 @@ export class PopupText {
// Set defaults for triggerHelper object (anything that won't change based on
// other trigger functions running)
_onTriggerInternalHelperDefaults(triggerHelper: TriggerHelper): void {
// Load settings from triggerAutoConfig if they're set
triggerHelper.textAlertsEnabled = triggerHelper.triggerAutoConfig.TextAlertsEnabled ??
triggerHelper.textAlertsEnabled;
triggerHelper.soundAlertsEnabled = triggerHelper.triggerAutoConfig.SoundAlertsEnabled ??
triggerHelper.soundAlertsEnabled;
triggerHelper.spokenAlertsEnabled = triggerHelper.triggerAutoConfig.SpokenAlertsEnabled ??
triggerHelper.spokenAlertsEnabled;

// Load settings from triggerOptions if they're set
// Options priority:
// backcompat triggerOptions > trigger autoconfig > trigger set autoconfig > top level option
triggerHelper.textAlertsEnabled = triggerHelper.triggerOptions.TextAlert ??
triggerHelper.triggerAutoConfig.TextAlertsEnabled ??
triggerHelper.trigger.triggerSetAutoConfig?.TextAlertsEnabled ??
triggerHelper.textAlertsEnabled;
triggerHelper.soundAlertsEnabled = triggerHelper.triggerOptions.SoundAlert ??
triggerHelper.triggerAutoConfig.SoundAlertsEnabled ??
triggerHelper.trigger.triggerSetAutoConfig?.SoundAlertsEnabled ??
triggerHelper.soundAlertsEnabled;
triggerHelper.spokenAlertsEnabled = triggerHelper.triggerOptions.SpeechAlert ??
triggerHelper.triggerAutoConfig.SpokenAlertsEnabled ??
triggerHelper.trigger.triggerSetAutoConfig?.SpokenAlertsEnabled ??
triggerHelper.spokenAlertsEnabled;

// Load settings from triggerOptions if they're set
triggerHelper.groupSpokenAlertsEnabled = triggerHelper.triggerOptions.GroupSpeechAlert ??
triggerHelper.groupSpokenAlertsEnabled;

Expand Down
Loading

0 comments on commit 60b7179

Please sign in to comment.