-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
85 lines (73 loc) · 2.95 KB
/
main.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
import { UnKennySheet } from "../apps/unkenny-sheet.js";
import { getConversationWithFlagSync, overwriteChatMessage, removeAllMessagesFromUnKennyConversation, removeMessageFromUnKennyConversation } from "./collecting-chat-messages.js";
import { registerGameParameters } from "./settings.js";
import { adjustHtml } from "./chat-message-rendering.js";
import { confirmationDialog } from "../apps/confirmation-dialogue.js";
import './chat-autocomplete.js';
// CONFIG.debug.hooks = true;
const UNKENNY_ICON = "fas fa-microchip";
const REMOVE_FROM_CONVERSATION = '<i class="fas fa-comment-slash"></i>';
function setupHooks() {
Hooks.once('init', function () {
// When Foundry loads ChatMessages from the database, it needs to initialise them with out class.
// Otherwise, the instanceof check when modifying a message will sporadically fail.
// This is the reason for this early overwrite.
overwriteChatMessage();
registerGameParameters();
});
Hooks.once('setup', function () {
// In case other modules overwrite the ChatMessage class as well, but do not inherit from the current class,
// we need to overwrite it again after all modules have been set up.
// This is the reason for this late overwrite.
overwriteChatMessage();
});
Hooks.on("getActorSheetHeaderButtons", function (sheet, buttons) {
const label = game.i18n.localize("unkenny.sheet.title");
buttons.unshift({
label: label,
class: "modify-UnKenniness",
icon: UNKENNY_ICON,
onclick: () => {
new UnKennySheet(sheet.object).render(true);
}
})
});
Hooks.on('renderChatLog', (app, html, data) => {
const label = game.i18n.localize("unkenny.chatLog.clearConversations");
const buttonHtml = `
<a aria-label="${label}" role="button" class="clear-unkenniness" data-tooltip="${label}">
${REMOVE_FROM_CONVERSATION}
</a>`;
const button = $(buttonHtml);
html.find('.control-buttons').append(button);
button.on('click', function () {
confirmationDialog({
title: label,
content: game.i18n.localize("unkenny.chatLog.clearConversationsConfirmation"),
yesCallback: () => {
removeAllMessagesFromUnKennyConversation(game.messages.contents);
}
});
});
});
Hooks.on("renderChatMessage", function (message, html, data) {
adjustHtml(message, html);
});
Hooks.on('getChatLogEntryContext', (html, options) => {
options.push({
name: game.i18n.localize("unkenny.chatLog.removeFromConversation"),
icon: REMOVE_FROM_CONVERSATION,
condition: listItem => {
const message = game.messages.get(listItem.data("messageId"));
const conversationWith = getConversationWithFlagSync(message);
return conversationWith;
},
callback: listItem => {
const message = game.messages.get(listItem.data("messageId"));
removeMessageFromUnKennyConversation(message);
}
});
});
}
setupHooks();
export { setupHooks };