Created
July 30, 2024 21:03
-
-
Save keithcurtis1/84d923d217cc9b8dbfa7c3dac47c4e66 to your computer and use it in GitHub Desktop.
Light Meter
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
on("change:graphic", function(obj, prev) { | |
let tokenID = obj.get("id"); | |
let page = getObj("page", Campaign().get("playerpageid")); | |
if (typeof checkLightLevel !== "undefined" && page.get("dynamic_lighting_enabled")) { | |
if (prev.left !== obj.get("left") || prev.top !== obj.get("top")) { | |
function containsIllumination(illumination, obj) { | |
return illumination.some(item => obj.name.includes(item)); | |
} | |
function updateIllumination(obj, lightLevel, dimLight, darkness) { | |
let newName; | |
if (lightLevel <= darkness) { | |
newName = obj.name.slice(0, -3) + " π"; | |
} else if (lightLevel > darkness && lightLevel <= dimLight) { | |
newName = obj.name.slice(0, -3) + " π"; | |
} else { | |
newName = obj.name.slice(0, -3) + " π"; | |
} | |
return newName; | |
} | |
let dimLight = 50; | |
let darkness = 20; | |
let lightLevel = (checkLightLevel.isLitBy(obj.get("id")).total * 100).toFixed(); | |
let illumination = [" **", " π", " π", " π"]; | |
if (containsIllumination(illumination, prev)) { | |
let newName = updateIllumination(prev, lightLevel, dimLight, darkness); | |
obj.set("name", newName); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment