forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 44
/
raidboss.ts
102 lines (86 loc) · 3.72 KB
/
raidboss.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
import { addOverlayListener } from '../../resources/overlay_plugin_api';
import { addRemotePlayerSelectUI } from '../../resources/player_override';
import UserConfig from '../../resources/user_config';
import raidbossFileData from './data/raidboss_manifest.txt';
import { HTMLTimelineUI } from './html_timeline_ui';
import { PopupText, PopupTextGenerator } from './popup-text';
import defaultOptions from './raidboss_options';
import { TimelineController, TimelineLoader } from './timeline';
import '../../resources/timerbar';
import './raidboss_config';
import '../../resources/defaults.css';
import './raidboss.css';
UserConfig.getUserConfigLocation('raidboss', defaultOptions, () => {
const options = { ...defaultOptions };
// Query params override default and user options.
// This allows for html files that say "timeline only" or "alerts only".
const params = new URLSearchParams(window.location.search);
options.IsRemoteRaidboss = false;
const overlayWsParam = params.get('OVERLAY_WS');
if (overlayWsParam !== null) {
const wsParam = decodeURIComponent(overlayWsParam);
// TODO: is there a better way to do this?? This seems better than looking for ngrok.
const isLocal = wsParam.includes('localhost') || wsParam.includes('127.0.0.1');
options.IsRemoteRaidboss = !isLocal;
}
const playerNameParam = params.get('player');
if (playerNameParam !== null) {
options.PlayerNameOverride = playerNameParam;
console.log(`Enabling player name override via query parameter, name: ${playerNameParam}`);
}
if (options.IsRemoteRaidboss && playerNameParam === null) {
const lang = options.DisplayLanguage || options.ParserLanguage || 'en';
addRemotePlayerSelectUI(lang);
// Page will reload once player selected.
return;
}
const ttsParam = params.get('forceTTS');
if (ttsParam !== null) {
const forceEnable = !!parseInt(ttsParam);
if (forceEnable) {
options.SpokenAlertsEnabled = true;
console.log('Force enabling TTS via query parameter');
}
}
const alertsParam = params.get('alerts');
if (alertsParam !== null) {
const previous = options.AlertsEnabled;
options.AlertsEnabled = !!parseInt(alertsParam);
if (!previous && options.AlertsEnabled)
console.log('Enabling alerts via query parameter');
}
const timelineParam = params.get('timeline');
if (timelineParam !== null) {
const previous = options.TimelineEnabled;
options.TimelineEnabled = !!parseInt(timelineParam);
if (!previous && options.TimelineEnabled)
console.log('Enabling timeline via query parameter');
}
const audioParam = params.get('audio');
if (audioParam !== null) {
const previous = options.AudioAllowed;
options.AudioAllowed = !!parseInt(audioParam);
if (!previous && options.AudioAllowed)
console.log('Enabling audio via query parameter');
}
const container = document.getElementById('container');
if (!container)
throw new Error('Unable to find container element');
if (!options.AlertsEnabled)
container.classList.add('hide-alerts');
if (!options.TimelineEnabled)
container.classList.add('hide-timeline');
const timelineUI = new HTMLTimelineUI(options);
const timelineController = new TimelineController(options, timelineUI, raidbossFileData);
const timelineLoader = new TimelineLoader(timelineController);
const popupText = new PopupText(options, timelineLoader, raidbossFileData);
// Connect the timelines to the popup text, if alerts are desired.
if (options.AlertsEnabled)
timelineController.SetPopupTextInterface(new PopupTextGenerator(popupText));
addOverlayListener('onLogEvent', (e) => {
timelineController.OnLogEvent(e);
});
addOverlayListener('LogLine', (e) => {
timelineController.OnNetLog(e);
});
});