-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarker.js
32 lines (27 loc) · 1021 Bytes
/
marker.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
var bloodIcon = "icons/svg/blood.svg";
function updateToken(args, changedData) {
try{
let a = changedData.actorData.data.attributes.hp.value;
}
catch(e){
return;
}
let tMaxHealth = args.actor.data.data.attributes.hp.max;
let tCurrentHealth = args.actor.data.data.attributes.hp.value;
toggleBloodiedMarker((tCurrentHealth < (tMaxHealth / 2) && tCurrentHealth > 0), args);
setTokenDead(args, tCurrentHealth > 0);
}
function toggleBloodiedMarker(state, token) {
let effs = token.data.effects;
if ((state && !effs.includes(bloodIcon)) || (!state && effs.includes(bloodIcon))) {
token.toggleEffect(bloodIcon);
}
}
function setTokenDead(token, alive) {
if(!token.data.overlayEffect && alive == false){
token.toggleOverlay(CONFIG.controlIcons.defeated);
} else if (token.data.overlayEffect && alive == true){
token.toggleOverlay(null);
}
}
Hooks.on('updateToken', (arg, parentId, changedData) => updateToken(arg, changedData));