forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raidboss_config.js
1429 lines (1320 loc) · 42.7 KB
/
raidboss_config.js
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 PartyTracker from '../../resources/party';
import Regexes from '../../resources/regexes';
import { triggerOutputFunctions } from '../../resources/responses';
import UserConfig from '../../resources/user_config';
import Util from '../../resources/util';
import raidbossFileData from './data/manifest.txt';
import raidbossOptions from './raidboss_options';
const kOptionKeys = {
output: 'Output',
duration: 'Duration',
beforeSeconds: 'BeforeSeconds',
outputStrings: 'OutputStrings',
};
// 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: '❌ 비활성화',
},
},
};
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: '网络日志正则表达式',
},
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: '提前 (秒)',
},
cls: 'before-seconds-text',
generatedManually: true,
},
'condition': {
label: {
en: 'condition',
de: 'condition',
fr: 'condition',
ja: '条件',
cn: '条件',
ko: '조건',
},
cls: 'condition-text',
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,
},
};
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: '(函数)',
},
// Warning label for triggers without ids or overridden triggers.
warning: {
en: '⚠️ warning',
de: '⚠️ Warnung',
fr: '⚠️ Attention',
ja: '⚠️ 警告',
cn: '⚠️ 警告',
},
// Shows up for triggers without ids.
missingId: {
en: 'missing id field',
de: 'Fehlendes ID Feld',
fr: 'Champ ID manquant',
ja: 'idがありません',
cn: '缺少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}"文件覆盖',
},
};
const validDurationOrUndefined = (val) => {
val = parseFloat(val);
if (!isNaN(val) && val >= 0)
return val;
return undefined;
};
const canBeConfigured = (trig) => !trig.isMissingId && !trig.overriddenByFile;
const addTriggerDetail = (container, labelText, detailText, detailCls) => {
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.
function setOptionsFromOutputValue(options, value) {
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 {
console.error('unknown output type: ' + value);
}
}
// Helper for doing nothing during trigger eval, but still recording any
// calls to `output.responseOutputStrings = x;` via callback.
class DoNothingFuncProxy {
constructor(outputStringsCallback) {
return new Proxy(this, {
set(target, property, value) {
if (property === 'responseOutputStrings') {
outputStringsCallback(value);
return true;
}
// Ignore other property setting here.
},
get(target, name) {
return () => {};
},
});
}
}
class RaidbossConfigurator {
constructor(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 = this.base.getOption('raidboss', 'AlertsLanguage', this.base.lang);
this.timelineLang = this.base.getOption('raidboss', 'TimelineLanguage', this.base.lang);
}
buildUI(container, raidbossFiles, userOptions) {
const fileMap = this.processRaidbossFiles(raidbossFiles, userOptions);
const expansionDivs = {};
for (const key in fileMap) {
const info = fileMap[key];
// "expansion" here is technically section, which includes "general triggers"
// and one section per user file.
const expansion = info.section;
if (Object.keys(info.triggers).length === 0)
continue;
if (!expansionDivs[expansion]) {
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);
expansionDivs[expansion] = expansionContainer;
}
const triggerContainer = document.createElement('div');
triggerContainer.classList.add('trigger-file-container', 'collapsed');
expansionDivs[expansion].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 (let i = 0; i < parts.length; ++i) {
if (!parts[i])
continue;
const partDiv = document.createElement('div');
partDiv.classList.add('trigger-file-header-part');
partDiv.innerText = parts[i];
headerDiv.appendChild(partDiv);
}
triggerContainer.appendChild(headerDiv);
const triggerOptions = document.createElement('div');
triggerOptions.classList.add('trigger-file-options');
triggerContainer.appendChild(triggerOptions);
for (const id in info.triggers) {
const trig = info.triggers[id];
// Don't construct triggers that won't show anything.
let hasOutputFunc = false;
for (const func of triggerOutputFunctions) {
if (trig[func]) {
hasOutputFunc = true;
break;
}
}
if (!hasOutputFunc && !this.base.developerOptions)
continue;
// Build the trigger label.
const triggerDiv = document.createElement('div');
triggerDiv.innerHTML = trig.isMissingId ? '(???)' : trig.id;
triggerDiv.classList.add('trigger');
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) {
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 detailKey in kDetailKeys) {
if (kDetailKeys[detailKey].generatedManually)
continue;
if (!this.base.developerOptions && kDetailKeys[detailKey].debugOnly)
continue;
if (!trig[detailKey] && !trig.output[detailKey])
continue;
const detailCls = [kDetailKeys[detailKey].cls];
let detailText;
if (trig.output[detailKey]) {
detailText = trig.output[detailKey];
} else if (typeof trig[detailKey] === 'function') {
detailText = this.base.translate(kMiscTranslations.valueIsFunction);
detailCls.push('function-text');
} else {
detailText = trig[detailKey];
}
addTriggerDetail(triggerDetails,
this.base.translate(kDetailKeys[detailKey].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 = kMiscTranslations.valueDefault;
if (trig.beforeSeconds === undefined)
defaultValue = 0;
else if (typeof trig.beforeSeconds === 'number')
defaultValue = trig.beforeSeconds;
input.placeholder = this.base.translate(defaultValue);
input.value = this.base.getOption('raidboss', 'triggers', trig.id, optionKey, '');
const setFunc = () => {
const val = validDurationOrUndefined(input.value) || '';
this.base.setOption('raidboss', 'triggers', trig.id, 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';
input.placeholder = this.base.translate(kMiscTranslations.valueDefault);
input.value = this.base.getOption('raidboss', 'triggers', trig.id, optionKey, '');
const setFunc = () => {
const val = validDurationOrUndefined(input.value) || '';
this.base.setOption('raidboss', 'triggers', trig.id, optionKey, val);
};
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
// Add output strings manually
const outputStrings = trig.outputStrings || {};
for (const key in outputStrings) {
const optionKey = kOptionKeys.outputStrings;
const template = this.base.translate(outputStrings[key]);
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.getOption('raidboss', 'triggers', trig.id, optionKey, key, '');
const setFunc = () => this.base.setOption('raidboss', 'triggers', trig.id, optionKey, key, input.value);
input.onchange = setFunc;
input.oninput = setFunc;
triggerDetails.appendChild(div);
}
}
}
}
// This duplicates the raidboss function of the same name.
valueOrFunction(f, data, matches, output) {
const result = (typeof f === 'function') ? f(data, matches, output) : f;
if (result !== Object(result))
return result;
if (result[this.alertsLang])
return this.valueOrFunction(result[this.alertsLang]);
if (result[this.timelineLang])
return this.valueOrFunction(result[this.timelineLang]);
// For partially localized results where this localization doesn't
// exist, prefer English over nothing.
return this.valueOrFunction(result['en']);
}
processTrigger(trig) {
// TODO: with some hackiness (e.g. regexes?) we could figure out which
// output string came from which alert type (alarm, alert, info, tts).
trig.output = new DoNothingFuncProxy((outputStrings) => {
trig.outputStrings = trig.outputStrings || {};
Object.assign(trig.outputStrings, outputStrings);
});
const kBaseFakeData = {
party: new PartyTracker(),
lang: this.base.lang,
currentHP: 1000,
options: this.base.configOptions,
ShortName: (x) => x,
StopCombat: () => {},
ParseLocaleFloat: parseFloat,
CanStun: () => Util.canStun(this.job),
CanSilence: () => Util.canSilence(this.job),
CanSleep: () => Util.canSleep(this.job),
CanCleanse: () => Util.canCleanse(this.job),
CanFeint: () => Util.canFeint(this.job),
CanAddle: () => Util.canAddle(this.job),
};
const kFakeData = [
{
me: 'Tini Poutini',
job: 'GNB',
role: 'tank',
},
{
me: 'Potato Chippy',
job: 'WHM',
role: 'healer',
},
{
me: 'Tater Tot',
job: 'BLM',
role: 'dps',
},
{
me: 'Hash Brown',
job: 'DRG',
role: 'dps',
},
{
me: 'Aloo Gobi',
job: 'BLU',
role: 'dps',
},
];
for (let i = 0; i < kFakeData.length; ++i)
kFakeData[i] = Object.assign({}, kFakeData[i], kBaseFakeData);
const kFakeMatches = {
// TODO: really should convert all triggers to use regexes.js.
// Mooooost triggers use matches[1] to be a name.
1: kFakeData[0].me,
sourceId: '41234567',
source: 'Enemy',
id: '1234',
ability: 'Ability',
targetId: '1234567',
target: kFakeData[0].me,
flags: '',
x: 100,
y: 100,
z: 0,
heading: 0,
npcId: undefined,
effect: 'Effect',
duration: 30,
code: '00',
line: '',
name: 'Name',
capture: true,
};
const output = {};
const keys = ['alarmText', 'alertText', 'infoText', 'tts', 'sound'];
// Try to determine some sample output?
// This could get much more complicated if we wanted it to.
const evalTrigger = (trig, key, idx) => {
try {
const result = this.valueOrFunction(trig[key], kFakeData[idx], kFakeMatches, trig.output);
if (!result)
return false;
// Super hack:
if (result.includes('undefined') || result.includes('NaN'))
return false;
output[key] = result;
return true;
} catch (e) {
// This is all totally bogus. Many triggers assume fields on data
// are properly defined when these calls happen, so will throw errors.
// So just silently ignore.
return false;
}
};
// Handle 'response' first.
if (trig.response) {
const r = trig.response;
for (let d = 0; d < kFakeData.length; ++d) {
try {
// Can't use ValueOrFunction here as r returns a non-localizable object.
// FIXME: this hackily replicates some raidboss logic too.
let response = r;
while (typeof response === 'function') {
// TODO: check if this has builtInResponseStr first.
response = response(kFakeData[d], kFakeMatches, trig.output);
}
if (!response)
continue;
if (!trig.outputStrings) {
for (const key of keys)
evalTrigger(response, key, d);
}
break;
} catch (e) {
continue;
}
}
}
// Only evaluate fields if there are not outputStrings.
// outputStrings will indicate more clearly what the trigger says.
if (!trig.outputStrings) {
for (const key of keys) {
if (!trig[key])
continue;
for (let d = 0; d < kFakeData.length; ++d) {
if (evalTrigger(trig, key, d))
break;
}
}
}
trig.output = output;
const lang = this.base.lang;
const getRegex = (baseField) => {
const shortLanguage = lang.charAt(0).toUpperCase() + lang.slice(1);
const langSpecificRegex = trig[baseField + shortLanguage] || trig[baseField];
if (!langSpecificRegex)
return;
const baseRegex = Regexes.parse(langSpecificRegex);
if (!baseRegex)
return;
return Regexes.parse(baseRegex);
};
if (trig.isTimelineTrigger) {
trig.timelineRegex = getRegex('regex');
} else {
trig.triggerRegex = getRegex('regex');
trig.triggerNetRegex = getRegex('netRegex');
}
return trig;
}
processRaidbossFiles(files, userOptions) {
// `files` is map of filename => triggerSet (for trigger files)
// `map` is a sorted map of shortened zone key => { various fields, triggerSet }
const map = this.base.processFiles(files, userOptions.Triggers);
let triggerIdx = 0;
// While walking through triggers, record any previous triggers with the same
// id so that the ui can disable overriding information.
const previousTriggerWithId = {};
for (const [key, item] of Object.entries(map)) {
// TODO: maybe each trigger set needs a zone name, and we should
// use that instead of the filename???
const rawTriggers = {
trigger: [],
timeline: [],
};
const triggerSet = item.triggerSet;
if (triggerSet.triggers)
rawTriggers.trigger.push(...triggerSet.triggers);
if (triggerSet.timelineTriggers)
rawTriggers.timeline.push(...triggerSet.timelineTriggers);
item.triggers = {};
for (const key in rawTriggers) {
for (const trig of rawTriggers[key]) {
triggerIdx++;
if (!trig.id) {
// Give triggers with no id some "unique" string so that they can
// still be added to the set and show up in the ui.
trig.id = `!!NoIdTrigger${triggerIdx}`;
trig.isMissingId = true;
}
// Track if this trigger overrides any previous trigger.
const previous = previousTriggerWithId[trig.id];
if (previous)
previous.overriddenByFile = triggerSet.filename;
previousTriggerWithId[trig.id] = trig;
trig.isTimelineTrigger = key === 'timeline';
// Also, if a user has two of the same id in the same triggerSet (?!)
// then only the second trigger will show up.
item.triggers[trig.id] = this.processTrigger(trig);
}
}
}
return map;
}
buildTriggerOptions(trig, labelDiv) {
const optionKey = kOptionKeys.output;
const div = document.createElement('div');
div.classList.add('trigger-options');
const updateLabel = (input) => {
if (input.value === 'hidden' || input.value === 'disabled')
labelDiv.classList.add('disabled');
else
labelDiv.classList.remove('disabled');
};
const input = document.createElement('select');
div.appendChild(input);
const selectValue = this.base.getOption('raidboss', 'triggers', trig.id, optionKey, 'default');
for (const key in kTriggerOptions) {
// Hide debug only options unless they are selected.
// Otherwise, it will look weird to pick something like 'Disabled',
// but then not show it when developer options are turned off.
if (!this.base.developerOptions && kTriggerOptions[key].debugOnly && key !== selectValue)
continue;
const elem = document.createElement('option');
elem.innerHTML = this.base.translate(kTriggerOptions[key].label);
elem.value = key;
elem.selected = key === selectValue;
input.appendChild(elem);
updateLabel(input);
input.onchange = () => {
updateLabel(input);
let value = input.value;
if (value.includes('default'))
value = 'default';
this.base.setOption('raidboss', 'triggers', trig.id, optionKey, input.value);
};
}
return div;
}
}
// Raidboss needs to do some extra processing of user files.
const userFileHandler = (name, files, options, basePath) => {
if (!options.Triggers)
return;
for (const set of options.Triggers) {
// Annotate triggers with where they came from. Note, options is passed in repeatedly
// as multiple sets of user files add triggers, so only process each file once.
if (set.isUserTriggerSet)
continue;
// `filename` here is just cosmetic for better debug printing to make it more clear
// where a trigger or an override is coming from.
set.filename = `${basePath}${name}`;
set.isUserTriggerSet = true;
// Convert set.timelineFile to set.timeline.
if (set.timelineFile) {
const lastIndex = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\'));
// If lastIndex === -1, truncate name to the empty string.
// if lastIndex > -1, truncate name after the final slash.
const dir = name.substring(0, lastIndex + 1);
const timelineFile = `${dir}${set.timelineFile}`;
delete set.timelineFile;
if (!(timelineFile in files)) {
console.log(`ERROR: '${name}' specifies non-existent timeline file '${timelineFile}'.`);
continue;
}
// set.timeline is processed recursively.
set.timeline = [set.timeline, files[timelineFile]];
}
}
};
const templateOptions = {
buildExtraUI: (base, container) => {
const builder = new RaidbossConfigurator(base);
const userOptions = { ...raidbossOptions };
UserConfig.loadUserFiles('raidboss', userOptions, () => {
builder.buildUI(container, raidbossFileData, userOptions);
});
},
processExtraOptions: (options, savedConfig) => {
// raidboss will look up this.options.PerTriggerAutoConfig to find these values.
const optionName = 'PerTriggerAutoConfig';
options[optionName] = options[optionName] || {};
const triggers = savedConfig.triggers;
if (!triggers)
return;
const perTrigger = options[optionName];
const outputObjs = {};
const keys = Object.keys(kTriggerOptions);
for (const key of keys) {
outputObjs[key] = {};
setOptionsFromOutputValue(outputObjs[key], key);
}
for (const id in triggers) {
const autoConfig = {};
const output = triggers[id][kOptionKeys.output];
if (output)
Object.assign(autoConfig, outputObjs[output]);
const duration = validDurationOrUndefined(triggers[id][kOptionKeys.duration]);
if (duration)
autoConfig[kOptionKeys.duration] = duration;
const beforeSeconds = validDurationOrUndefined(triggers[id][kOptionKeys.beforeSeconds]);
if (beforeSeconds)
autoConfig[kOptionKeys.beforeSeconds] = beforeSeconds;
const outputStrings = triggers[id][kOptionKeys.outputStrings];
if (outputStrings)
autoConfig[kOptionKeys.outputStrings] = outputStrings;
if (output || duration || outputStrings)
perTrigger[id] = autoConfig;
}
},
options: [
{
id: 'Debug',
name: {
en: 'Enable debug mode',
de: 'Aktiviere Debugmodus',
fr: 'Activer le mode debug',
ja: 'デバッグモードを有効にする',
cn: '启用调试模式',
ko: '디버그 모드 활성화',
},
type: 'checkbox',
debugOnly: true,
},
{
id: 'DefaultAlertOutput',
name: {
en: 'Default alert output',
de: 'Standard Alert Ausgabe',
fr: 'Alerte par défaut',
ja: '警告情報出力既定値',
cn: '默认警报提示信息输出方式',
ko: '기본 알람 출력 방식',
},
type: 'select',
options: {
en: {
'🆙🔊 Text and Sound': 'textAndSound',
'🆙💬 Text and TTS': 'ttsAndText',
'💬 TTS Only': 'ttsOnly',
'🆙 Text Only': 'textOnly',
'❌ Disabled': 'disabled',
},
de: {
'🆙🔊 Text und Ton': 'textAndSound',
'🆙💬 Text und TTS': 'ttsAndText',
'💬 Nur TTS': 'ttsOnly',
'🆙 Nur Text': 'textOnly',
'❌ Deaktiviert': 'disabled',
},
fr: {
'🆙🔊 Texte et son': 'textAndSound',
'🆙💬 Texte et TTS': 'ttsAndText',
'💬 TTS seulement': 'ttsOnly',
'🆙 Texte seulement': 'textOnly',
'❌ Désactivé': 'disabled',
},
ja: {
'🆙🔊 テキストと音声': 'textAndSound',
'🆙💬 テキストとTTS': 'ttsAndText',