-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
party-overview.js
103 lines (91 loc) · 3.53 KB
/
party-overview.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
import { currentSystemProvider, initApi } from "./module/api.js";
import PartyOverviewApp from "./module/logic.js";
import { registerApiSettings, registerSettings } from "./module/settings.js";
Hooks.once("init", () => {
registerSettings();
initApi();
registerApiSettings();
if (game.keybindings) {
game.keybindings.register("party-overview", "openPartyOverview", {
name: game.i18n.localize("party-overview.keybinds.open.name"),
hint: game.i18n.localize("party-overview.keybinds.open.hint"),
onDown: () => {
game.partyOverview.render(true);
},
onUp: () => {},
precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL,
});
game.keybindings.register("party-overview", "closePartyOverview", {
name: game.i18n.localize("party-overview.keybinds.close.name"),
hint: game.i18n.localize("party-overview.keybinds.close.hint"),
onDown: () => {
game.partyOverview.close();
},
onUp: () => {},
precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL,
});
game.keybindings.register("party-overview", "togglePartyOverview", {
name: game.i18n.localize("party-overview.keybinds.toggle.name"),
hint: game.i18n.localize("party-overview.keybinds.toggle.hint"),
onDown: () => {
if (!game.partyOverview.rendering) game.partyOverview.render(true);
else game.partyOverview.close();
},
onUp: () => {},
precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL,
});
}
return loadTemplates([
"modules/party-overview/templates/parts/Tabs.html",
"modules/party-overview/templates/parts/FilterButton.html",
"modules/party-overview/templates/parts/ToggleVisibilityButton.html",
"modules/party-overview/templates/parts/Languages.html",
...currentSystemProvider.loadTemplates,
]);
});
Hooks.on("ready", () => {
game.partyOverview = new PartyOverviewApp();
if (game.modules.get("stream-view")?.active && game?.user?.id === game.settings.get("stream-view", "user-id")) game.partyOverview.render(true);
});
Hooks.on("renderActorDirectory", (app, html, data) => {
if (!game.user.isGM && !game.settings.get("party-overview", "EnablePlayerAccess")) return;
let button = $(`<button class="party-overview-button ${currentSystemProvider.customCSS}"><i class="fas fa-users"></i> Party Overview</button>`);
button.on("click", (e) => {
game.partyOverview.render(true);
});
$(html).find(".header-actions").prepend(button);
});
Hooks.on("updateActor", (actor, data, options, userId) => {
if (game.partyOverview.rendering && actor.hasPlayerOwner) {
game.partyOverview.render(false);
}
});
Hooks.on("updateToken", (token, data, options, userId) => {
if (game.partyOverview.rendering && token.actor?.hasPlayerOwner) {
game.partyOverview.render(false);
}
});
Hooks.on("createToken", (token, options, userId) => {
if (game.partyOverview.rendering && game.actors.contents.find((actor) => actor.id === token.actor.id).hasPlayerOwner) {
game.partyOverview.render(false);
}
});
Hooks.on("deleteActor", (actor, options, userId) => {
if (game.partyOverview.rendering && actor.hasPlayerOwner) {
game.partyOverview.render(false);
}
});
Hooks.on("deleteToken", (token, options, userId) => {
if (game.partyOverview.rendering && token.actor?.hasPlayerOwner) {
game.partyOverview.render(false);
}
});
Hooks.on("canvasInit", (canvas) => {
if (game.partyOverview?.rendering) {
// what a hack! the hook is fired when the scene switch is not yet activated, so we need
// to wait a tiny bit. The combat tracker is rendered last, so the scene should be available
Hooks.once("renderCombatTracker", (app, html, data) => {
game.partyOverview.render(false);
});
}
});