-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTorchToggle.js
More file actions
28 lines (26 loc) · 969 Bytes
/
TorchToggle.js
File metadata and controls
28 lines (26 loc) · 969 Bytes
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
async function main(){
console.log("Tokens controlled: ", canvas.tokens.controlled);
if (canvas.tokens.controlled.length != 1){
ui.notifications.error("Please select a single token");
return;
}
let token = canvas.tokens.controlled[0];
let actor = token.actor;
let torch = actor.items.find(item => item.name == "Torch");
if (torch == null || torch == undefined){
ui.notifications.error("No torches found");
return;
}
colour = token.document.light.color;
if (colour != "#fba732"){
await torch.update({"system.quantity": torch.system.quantity - 1});
if (torch.system.quantity < 1){
torch.delete();
}
await token.document.update({"light.dim": 40, "light.bright": 20, "light.color": "#fba732"});
}
else {
await token.document.update({"light.dim": 0, "light.bright": 0, "light.color": "#000000"});
}
}
main()