forked from mclemente/healthEstimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthEstimate.js
95 lines (85 loc) · 2.87 KB
/
healthEstimate.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
import {registerSettings} from './module/settings.js';
import {preloadTemplates} from './module/preloadTemplates.js';
import {prepareSystemSpecifics} from "./module/systemSpecifics.js";
import {HealthEstimate, getCharacters, outputChat, outputStageChange, updateSettings} from "./module/logic.js";
/**
* Preload templates and add it template to the HUD
*/
Hooks.once('init', async function () {
await preloadTemplates();
Hooks.on('renderHeadsUpDisplay', (app, html, data) => {
html.append('<template id="healthEstimate"></template>');
});
});
/**
* Have to register Settings here, because doing so at init breaks i18n
*/
Hooks.once('setup', function () {
prepareSystemSpecifics().then(registerSettings());
});
Hooks.once('ready', function () {
new HealthEstimate();
});
/**
* HP storing code for canvas load or token created
*/
Hooks.on('canvasReady', function(){
let tokens = canvas.tokens.placeables.filter(e => e.actor);
updateSettings();
getCharacters(tokens);
});
Hooks.on('createToken', function(){
let tokens = canvas.tokens.placeables.filter(e => e.actor);
getCharacters(tokens);
});
/**
* spam in chat if token (NPC) is updated
* only the USER that promoted the change will spam the message
* start collectting all PNC hp information
*/
Hooks.on("updateToken", (scene, token, updateData, options, userId) => {
if(game.user.isGM && outputChat) {
let actors = canvas.tokens.placeables.filter(e=> e.actor);
outputStageChange(actors);
}
});
/**
* spam in chat if the actor is updated
* only the USER that promoted the change will spam the message
* start collectting all PNC hp information
*/
Hooks.on('updateActor', (data, options, apps, userId) => {
if(game.user.isGM && outputChat) {
let actors = canvas.tokens.placeables.filter(e=> e.actor && e.actor.data.type==='character');
outputStageChange(actors);
}
});
/**
* Chat Styling
*/
Hooks.on("renderChatMessage", (app, html, data) => {
if (html.find(".hm_messageheal").length) {
html.css("background", "#06a406");
html.css("text-shadow", "-1px -1px 0 #000 , 1px -1px 0 #000 , -1px 1px 0 #000 , 1px 1px 0 #000");
html.css("color", "white");
html.css("text-align", "center");
html.css("font-size", "12px");
html.css("margin", "2px");
html.css("padding", "2px");
html.css("border", "2px solid #191813d6");
// html.find(".message-sender").text("");
// html.find(".message-metadata")[0].style.display = "none";
}
if (html.find(".hm_messagetaken").length) {
html.css("background", "#c50d19");
html.css("text-shadow", "-1px -1px 0 #000 , 1px -1px 0 #000 , -1px 1px 0 #000 , 1px 1px 0 #000");
html.css("color", "white");
html.css("text-align", "center");
html.css("font-size", "12px");
html.css("margin", "2px");
html.css("padding", "2px");
html.css("border", "2px solid #191813d6");
// html.find(".message-sender").text("");
// html.find(".message-metadata")[0].style.display = "none";
}
});