This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
maestro.js
215 lines (186 loc) · 5.92 KB
/
maestro.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
// @ts-check
import CombatTrack from "./modules/combat-track.js";
import HypeTrack from "./modules/hype-track.js";
import ItemTrack from "./modules/item-track.js";
import { migrationHandler } from "./modules/migration.js";
import * as Misc from "./modules/misc.js";
import * as Playback from "./modules/playback.js";
import { registerModuleSettings } from "./modules/settings.js";
/**
* Orchestrates (pun) module functionality
*/
export default class Conductor {
static begin() {
Conductor._hookOnInit();
Conductor._hookOnReady();
}
/**
* Init Hook
*/
static async _hookOnInit() {
Hooks.on("init", async () => {
game.maestro = {};
await registerModuleSettings();
Conductor._initHookRegistrations();
});
}
/**
* Ready Hook
*/
static async _hookOnReady() {
Hooks.on("ready", async () => {
game.maestro.hypeTrack = new HypeTrack();
game.maestro.itemTrack = new ItemTrack();
game.maestro.combatTrack = new CombatTrack();
HypeTrack._onReady();
ItemTrack._onReady();
CombatTrack._onReady();
Misc._checkForCriticalPlaylist();
Misc._checkForFailurePlaylist();
// Macros/external methods
game.maestro.pause = Playback.pauseSounds;
game.maestro.playByName = Playback.playSoundByName;
game.maestro.findSound = Playback.findPlaylistSound;
game.maestro.pauseAll = Playback.pauseAll;
game.maestro.resume = Playback.resumeSounds;
//Set a timeout to allow the sheets to register correctly before we try to hook on them
window.setTimeout(Conductor._readyHookRegistrations, 500);
//Conductor._readyHookRegistrations();
if (game.version >= "0.4.4" && Misc.isFirstGM()) {
game.maestro.migration = {};
migrationHandler();
}
});
}
/**
* Init Hook Registrations
*/
static _initHookRegistrations() {
Conductor._hookOnRenderPlaylistDirectory();
}
/**
* Ready Hook Registrations
*/
static _readyHookRegistrations() {
// Sheet/App Render Hooks
Conductor._hookOnRenderActorSheet();
Conductor._hookOnRenderItemSheet();
Conductor._hookOnRenderChatMessage();
Conductor._hookOnRenderCombatTrackerConfig();
// Pre-Create Hooks
Conductor._hookOnPreCreateChatMessage();
// Pre-update Hooks
Conductor._hookOnPreUpdatePlaylistSound();
Conductor._hookOnPreUpdatePlaylist();
Conductor._hookOnPreUpdateCombat();
// Update Hooks
Conductor._hookOnUpdateCombat();
//Conductor._hookOnUpdatePlaylist();
// Delete hooks
Conductor._hookOnDeleteCombat();
Conductor._hookOnDeleteItem();
}
/**
* PreUpdate Playlist Hook
*/
static _hookOnPreUpdatePlaylist() {
Hooks.on("preUpdatePlaylist", (playlist, update, options, userId) => {
// unused
});
}
/**
* PreUpdate Playlist Sound Hook
*/
static _hookOnPreUpdatePlaylistSound() {
Hooks.on("preUpdatePlaylistSound", (sound, update, options, userId) => {
Misc._onPreUpdatePlaylistSound(sound, update, options, userId);
});
}
/**
* PreCreate Chat Message Hook
*/
static _hookOnPreCreateChatMessage() {
Hooks.on("preCreateChatMessage", (message, options, userId) => {
Misc._onPreCreateChatMessage(message, options);
});
}
static _hookOnDeleteItem() {
Hooks.on("deleteItem", (item, options, userId) => {
ItemTrack._onDeleteItem(item, options, userId);
});
}
/**
* PreUpdate Combat Hook
*/
static _hookOnPreUpdateCombat() {
Hooks.on("preUpdateCombat", (combat, update, options, userId) => {
CombatTrack._onPreUpdateCombat(combat, update, options, userId);
});
}
/**
* Update Combat Hook
*/
static _hookOnUpdateCombat() {
Hooks.on("updateCombat", (combat, update, options, userId) => {
HypeTrack._onUpdateCombat(combat, update, options, userId);
CombatTrack._onUpdateCombat(combat, update, options, userId);
});
}
/**
* Delete Combat Hook
*/
static _hookOnDeleteCombat() {
Hooks.on("deleteCombat", (combat, options, userId) => {
HypeTrack._onDeleteCombat(combat, options, userId);
CombatTrack._onDeleteCombat(combat, options, userId);
});
}
/**
* Render Actor SheetsHook
*/
static _hookOnRenderActorSheet() {
Hooks.on("renderActorSheet", (app, html, data) => {
HypeTrack._onRenderActorSheet(app, html, data);
});
}
/**
* RenderChatMessage Hook
*/
static _hookOnRenderChatMessage() {
Hooks.on("renderChatMessage", (message, html, data) => {
ItemTrack._onRenderChatMessage(message, html, data);
Misc._onRenderChatMessage(message, html, data);
})
}
/**
* RenderPlaylistDirectory Hook
*/
static _hookOnRenderPlaylistDirectory() {
Hooks.on("renderPlaylistDirectory", (app, html, data) => {
Misc._onRenderPlaylistDirectory(app, html, data);
});
}
/**
* Render CombatTrackerConfig Hook
*/
static _hookOnRenderCombatTrackerConfig() {
Hooks.on("renderCombatTrackerConfig", (app, html, data) => {
CombatTrack._onRenderCombatTrackerConfig(app, html, data);
});
}
/**
* Render Item Sheet Hook
*/
static _hookOnRenderItemSheet() {
Hooks.on("renderItemSheet", (app, html, data) => {
ItemTrack._onRenderItemSheet(app, html, data);
});
}
}
/**
* Tap, tap, tap, ahem
* Shall we begin?
*
* Initiates the module
*/
Conductor.begin();