-
-
Save palikhov/317ef99bbc66061489b9cf5610f8609c to your computer and use it in GitHub Desktop.
Foundry VTT macros TOKEN VISION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I addded : | |
// - Faerie Fire option | |
// - Light color option | |
// - Radiant consumption option (Aasimar) | |
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="faerie-fire">Faerie Fire (Spell)</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="radiant-consumption">Radiant Consumption (Aasimar)</option> | |
<option value="torch">Torch</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<label>Light Color</label> | |
<input type="color" value="${token.data.lightColor || '#ffffff'}" data-edit="light-color" name="light-color"> | |
</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 lightColor = html.find('[name="light-color"]')[0].value || ''; | |
let radiant = false; | |
let radiantEffect = 'icons/svg/sun.svg'; | |
let dimSight = 0; | |
let brightSight = 0; | |
let dimLight = 0; | |
let brightLight = 0; | |
let lightAngle = 360; | |
let lockRotation = token.data.lockRotation; | |
// Set the color | |
// 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 "faerie-fire": | |
dimLight = 10; | |
brightLight = 0; | |
if (!lightColor || lightColor === '#ffffff') lightColor = '#00ff00'; | |
break; | |
case "radiant-consumption": | |
dimLight = 20; | |
brightLight = 10; | |
radiant = true; | |
token.toggleEffect(radiantEffect); | |
break; | |
case "nochange": | |
default: | |
dimLight = token.data.dimLight; | |
brightLight = token.data.brightLight; | |
lightAngle = token.data.lightAngle; | |
lockRotation = token.data.lockRotation; | |
lightColor = token.data.lightColor; | |
} | |
// Update Token | |
token.update({ | |
vision: true, | |
dimSight: dimSight, | |
brightSight: brightSight, | |
dimLight: dimLight, | |
brightLight: brightLight, | |
lightAngle: lightAngle, | |
lockRotation: lockRotation, | |
lightColor: lightColor, | |
}); | |
if (!radiant && token.data.effects.includes(radiantEffect)) { | |
token.toggleEffect(radiantEffect); | |
} | |
} | |
} | |
} | |
}).render(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment