forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathraidboss_config.ts
2539 lines (2336 loc) · 83.7 KB
/
raidboss_config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { isLang, Lang } from '../../resources/languages';
import { buildNetRegexForTrigger } from '../../resources/netregexes';
import { UnreachableCode } from '../../resources/not_reached';
import PartyTracker from '../../resources/party';
import Regexes from '../../resources/regexes';
import { triggerOutputFunctions } from '../../resources/responses';
import { translateRegex, translateRegexBuildParam } from '../../resources/translations';
import UserConfig, {
ConfigEntry,
ConfigValue,
OptionsTemplate,
UserFileCallback,
} from '../../resources/user_config';
import { BaseOptions, RaidbossData } from '../../types/data';
import { SavedConfigEntry } from '../../types/event';
import { Job, Role } from '../../types/job';
import { Matches } from '../../types/net_matches';
import {
LocaleText,
LooseTrigger,
Output,
OutputStrings,
RaidbossFileData,
TimelineField,
TriggerAutoConfig,
TriggerSetAutoConfig,
} from '../../types/trigger';
import {
CactbotConfigurator,
ConfigLooseTrigger,
ConfigLooseTriggerSet,
ConfigProcessedFileMap,
} from '../config/config';
import raidbossFileData from './data/raidboss_manifest.txt';
import { RaidbossTriggerField, RaidbossTriggerOutput } from './popup-text';
import raidbossOptions, { RaidbossOptions } from './raidboss_options';
import { TimelineParser } from './timeline_parser';
const kOptionKeys = {
output: 'Output',
duration: 'Duration',
beforeSeconds: 'BeforeSeconds',
delayAdjust: 'DelayAdjust',
outputStrings: 'OutputStrings',
// folder for all trigger options
triggers: 'triggers',
// folder for all trigger set options
triggerSets: 'triggerSets',
// folder for options in trigger set config ui
triggerSetConfig: 'TriggerSetConfig',
} as const;
type TriggerSoundOption = {
label: LocaleText;
debugOnly?: boolean;
};
// No sound only option, because that's silly.
const kTriggerOptions = {
default: {
label: {
en: '✔ Defaults',
de: '✔ Standards',
fr: '✔ Défauts',
ja: '✔ 初期設定',
cn: '✔ 默认设置',
ko: '✔ 기본',
},
},
textAndSound: {
label: {
en: '🆙🔊 Text and Sound',
de: '🆙🔊 Text und Ton',
fr: '🆙🔊 Texte et son',
ja: '🆙🔊 テキストと音声',
cn: '🆙🔊 文本显示与提示音',
ko: '🆙🔊 텍스트와 소리',
},
},
ttsAndText: {
label: {
en: '🆙💬 Text and TTS',
de: '🆙💬 Text und TTS',
fr: '🆙💬 Texte et TTS',
ja: '🆙💬 テキストとTTS',
cn: '🆙💬 文本显示与TTS',
ko: '🆙💬 텍스트와 TTS',
},
},
ttsOnly: {
label: {
en: '💬 TTS Only',
de: '💬 Nur TTS',
fr: '💬 TTS Seulement',
ja: '💬 TTSのみ',
cn: '💬 只使用TTS',
ko: '💬 TTS만',
},
},
textOnly: {
label: {
en: '🆙 Text Only',
de: '🆙 Nur Text',
fr: '🆙 Texte seulement',
ja: '🆙 テキストのみ',
cn: '🆙 只使用文本显示',
ko: '🆙 텍스트만',
},
},
disabled: {
label: {
en: '❌ Disabled',
de: '❌ Deaktiviert',
fr: '❌ Désactivé',
ja: '❌ 無効',
cn: '❌ 禁用',
ko: '❌ 비활성화',
},
},
} as const;
const triggerSoundOptions: { [key: string]: TriggerSoundOption } = kTriggerOptions;
type DetailKey = {
label: LocaleText;
cls: string;
debugOnly?: boolean;
generatedManually?: boolean;
};
const kDetailKeys = {
'triggerRegex': {
label: {
en: 'regex',
de: 'regex',
fr: 'regex',
ja: '正規表現',
cn: '正则表达式',
ko: '정규식',
},
cls: 'regex-text',
debugOnly: true,
},
'triggerNetRegex': {
label: {
en: 'netregex',
de: 'netregex',
fr: 'netregex',
ja: 'ネット正規表現',
cn: '网络日志正则表达式',
ko: '정규표현식',
},
cls: 'regex-text',
debugOnly: true,
},
'timelineRegex': {
label: {
en: 'timeline',
de: 'timeline',
fr: 'timeline',
ja: 'タイムライン',
cn: '时间轴',
ko: '타임라인',
},
cls: 'regex-text',
debugOnly: true,
},
'beforeSeconds': {
label: {
en: 'before (sec)',
de: 'Vorher (Sekunden)',
fr: 'avant (seconde)',
ja: 'その前に (秒)',
cn: '提前 (秒)',
ko: '앞당김 (초)',
},
cls: 'before-seconds-text',
generatedManually: true,
},
'condition': {
label: {
en: 'condition',
de: 'condition',
fr: 'condition',
ja: '条件',
cn: '条件',
ko: '조건',
},
cls: 'condition-text',
debugOnly: true,
},
'delayAdjust': {
label: {
// Note: delay adjusting is both dangerous (delays can be functional in terms of
// needing to happen after/before a particular time to collect the state of the world)
// as well as confusing (you can adjust some but not many things negatively as
// delay can't go below zero). Therefore, this is a developer/debug mode only for
// people who know what they're doing.
en: 'DEBUG delay adjust (sec)',
de: 'DEBUG Verzögerungseinstellung (sec)',
fr: 'Délai d\'ajustement DEBUG (s)',
ja: 'DEBUGの待機調整 (秒)',
cn: 'DEBUG 延时调整 (秒)',
ko: '"디버그" 딜레이 조절 (초)',
},
cls: 'delay-adjust-text',
generatedManually: true,
debugOnly: true,
},
'duration': {
label: {
en: 'duration (sec)',
de: 'Dauer (Sekunden)',
fr: 'Durée (secondes)',
ja: '存続時間 (秒)',
cn: '显示时长 (秒)',
ko: '지속 시간 (초)',
},
cls: 'duration-text',
generatedManually: true,
},
'preRun': {
label: {
en: 'preRun',
de: 'preRun',
fr: 'preRun',
ja: 'プレ実行',
cn: '预运行',
ko: '사전 실행',
},
cls: 'prerun-text',
debugOnly: true,
},
'alarmText': {
label: {
en: 'alarm',
de: 'alarm',
fr: 'alarme',
ja: '警報',
cn: '致命级',
ko: '경고',
},
cls: 'alarm-text',
},
'alertText': {
label: {
en: 'alert',
de: 'alert',
fr: 'alerte',
ja: '警告',
cn: '严重级',
ko: '주의',
},
cls: 'alert-text',
},
'infoText': {
label: {
en: 'info',
de: 'info',
fr: 'info',
ja: '情報',
cn: '一般级',
ko: '안내',
},
cls: 'info-text',
},
'tts': {
label: {
en: 'tts',
de: 'tts',
fr: 'tts',
ja: 'TTS',
cn: 'TTS',
ko: 'TTS',
},
cls: 'tts-text',
},
'sound': {
label: {
en: 'sound',
de: 'sound',
fr: 'son',
ja: '音声',
cn: '提示音',
ko: '소리',
},
cls: 'sound-text',
},
'run': {
label: {
en: 'run',
de: 'run',
fr: 'run',
ja: '実行',
cn: '运行',
ko: '실행',
},
cls: 'run-text',
debugOnly: true,
},
} as const;
// Ordered set of headers in the timeline edit table.
const kTimelineTableHeaders = {
shouldDisplayText: {
en: 'Show',
de: 'Anzeigen',
fr: 'Afficher',
ja: '表示',
cn: '显示',
ko: '표시',
},
text: {
en: 'Timeline Text',
de: 'Timeline Text',
fr: 'Texte de la timeline',
ja: 'タイムラインテキスト',
cn: '时间轴文本',
ko: '타임라인 텍스트',
},
overrideText: {
en: 'Rename',
de: 'Umbenennen',
fr: 'Renommer',
ja: 'テキスト変更',
cn: '修改文本',
ko: '텍스트 변경',
},
} as const;
const detailKeys: { [key in keyof LooseTrigger]: DetailKey } = kDetailKeys;
const kMiscTranslations = {
// Shows up for un-set values.
valueDefault: {
en: '(default)',
de: '(Standard)',
fr: '(Défaut)',
ja: '(初期値)',
cn: '(默认值)',
ko: '(기본값)',
},
// Shown when the UI can't decipher the output of a function.
valueIsFunction: {
en: '(function)',
de: '(Funktion)',
fr: '(Fonction)',
ja: '(関数)',
cn: '(函数)',
ko: '(함수)',
},
// Warning label for triggers without ids or overridden triggers.
warning: {
en: '⚠️ warning',
de: '⚠️ Warnung',
fr: '⚠️ Attention',
ja: '⚠️ 警告',
cn: '⚠️ 警告',
ko: '⚠️ 주의',
},
// Shows up for triggers without ids.
missingId: {
en: 'missing id field',
de: 'Fehlendes ID Feld',
fr: 'Champ ID manquant',
ja: 'idがありません',
cn: '缺少id属性',
ko: 'ID 필드값 없음',
},
// Shows up for triggers that are overridden by other triggers.
overriddenByFile: {
en: 'overridden by "${file}"',
de: 'Überschrieben durch "${file}"',
fr: 'Écrasé(e) par "${file}"',
ja: '"${file}"に上書きました',
cn: '被"${file}"文件覆盖',
ko: '"${file}" 파일에서 덮어씌움',
},
// Opens trigger file on Github.
viewTriggerSource: {
en: 'View Trigger Source',
de: 'Zeige Trigger Quelle',
fr: 'Afficher la source du Trigger',
ja: 'トリガーのコードを表示',
cn: '显示触发器源码',
ko: '트리거 소스코드 보기',
},
// The header for the editing timeline section inside a trigger file.
editTimeline: {
en: 'Edit Timeline',
de: 'Timeline bearbeiten',
fr: 'Éditer la timeline',
ja: 'タイムラインを編集',
cn: '编辑时间轴',
ko: '타임라인 편집',
},
// The header inside the Edit Timeline section on top of the reference timeline text.
timelineListing: {
en: 'Reference Text (uneditable)',
de: 'Referenztext (nicht editierbar)',
fr: 'Texte de référence (non éditable)',
ja: '参考タイムライン (編集不可)',
cn: '参考文本 (不可编辑)',
ko: '원본 타임라인 (수정 불가능)',
},
// The header inside the Edit Timeline section on top of the add entries section.
addCustomTimelineEntries: {
en: 'Add Custom Timeline Entries',
de: 'Eigene Timeline Einträge hinzufügen',
fr: 'Ajouter une entrée de timeline personnalisée',
ja: 'カスタマイズタイムライン追加',
cn: '添加自定义时间轴条目',
ko: '사용자 지정 타임라인 항목 추가',
},
// The button text for the Edit Timeline add entries section.
addMoreRows: {
en: 'Add more rows',
de: 'Mehr Reihen hinzufügen',
fr: 'Ajouter une ligne',
ja: '行追加',
cn: '添加更多行',
ko: '행 추가',
},
customEntryTime: {
en: 'Time',
de: 'Zeit',
fr: 'Temps',
ja: '時間',
cn: '时间',
ko: '시간',
},
customEntryText: {
en: 'Text',
de: 'Text',
fr: 'Texte',
ja: 'テキスト',
cn: '文本',
ko: '텍스트',
},
customEntryDuration: {
en: 'Duration (seconds)',
de: 'Dauer (Sekunden)',
fr: 'Durée (s)',
ja: '持続時間 (秒)',
cn: '显示时长 (秒)',
ko: '지속시간 (초)',
},
customEntryRemove: {
en: 'Remove',
de: 'Entfernen',
fr: 'Supprimer',
ja: '削除',
cn: '移除',
ko: '삭제',
},
};
const validDurationOrUndefined = (valEntry?: SavedConfigEntry) => {
if (typeof valEntry !== 'string' && typeof valEntry !== 'number')
return undefined;
const val = parseFloat(valEntry.toString());
if (!isNaN(val) && val >= 0)
return val;
return undefined;
};
const validDelayAdjustOrUndefined = (valEntry?: SavedConfigEntry) => {
if (typeof valEntry !== 'string' && typeof valEntry !== 'number')
return undefined;
const val = parseFloat(valEntry.toString());
if (!isNaN(val))
return val;
return undefined;
};
const canBeConfigured = (trig: ConfigLooseTrigger) =>
!trig.isMissingId && trig.overriddenByFile === undefined;
const addTriggerDetail = (
container: HTMLElement,
labelText: string,
detailText: string,
detailCls?: string[],
): void => {
const label = document.createElement('div');
label.innerText = labelText;
label.classList.add('trigger-label');
container.appendChild(label);
const detail = document.createElement('div');
detail.classList.add('trigger-detail');
detail.innerText = detailText;
container.appendChild(detail);
if (detailCls)
detail.classList.add(...detailCls);
};
// This is used both for top level Options and for PerTriggerAutoConfig settings.
// Unfortunately due to poor decisions in the past, PerTriggerOptions has different
// fields here. This should be fixed.
const setOptionsFromOutputValue = (
value: SavedConfigEntry,
options: BaseOptions | TriggerAutoConfig | TriggerSetAutoConfig,
) => {
if (value === 'default') {
// Nothing.
} else if (value === 'textAndSound') {
options.TextAlertsEnabled = true;
options.SoundAlertsEnabled = true;
options.SpokenAlertsEnabled = false;
} else if (value === 'ttsAndText') {
options.TextAlertsEnabled = true;
options.SoundAlertsEnabled = true;
options.SpokenAlertsEnabled = true;
} else if (value === 'ttsOnly') {
options.TextAlertsEnabled = false;
options.SoundAlertsEnabled = true;
options.SpokenAlertsEnabled = true;
} else if (value === 'textOnly') {
options.TextAlertsEnabled = true;
options.SoundAlertsEnabled = false;
options.SpokenAlertsEnabled = false;
} else if (value === 'disabled') {
options.TextAlertsEnabled = false;
options.SoundAlertsEnabled = false;
options.SpokenAlertsEnabled = false;
} else {
// FIXME: handle lint error here
// ref: https://github.com/OverlayPlugin/cactbot/pull/274#discussion_r1692375852
// eslint-disable-next-line @typescript-eslint/no-base-to-string
console.error(`unknown output type: ${value.toString()}`);
}
};
// Helper for doing nothing during trigger eval, but still recording any
// calls to `output.responseOutputStrings = x;` via callback.
class DoNothingFuncProxy {
constructor(outputStringsCallback: (outputStrings: OutputStrings) => void) {
return new Proxy(this, {
set(_target, property, value): boolean {
if (property === 'responseOutputStrings') {
// TODO: need some way of verifying that a value is an OutputStrings.
outputStringsCallback(value as OutputStrings);
return true;
}
// Ignore other property setting here.
return false;
},
get(_target, _name) {
return () => {/* noop */};
},
});
}
}
const makeLink = (href: string) => {
return `<a href="${href}" target="_blank">${href}</a>`;
};
const langOrEn = (lang: ConfigValue): Lang => {
return typeof lang === 'string' && isLang(lang) ? lang : 'en';
};
class RaidbossConfigurator {
private base: CactbotConfigurator;
private alertsLang: Lang;
private timelineLang: Lang;
constructor(cactbotConfigurator: CactbotConfigurator) {
this.base = cactbotConfigurator;
// TODO: is it worth adding the complexity to reflect this change in triggers that use it?
// This is probably where using something like vue or react would be easier.
// For the moment, folks can just reload, for real.
this.alertsLang = langOrEn(this.base.getOption('raidboss', 'AlertsLanguage', this.base.lang));
this.timelineLang = langOrEn(
this.base.getOption('raidboss', 'TimelineLanguage', this.base.lang),
);
}
buildUI(container: HTMLElement, raidbossFiles: RaidbossFileData, userOptions: RaidbossOptions) {
const fileMap = this.processRaidbossFiles(raidbossFiles, userOptions);
const expansionDivs: { [expansion: string]: HTMLElement } = {};
for (const [key, info] of Object.entries(fileMap)) {
// "expansion" here is technically section, which includes "general triggers"
// and one section per user file.
const expansion = info.section;
// This isn't perfect, but skip trigger sets that are no-ops.
const hasTriggers = Object.keys(info.triggers ?? []).length !== 0;
const hasTimeline = info.triggerSet.timeline !== undefined;
const hasTriggerSetConfig = (info.triggerSet.config ?? []).length > 0;
if (!hasTriggers && !hasTimeline && !hasTriggerSetConfig)
continue;
let expansionDiv = expansionDivs[expansion];
if (!expansionDiv) {
const expansionContainer = document.createElement('div');
expansionContainer.classList.add('trigger-expansion-container', 'collapsed');
container.appendChild(expansionContainer);
const expansionHeader = document.createElement('div');
expansionHeader.classList.add('trigger-expansion-header');
expansionHeader.onclick = () => {
expansionContainer.classList.toggle('collapsed');
};
expansionHeader.innerText = expansion;
expansionContainer.appendChild(expansionHeader);
expansionDiv = expansionDivs[expansion] = expansionContainer;
}
const triggerContainer = document.createElement('div');
triggerContainer.classList.add('trigger-file-container', 'collapsed');
expansionDiv.appendChild(triggerContainer);
const headerDiv = document.createElement('div');
headerDiv.classList.add('trigger-file-header');
headerDiv.onclick = () => {
triggerContainer.classList.toggle('collapsed');
};
const parts = [info.title, info.type, info.prefix];
for (const part of parts) {
if (part === undefined)
continue;
const partDiv = document.createElement('div');
partDiv.classList.add('trigger-file-header-part');
// Use innerHTML here because of <Emphasis>Whorleater</Emphasis>.
partDiv.innerHTML = part;
headerDiv.appendChild(partDiv);
}
triggerContainer.appendChild(headerDiv);
// TODO: print a warning if config exists without triggerset id??
if (info.triggerSet.id !== undefined) {
const triggerSetConfig = document.createElement('div');
triggerSetConfig.classList.add('overlay-options');
triggerContainer.appendChild(triggerSetConfig);
const triggerSetAlertOutput = {
...defaultTriggerSetAlertOutput,
id: kOptionKeys.output,
default: this.base.getStringOption(
'raidboss',
defaultAlertOutput.id,
defaultAlertOutput.default.toString(),
),
} as const;
this.base.buildConfigEntry(
userOptions,
triggerSetConfig,
triggerSetAlertOutput,
'raidboss',
[
kOptionKeys.triggerSets,
info.triggerSet.id,
],
);
for (const opt of info.triggerSet.config ?? []) {
if (!this.base.developerOptions && opt.debugOnly)
continue;
this.base.buildConfigEntry(userOptions, triggerSetConfig, opt, 'raidboss', [
kOptionKeys.triggerSetConfig,
info.triggerSet.id,
]);
}
}
// Timeline editing is tied to a single, specific zoneId per file for now.
// We could add more indirection (via fileKey?) and look up zoneId -> fileKey[]
// and fileKey -> timeline edits if needed.
if (info.triggerSet.timeline !== undefined && typeof info.zoneId === 'number')
this.buildTimelineUIContainer(info.zoneId, info.triggerSet, triggerContainer, userOptions);
const triggerOptions = document.createElement('div');
triggerOptions.classList.add('trigger-file-options');
triggerContainer.appendChild(triggerOptions);
for (const [trigId, trig] of Object.entries(info.triggers ?? {})) {
// Don't construct triggers that won't show anything.
let hasOutputFunc = false;
for (const func of triggerOutputFunctions) {
if (func in trig) {
hasOutputFunc = true;
break;
}
}
if (!hasOutputFunc && !this.base.developerOptions)
continue;
const triggerDiv = document.createElement('div');
triggerDiv.classList.add('trigger');
// Build the trigger label.
const triggerId = document.createElement('div');
triggerId.classList.add('trigger-id');
triggerId.innerHTML = trig.isMissingId ? '(???)' : trigId;
triggerId.classList.add('trigger-id');
triggerDiv.appendChild(triggerId);
// Build the trigger comment
if (trig.comment) {
const trigComment = trig.comment[this.base.lang] ?? trig.comment?.en ?? '';
const triggerCommentDiv = document.createElement('div');
triggerCommentDiv.innerHTML = trigComment;
triggerCommentDiv.classList.add('comment');
triggerDiv.appendChild(triggerCommentDiv);
}
triggerOptions.appendChild(triggerDiv);
// Container for the right side ui (select boxes, all of the info).
const triggerDetails = document.createElement('div');
triggerDetails.classList.add('trigger-details');
triggerOptions.appendChild(triggerDetails);
if (canBeConfigured(trig))
triggerDetails.appendChild(this.buildTriggerOptions(trig, triggerDiv));
if (trig.isMissingId) {
addTriggerDetail(
triggerDetails,
this.base.translate(kMiscTranslations.warning),
this.base.translate(kMiscTranslations.missingId),
);
}
if (trig.overriddenByFile !== undefined) {
const baseText = this.base.translate(kMiscTranslations.overriddenByFile);
const detailText = baseText.replace('${file}', trig.overriddenByFile);
addTriggerDetail(
triggerDetails,
this.base.translate(kMiscTranslations.warning),
detailText,
);
}
// Append some details about the trigger so it's more obvious what it is.
for (const [detailStringKey, opt] of Object.entries(detailKeys)) {
// Object.entries coerces to a string, but the detailKeys definition makes this true.
const detailKey = detailStringKey as keyof LooseTrigger;
if (opt.generatedManually)
continue;
if (!this.base.developerOptions && opt.debugOnly)
continue;
const trigOutput = trig.configOutput?.[detailKey];
const trigFunc = trig[detailKey];
if (trigFunc === undefined || trigFunc === null)
continue;
const detailCls = [opt.cls];
let detailText: string | undefined;
if (trigOutput !== undefined) {
detailText = trigOutput;
} else if (typeof trigFunc === 'function') {
detailText = this.base.translate(kMiscTranslations.valueIsFunction);
detailCls.push('function-text');
} else {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
detailText = trigFunc.toString();
}
addTriggerDetail(
triggerDetails,
this.base.translate(opt.label),
detailText,
detailCls,
);
}
if (!canBeConfigured(trig))
continue;
// Add beforeSeconds manually for timeline triggers.
if (trig.isTimelineTrigger) {
const detailKey = 'beforeSeconds';
const optionKey = kOptionKeys.beforeSeconds;
const label = document.createElement('div');
label.innerText = this.base.translate(kDetailKeys[detailKey].label);
label.classList.add('trigger-label');
triggerDetails.appendChild(label);
const div = document.createElement('div');
div.classList.add('option-input-container', 'trigger-before-seconds');
const input = document.createElement('input');
div.appendChild(input);
input.type = 'text';
input.step = 'any';
// Say "(default)" for more complicated things like functions.
let defaultValue = this.base.translate(kMiscTranslations.valueDefault);
if (trig.beforeSeconds === undefined)
defaultValue = '0';
else if (typeof trig.beforeSeconds === 'number')
defaultValue = trig.beforeSeconds.toString();
input.placeholder = defaultValue;
input.value = this.base.getStringOption('raidboss', [
kOptionKeys.triggers,
trigId,
optionKey,
], '');
const setFunc = () => {
const val = validDurationOrUndefined(input.value) || '';
this.base.setOption('raidboss', [kOptionKeys.triggers, trigId, optionKey], val);
};
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
// Add delay adjust manually, as this isn't a trigger field.
if (this.base.developerOptions) {
const detailKey = 'delayAdjust';
const optionKey = kOptionKeys.delayAdjust;
const label = document.createElement('div');
label.innerText = this.base.translate(kDetailKeys[detailKey].label);
label.classList.add('trigger-label');
triggerDetails.appendChild(label);
const div = document.createElement('div');
div.classList.add('option-input-container', 'trigger-delay-adjust');
const input = document.createElement('input');
div.appendChild(input);
input.type = 'text';
input.step = 'any';
input.placeholder = `0`;
input.value = this.base.getStringOption('raidboss', [
kOptionKeys.triggers,
trigId,
optionKey,
], '');
const setFunc = () => {
const val = validDelayAdjustOrUndefined(input.value) || '';
this.base.setOption('raidboss', [kOptionKeys.triggers, trigId, optionKey], val);
};
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
// Add duration manually with an input to override.
if (hasOutputFunc) {
const detailKey = 'duration';
const optionKey = kOptionKeys.duration;
const label = document.createElement('div');
label.innerText = this.base.translate(kDetailKeys[detailKey].label);
label.classList.add('trigger-label');
triggerDetails.appendChild(label);
const div = document.createElement('div');
div.classList.add('option-input-container', 'trigger-duration');
const input = document.createElement('input');
div.appendChild(input);
input.type = 'text';
input.step = 'any';
if (typeof trig.durationSeconds === 'number')
input.placeholder = `${trig.durationSeconds}`;
else
input.placeholder = this.base.translate(kMiscTranslations.valueDefault);
input.value = this.base.getStringOption('raidboss', [
kOptionKeys.triggers,
trigId,
optionKey,
], '');
const setFunc = () => {
const val = validDurationOrUndefined(input.value) || '';
this.base.setOption('raidboss', [kOptionKeys.triggers, trigId, optionKey], val);
};
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
// Add output strings manually
const outputStrings = trig.outputStrings || {};
for (const [key, outputString] of Object.entries(outputStrings)) {
const optionKey = kOptionKeys.outputStrings;
const template = typeof outputString === 'string'
? outputString
: this.base.translate(outputString);
const label = document.createElement('div');
label.innerText = key;
label.classList.add('trigger-outputstring-label');
triggerDetails.appendChild(label);
const div = document.createElement('div');
div.classList.add('option-input-container', 'trigger-outputstring');
const input = document.createElement('input');
div.appendChild(input);
input.type = 'text';
input.placeholder = template;
input.value = this.base.getStringOption(
'raidboss',
[kOptionKeys.triggers, trigId, optionKey, key],
'',
);
const setFunc = () =>
this.base.setOption(
'raidboss',
[kOptionKeys.triggers, trigId, optionKey, key],
input.value,
);
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
const label = document.createElement('div');
triggerDetails.appendChild(label);
const path = key.split('-');
const [p0, p1, p2] = path;
if (p0 !== undefined && p1 !== undefined && p2 !== undefined) {
const div = document.createElement('div');
div.classList.add('option-input-container', 'trigger-source');
const baseUrl = 'https://github.com/OverlayPlugin/cactbot/blob/triggers';
let urlFilepath;
if (path.length === 3) {
// 00-misc/general.js
urlFilepath = `${p0}-${p1}/${[...path].slice(2).join('-')}`;
} else {
// 02-arr/raids/t1.js
urlFilepath = `${p0}-${p1}/${p2}/${[...path].slice(3).join('-')}`;
}
const escapedTriggerId = trigId.replace(/'/g, '\\\'');
const uriComponent = encodeURIComponent(`id: '${escapedTriggerId}'`).replace(/'/g, '%27');
const urlString = `${baseUrl}/${urlFilepath}.js#:~:text=${uriComponent}`;
div.innerHTML = `<a href="${urlString}" target="_blank">(${
this.base.translate(kMiscTranslations.viewTriggerSource)
})</a>`;
triggerDetails.appendChild(div);
}
}
}
}
// Build the top level timeline editing expandable container.
buildTimelineUIContainer(
zoneId: number,
set: ConfigLooseTriggerSet,
parent: HTMLElement,
options: RaidbossOptions,
): void {
const container = document.createElement('div');
container.classList.add('timeline-edit-container', 'collapsed');
parent.appendChild(container);
let hasEverBeenExpanded = false;
const headerDiv = document.createElement('div');
headerDiv.classList.add('timeline-edit-header');
headerDiv.onclick = () => {
container.classList.toggle('collapsed');
// Build the rest of this UI on demand lazily.
if (!hasEverBeenExpanded) {
const text = this.timelineTextFromSet(set);
const timeline = new TimelineParser(text, set.timelineReplace ?? [], [], [], options);
this.buildTimelineListingUI(timeline, text, container);
this.buildTimelineAddUI(zoneId, container);
this.buildTimelineTextUI(zoneId, timeline, container);
}
hasEverBeenExpanded = true;
};
headerDiv.innerText = this.base.translate(kMiscTranslations.editTimeline);
container.appendChild(headerDiv);
}
timelineTextFromSet(set: ConfigLooseTriggerSet): string {
let text = '';
// Recursively turn the timeline array into a string.
const addTimeline = (obj?: TimelineField) => {
if (obj === undefined)
return;
if (Array.isArray(obj)) {
for (const objVal of obj)