forked from cyruzzo/AboveVTT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AOETemplates.js
182 lines (156 loc) · 7.03 KB
/
AOETemplates.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Lines are not supported yet
const AOE_TEMPLATES = {
'dark-circle': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/SpellToken_DarkCircle.png',
'dark-cone': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_DarkCone.png',
//'dark-line': 'https://drive.google.com/file/d/16G3T1cdyrOkn3TYrol855yXtR122VkTe/view?usp=sharing',
'dark-square': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_DarkSquare.png',
'default-circle': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_DefaultCircle.png',
'default-cone': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/SpellToken_DefaultCone.png',
//'default-line': 'https://drive.google.com/file/d/1GfstCLPWsIpZ8wz8O1MVv0658XlM0i2p/view?usp=sharing',
'default-square': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/SpellToken_DefaultSquare.png',
'fire-circle': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/SpellToken_FireCircle.png',
'fire-cone': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_FireCone.png',
//'fire-line': 'https://drive.google.com/file/d/1TEyhC5c_syyY_gnfB2fIFZK6djdWw9qg/view?usp=sharing',
'fire-square': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/SpellToken_FireSquare.png',
'green-circle': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_GreenCircle.png',
'green-cone': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_GreenCone.png',
//'green-line': 'https://drive.google.com/file/d/1LNIBQAMJhrjFaOJk-iPioaUaFFvX3EUP/view?usp=sharing',
'green-square': 'https://abovevtt-assets.s3.eu-central-1.amazonaws.com/aoe/Spelltoken_GreenSquare.png',
}
function setup_aoe_button() {
aoe_button = $("<button style='display:inline;width:75px' id='aoe_button' class='drawbutton menu-button hideable'><u>A</u>OE</button>");
aoe_menu = $("<div id='aoe_menu' class='top_menu'></div>");
aoe_menu.append("<div style='font-weight:bold'>Size</div>");
aoe_menu.append("<div><input tabindex='2' id='aoe_feet' value='20' style='width:75px;margin:0px;text-align:center' maxlength='10'></div>");
aoe_menu.append("<div style='font-weight:bold'>Color</div>");
aoe_menu.append("<div><button tabindex='3' id='aoe_default' class='drawbutton menu-option aoe-option aoecolor remembered-selection' style='width:75px'>Default</button></div>");
aoe_menu.append("<div><button tabindex='3' id='aoe_fire' class='drawbutton menu-option aoe-option aoecolor' style='width:75px'>Fire</button></div>");
aoe_menu.append("<div><button tabindex='3' id='aoe_dark' class='drawbutton menu-option aoe-option aoecolor' style='width:75px'>Dark</button></div>");
aoe_menu.append("<div><button tabindex='3' id='aoe_green' class='drawbutton menu-option aoe-option aoecolor' style='width:75px'>Green</button></div>");
aoe_menu.append("<div style='font-weight:bold'>Shape</div>");
aoe_menu.append("<div><button tabindex='1' id='aoe_cone' class='aoeshape' style='width:75px'>Cone</button></div>");
aoe_menu.append("<div><button tabindex='1' id='aoe_square' class='aoeshape' style='width:75px'>Square</button></div>");
aoe_menu.append("<div><button tabindex='1' id='aoe_circle'class='aoeshape' style='width:75px'>Circle</button></div>");
aoe_menu.css("position", "fixed");
aoe_menu.css("top", "25px");
aoe_menu.css("width", "75px");
aoe_menu.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");
$("body").append(aoe_menu);
buttons.append(aoe_button);
aoe_menu.css("left", aoe_button.position().left);
$("#aoe_feet").keydown(function(e) {
if (e.key === "Escape") {
$('#select-button').click();
}
});
$(".aoeshape").click(function (e) {
const color = $(".aoe-option.remembered-selection").attr('id').split('_')[1];
const shape = this.id.split("_")[1];
let feet = document.getElementById("aoe_feet").value
// refocus size box if size is 0
if (!is_feet_valid(feet)) {
$("#aoe_feet").focus();
return;
}
drop_aoe_token(color, shape, feet);
if(window.DM){
$('#select-button').click();
}
else{
$('#aoe_button').click();
}
});
}
function is_feet_valid(feet) {
return parseInt(feet) > 0;
}
function drop_aoe_token(color, shape, feet) {
// support 13 damage types, for now most things will be default,
// but this should make it easier to add more template colors as they come in
switch(color) {
case "slashing":
color = "default";
break;
case "piercing":
color = "default";
break;
case "bludgeoning":
color = "default";
break;
case "poison":
color = "green";
break;
case "acid":
color = "green";
break;
case "fire":
color = "fire";
break;
case "cold":
color = "default";
break;
case "radiant":
color = "fire";
break;
case "necrotic":
color = "dark";
break;
case "lightning":
color = "default";
break;
case "thunder":
color = "default";
break;
case "force":
color = "default";
break;
case "psychic":
color = "default";
break;
}
// normalize shape
switch(shape) {
case "cube":
shape = "square";
break;
case "sphere":
shape = "circle";
break;
case "cylinder":
shape = "circle";
}
// don't create a token if the size isn't valid
if (!is_feet_valid(feet)) {
throw "failed to create aoe token, feet is invalid: " + feet;
}
// convert feet into pixels
let size = window.CURRENT_SCENE_DATA.hpps * (feet / window.CURRENT_SCENE_DATA.fpsq);
// circles are always by radius
if (shape == 'circle') {
size = size * 2;
}
console.log(`dropping aoe token: color ${color}, shape ${shape}, feet ${feet}`);
let atts = {
'data-disablestat': true,
'data-hidestat': true,
'data-disableborder': true,
'data-square': 1,
'data-img': AOE_TEMPLATES[`${color}-${shape}`],
'data-size': Math.round(size),
};
if(window.DM){
let fake=$("<div/>");
fake.attr(atts);
token_button({target:fake.get(0)});
fake.remove();
}
else{
let centerX = $(window).scrollLeft() + Math.round(+$(window).width() / 2) - 200;
let centerY = $(window).scrollTop() + Math.round($(window).height() / 2) - 200;
centerX = Math.round(centerX * (1.0 / window.ZOOM));
centerY = Math.round(centerY * (1.0 / window.ZOOM));
atts['data-left']=centerX;
atts['data-top']=centerY;
window.MB.sendMessage("custom/myVTT/createtoken",atts);
}
}