Created
February 3, 2021 11:47
-
-
Save shinmai/6139f0eb59a80ccd5e625be856f352b8 to your computer and use it in GitHub Desktop.
Modified version of Aarowaim's FoundryVTT Token Vision macro for my own use
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
| let namedfields = (...fields) => { | |
| return (...arr) => { | |
| var obj = {}; | |
| fields.forEach((field, index) => { | |
| obj[field] = arr[index]; | |
| }); | |
| return obj; | |
| }; | |
| }; | |
| let VisionType = namedfields('name', 'dim', 'bright'); | |
| let visions = (() => { | |
| return [ | |
| VisionType('No Darkvision', 5, 0), | |
| ].concat(...[...Array(5).keys()].map(x => (x+1)*30).map(n => { | |
| return VisionType(`Darkvision (${n}ft)`, n, 0); | |
| })); | |
| })(); | |
| let LightSource = namedfields('name', 'dim', 'bright') | |
| let lightSources = [ | |
| LightSource('None', 0, 0), | |
| LightSource('Candle', 10, 5), | |
| LightSource('Torch/Light', 40, 20), | |
| LightSource('Lamp', 45, 15), | |
| LightSource('Hooded Lantern', 60, 30), | |
| LightSource('Hooded Lantern (Dim)', 5, 0), | |
| ]; | |
| if (canvas.tokens.controlled.length === 0) | |
| ui.notifications.error("Select tokens"); | |
| else new Dialog({ | |
| title: `Lamppu`, | |
| content: ` | |
| <form> | |
| ${visions.map((vision, index) => { | |
| return `\t<button style="width: 49%; float: left;" onclick="for ( let token of canvas.tokens.controlled ) { | |
| token.update({ | |
| vision: true, | |
| dimSight: ${vision.dim} ?? token.data.dimSight, | |
| brightSight: ${vision.brigh} ?? token.data.brightSight, | |
| }); | |
| }; return false;">${vision.name}</button>`; | |
| }).join('\n') | |
| } | |
| <br style="clear: both;" /> | |
| <hr style="clear: both;" /> | |
| ${lightSources.map((lightSource, index) => { | |
| return `\t<button style="width: 49%; float: left;" onclick="for ( let token of canvas.tokens.controlled ) { | |
| token.update({ | |
| vision: true, | |
| dimLight: ${lightSource.dim} ?? token.data.dimLight, | |
| brightLight: ${lightSource.bright} ?? token.data.brightLight, | |
| }); | |
| }; return false;">${lightSource.name}</button>`; | |
| }).join('\n') | |
| } | |
| </form> | |
| `, | |
| buttons: { | |
| no: { | |
| icon: "<i class='fas fa-times'></i>", | |
| label: `Close` | |
| } | |
| }, | |
| default: "no", | |
| }).render(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment