forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathoopsyraidsy.ts
93 lines (80 loc) · 3.58 KB
/
oopsyraidsy.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
import { UnreachableCode } from '../../resources/not_reached';
import { addOverlayListener, callOverlayHandler } from '../../resources/overlay_plugin_api';
import PartyTracker from '../../resources/party';
import UserConfig from '../../resources/user_config';
import { OopsyMistakeType } from '../../types/oopsy';
import { DamageTracker } from './damage_tracker';
import oopsyFileData from './data/oopsy_manifest.txt';
import { MistakeCollector } from './mistake_collector';
import { OopsyLiveList } from './oopsy_live_list';
import defaultOptions from './oopsy_options';
import { OopsySummaryList, OopsySummaryTable } from './oopsy_summary_list';
import './oopsyraidsy_config';
import '../../resources/defaults.css';
import './oopsy_common.css';
export const addDebugInfo = (collector: MistakeCollector, numMistakes: number): void => {
// TODO: maybe this should use the fake_name_generator.
const names = [
'Tini Poutini',
'Potato Chippy',
'Papas Fritas',
'Tater Tot',
'Hash Brown',
'French Fry',
];
const types: OopsyMistakeType[] = ['death', 'fail', 'warn', 'pull'];
// TODO: this should probably start/stop combat too for the summary page?
let fakeTimestamp = 0;
collector.StartEncounter(fakeTimestamp);
for (let i = 0; i < numMistakes; ++i) {
fakeTimestamp += 1000;
collector.OnMistakeObj(fakeTimestamp, {
type: types[Math.floor(Math.random() * types.length)] ?? 'good',
blame: names[Math.floor(Math.random() * names.length)],
text: 'stuff',
});
}
};
// Note: changes to this setup function should be reflected in
// oopsy_viewer as well.
UserConfig.getUserConfigLocation('oopsyraidsy', defaultOptions, () => {
const options = { ...defaultOptions };
const partyTracker = new PartyTracker(options);
const mistakeCollector = new MistakeCollector(options, true);
const summaryElement = document.getElementById('summary');
const liveListElement = document.getElementById('livelist');
// Choose the ui based on whether this is the summary view or the live list.
// They have different elements in the file.
if (summaryElement) {
const listView = new OopsySummaryList(options, summaryElement, partyTracker);
mistakeCollector.AddObserver(listView);
const tableElement = document.getElementById('mistake-table');
if (!tableElement)
throw new UnreachableCode();
const table = new OopsySummaryTable(tableElement, partyTracker);
mistakeCollector.AddObserver(table);
} else if (liveListElement) {
const listView = new OopsyLiveList(options, liveListElement, partyTracker);
mistakeCollector.AddObserver(listView);
addOverlayListener(
'onInCombatChangedEvent',
(e) => listView.SetInCombat(e.detail.inGameCombat),
);
} else {
throw new UnreachableCode();
}
// NOTE: add "debug=1" url parameter to add extra events.
const params = new URLSearchParams(window.location.search);
// FIXME: should this consider the value?
if (typeof params.get('debug') === 'string')
addDebugInfo(mistakeCollector, 2200);
const damageTracker = new DamageTracker(options, mistakeCollector, partyTracker, oopsyFileData);
addOverlayListener('LogLine', (e) => damageTracker.OnNetLog(e));
addOverlayListener('onPlayerChangedEvent', (e) => damageTracker.OnPlayerChange(e));
addOverlayListener('ChangeZone', (e) => damageTracker.OnChangeZone(e));
addOverlayListener('onInCombatChangedEvent', (e) => {
damageTracker.OnInCombatChangedEvent(e);
});
addOverlayListener('BroadcastMessage', (e) => mistakeCollector.OnBroadcastMessage(e));
void callOverlayHandler({ call: 'cactbotRequestPlayerUpdate' });
});