|
| 1 | +function tokenUpdate(data) { |
| 2 | + canvas.tokens.controlled.map(token => token.update(data)); |
| 3 | +} |
| 4 | + |
| 5 | +const isGM = game.user.isGM; |
| 6 | + |
| 7 | +let color = "#ffffff"; |
| 8 | +let alpha = 1.0; |
| 9 | +let tokens = canvas.tokens.controlled; |
| 10 | +if (tokens.length === 1) { |
| 11 | + color = tokens[0].data.lightColor; |
| 12 | + alpha = tokens[0].data.lightAlpha; |
| 13 | +} |
| 14 | + |
| 15 | +const torchAnimation = {type: "torch", speed: 1, intensity: 1}; |
| 16 | +const energyShield = {type: "energy", speed: 1, intensity: 1}; |
| 17 | +const lights = { |
| 18 | + none: { |
| 19 | + label: "None", |
| 20 | + data: {dimLight: null, brightLight: null, lightAngle: 360} |
| 21 | + }, |
| 22 | + torch: { |
| 23 | + label: "Torch", |
| 24 | + data: {dimLight: 40, brightLight: 20, lightAngle: 360, lightAnimation: torchAnimation} |
| 25 | + }, |
| 26 | + light: { |
| 27 | + label: "Light cantrip", |
| 28 | + data: {dimLight: 40, brightLight: 20, lightAngle: 360, lightAnimation: {type: "none"}} |
| 29 | + }, |
| 30 | + lamp: { |
| 31 | + label: "Lamp", |
| 32 | + data: {dimLight: 45, brightLight: 15, lightAngle: 360, lightAnimation: torchAnimation} |
| 33 | + }, |
| 34 | + shield: { |
| 35 | + label: "Shield", |
| 36 | + data: {dimLight: 0.5, brightLight: 0, lightAngle: 360, lightAnimation: energyShield} |
| 37 | + }, |
| 38 | + bullseye: { |
| 39 | + label: "Bullseye Lantern", |
| 40 | + data: {dimLight: 120, brightLight: 60, lightAngle: 45, lightAnimation: torchAnimation} |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +function getLights() { |
| 45 | + let lightButtons = {}; |
| 46 | + Object.entries(lights).forEach(([key, light]) => { |
| 47 | + lightButtons[key] = { |
| 48 | + label: light.label, |
| 49 | + callback: (html) => { |
| 50 | + const newColor = html.find("#color").val(); |
| 51 | + const newAlpha = html.find("#alpha").val(); |
| 52 | + var data = light.data; |
| 53 | + tokenUpdate(Object.assign(data, {lightColor: newColor, lightAlpha: newAlpha})); |
| 54 | + } |
| 55 | + } |
| 56 | + }); |
| 57 | + |
| 58 | + lightButtons = Object.assign(lightButtons, { |
| 59 | + close: { |
| 60 | + icon: "<i class='fas fa-tick'></i>", |
| 61 | + label: `Close` |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + return lightButtons; |
| 66 | +} |
| 67 | + |
| 68 | +new Dialog({ |
| 69 | + title: `Token Light Picker`, |
| 70 | + content: ` |
| 71 | + <form> |
| 72 | + <div style="display: flex; align-content: center;"> |
| 73 | + <label for="color" style="line-height: 25px;">Color:</label> |
| 74 | + <input type="color" value="${color}" id="color" style="margin-left: 10px;"> |
| 75 | + ${isGM ? '<label for="alpha" style="line-height: 25px;">Intensity:</label>' : ''} |
| 76 | + <input type="${isGM ? 'range' : 'hidden'}" value="${alpha}" id="alpha" style="margin-left: 10px;" min="0.0" max="1.0" step="0.05"> |
| 77 | + </div> |
| 78 | + </form>`, |
| 79 | + buttons: getLights(), |
| 80 | + default: "close", |
| 81 | + close: () => {} |
| 82 | +}).render(true); |
0 commit comments