-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenVision.js
155 lines (155 loc) · 4.62 KB
/
tokenVision.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
let applyChanges = false;
new Dialog({
title: `Token Vision Configuration`,
content: `
<form>
<div class="form-group">
<label>Vision Type:</label>
<select id="vision-type" name="vision-type">
<option value="nochange">No Change</option>
<option value="dim0">Self</option>
<option value="dim30">Darkvision (30 ft)</option>
<option value="dim60">Darkvision (60 ft)</option>
<option value="dim90">Darkvision (90 ft)</option>
<option value="dim120">Darkvision (120 ft)</option>
<option value="dim150">Darkvision (150 ft)</option>
<option value="dim180">Darkvision (180 ft)</option>
<option value="bright120">Devil's Sight (Warlock)</option>
</select>
</div>
<div class="form-group">
<label>Light Source:</label>
<select id="light-source" name="light-source">
<option value="nochange">No Change</option>
<option value="none">None</option>
<option value="candle">Candle</option>
<option value="lamp">Lamp</option>
<option value="bullseye">Lantern (Bullseye)</option>
<option value="hooded-dim">Lantern (Hooded - Dim)</option>
<option value="hooded-bright">Lantern (Hooded - Bright)</option>
<option value="light">Light (Cantrip)</option>
<option value="torch">Torch</option>
</select>
</div>
</form>
`,
buttons: {
yes: {
icon: "<i class='fas fa-check'></i>",
label: `Apply Changes`,
callback: () => applyChanges = true
},
no: {
icon: "<i class='fas fa-times'></i>",
label: `Cancel Changes`
},
},
default: "yes",
close: html => {
if (applyChanges) {
for ( let token of canvas.tokens.controlled ) {
let visionType = html.find('[name="vision-type"]')[0].value || "none";
let lightSource = html.find('[name="light-source"]')[0].value || "none";
let dimSight = 0;
let brightSight = 0;
let dimLight = 0;
let brightLight = 0;
let lightAngle = 360;
let lockRotation = token.data.lockRotation;
// Get Vision Type Values
switch (visionType) {
case "dim0":
dimSight = 0;
brightSight = 0;
break;
case "dim30":
dimSight = 30;
brightSight = 0;
break;
case "dim60":
dimSight = 60;
brightSight = 0;
break;
case "dim90":
dimSight = 90;
brightSight = 0;
break;
case "dim120":
dimSight = 120;
brightSight = 0;
break;
case "dim150":
dimSight = 150;
brightSight = 0;
break;
case "dim180":
dimSight = 180;
brightSight = 0;
break;
case "bright120":
dimSight = 0;
brightSight= 120;
break;
case "nochange":
default:
dimSight = token.data.dimSight;
brightSight = token.data.brightSight;
}
// Get Light Source Values
switch (lightSource) {
case "none":
dimLight = 0;
brightLight = 0;
break;
case "candle":
dimLight = 10;
brightLight = 5;
break;
case "lamp":
dimLight = 45;
brightLight = 15;
break;
case "bullseye":
dimLight = 120;
brightLight = 60;
lockRotation = false;
lightAngle = 52.5;
break;
case "hooded-dim":
dimLight = 5;
brightLight = 0;
break;
case "hooded-bright":
dimLight = 60;
brightLight = 30;
break;
case "light":
dimLight = 40;
brightLight = 20;
break;
case "torch":
dimLight = 40;
brightLight = 20;
break;
case "nochange":
default:
dimLight = token.data.dimLight;
brightLight = token.data.brightLight;
lightAngle = token.data.lightAngle;
lockRotation = token.data.lockRotation;
}
// Update Token
console.log(token);
token.update({
vision: true,
dimSight: dimSight,
brightSight: brightSight,
dimLight: dimLight,
brightLight: brightLight,
lightAngle: lightAngle,
lockRotation: lockRotation
});
}
}
}
}).render(true);