Skip to content

Instantly share code, notes, and snippets.

@keithcurtis1
Created July 30, 2024 21:03
Show Gist options
  • Save keithcurtis1/84d923d217cc9b8dbfa7c3dac47c4e66 to your computer and use it in GitHub Desktop.
Save keithcurtis1/84d923d217cc9b8dbfa7c3dac47c4e66 to your computer and use it in GitHub Desktop.
Light Meter
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