Skip to content

Commit

Permalink
Merge pull request #28 from delVhariant/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
delVhariant authored Jan 2, 2021
2 parents e146d75 + d139308 commit 271d9fc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 40 deletions.
4 changes: 2 additions & 2 deletions dev-module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"title": "Dynamic Illumination (DEV)",
"description": "Adds additional setting for lighting time of day color, additional lighting 'times' (Dawn/Dusk), and make scene lighting impact global illumination setting.",
"author": "delVhar",
"version": "0.7.7",
"version": "0.9.0",
"minimumCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.7",
"compatibleCoreVersion": "0.7.9",
"scripts": ["scripts/dynamic-illumination.js"],
"languages": [
{
Expand Down
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"dynamic-illumination.dayColor.name": "Day Color",
"dynamic-illumination.dayColor.hint": "The lighting overlay color for Day. Use hex color reference (ie: #FFFEFE)",
"dynamic-illumination.dayLevel.name": "Day Darkness Level",
"dynamic-illumination.dayLevel.hint": "The darkness level to set when Day is selected. If global illumination linking is enabled this will determine whether it is off at Day."
"dynamic-illumination.dayLevel.hint": "The darkness level to set when Day is selected. If global illumination linking is enabled this will determine whether it is off at Day.",
"dynamic-illumination.allowInterrupt.name": "Allow Interrupt (Expermental)",
"dynamic-illumination.allowInterrupt.hint": "Whether or not to allow interrupting an in flight change with a new change. May result in incorrect color/darkness level"
}
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"title": "Dynamic Illumination",
"description": "Adds additional setting for lighting time of day color, additional lighting 'times' (Dawn/Dusk)",
"author": "delVhar",
"version": "0.7.7",
"version": "0.9.0",
"minimumCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.7",
"compatibleCoreVersion": "0.7.9",

"scripts": ["scripts/dynamic-illumination.js"],
"languages": [
Expand All @@ -18,6 +18,6 @@
"socket": true,
"url": "https://github.com/delVhariant/illumination",
"manifest": "https://raw.githubusercontent.com/delVhariant/illumination/master/module.json",
"download": "https://github.com/delVhariant/illumination/archive/0.7.7.zip"
"download": "https://github.com/delVhariant/illumination/archive/v0.9.0.zip"

}
102 changes: 68 additions & 34 deletions scripts/dynamic-illumination.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,33 @@ class SceneColorChange

function changeLighting(level, color)
{
//console.log(`Called with col: ${color} and level: ${level}`);

if(game.settings.get("dynamic-illumination","animateDarknessChange"))
{
canvas.scene.update({darkness: level}, {animateDarkness: true}).then(() => {
if(canvas.getLayer("LightingLayer")._animating || canvas.scene.getFlag("dynamic-illumination","_animating"))
{

if(game.settings.get("dynamic-illumination","allowInterrupt"))
{
// An attempt to gracefully interrupt ongoing changes that doesn't quite work correctly.
// console.log(CanvasAnimation.animations)
// console.log("Cancelling darkness animation");
CanvasAnimation.terminateAnimation("lighting.animateDarkness");
CanvasAnimation.terminateAnimation("lighting.darknessColor")
canvas.getLayer("LightingLayer")._animating = false;
canvas.scene.setFlag("dynamic-illumination","_animating", false);
// console.log(CanvasAnimation.animations)
// console.log(canvas.getLayer("LightingLayer")._animating);
}
else
{
ui.notifications.notify('Scene color/darkness already animating. You can enable interrupting ongiong changes in settings.', "warning");
return;
}
}

canvas.scene.update({darkness: level}, {animateDarkness: true}).then(() => {
interpolateSceneColor(color)
});
}
Expand All @@ -47,32 +71,31 @@ function changeLighting(level, color)

async function interpolateSceneColor(target="#FFFEFF")
{
if(canvas.scene.getFlag("dynamic-illumination","_animating"))
return

const interpolationData = [{
parent: {interpolationSteps: 0},
attribute: "interpolationSteps",
to: 20
}];

canvas.scene.setFlag("dynamic-illumination","_animating", true);
return CanvasAnimation.animateLinear(interpolationData, {
name: "lighting.darknessColor",
duration: game.settings.get("dynamic-illumination","animationColorChangeDelay") * 1000,
ontick: (dt, attributes) => {
color = interpolateColor(canvas.scene.getFlag("dynamic-illumination","darknessColor"), target, attributes[0].parent.interpolationSteps/attributes[0].to)
// Only update if we actually changed color
if(color.toLowerCase() != canvas.scene.getFlag("dynamic-illumination","darknessColor").toLowerCase())
{
SendColorChange(color);
}
}
}).then(() => {
canvas.scene.setFlag("dynamic-illumination","_animating", false);
//Set it to the target at the end in case it wasn't there for some reason
SendColorChange(target);
});
const interpolationData = [{
parent: {interpolationSteps: 0},
attribute: "interpolationSteps",
to: 20
}];

canvas.scene.setFlag("dynamic-illumination","_animating", true);
return CanvasAnimation.animateLinear(interpolationData, {
name: "lighting.darknessColor",
duration: game.settings.get("dynamic-illumination","animationColorChangeDelay") * 1000,
ontick: (dt, attributes) => {
color = interpolateColor(canvas.scene.getFlag("dynamic-illumination","darknessColor"), target, attributes[0].parent.interpolationSteps/attributes[0].to)
// Only update if we actually changed color
if(color.toLowerCase() != canvas.scene.getFlag("dynamic-illumination","darknessColor").toLowerCase())
{
SendColorChange(color);
}
}
}).then(() => {
canvas.scene.setFlag("dynamic-illumination","_animating", false);
//Set it to the target at the end in case it wasn't there for some reason
SendColorChange(target);
console.log("finished color change");
});

}

function interpolateColor(color1, color2, factor) {
Expand Down Expand Up @@ -108,7 +131,6 @@ function SendColorChange(color)
CONFIG.Canvas.exploredColor = convertedColor;
canvas.sight.refresh();
}

game.socket.emit("module.dynamic-illumination");
canvas.getLayer("LightingLayer").refresh();
}).then(() => {
Expand All @@ -126,7 +148,6 @@ function ReceiveColorChange()
CONFIG.Canvas.exploredColor = convertedColor;
canvas.sight.refresh();
}

canvas.getLayer("LightingLayer").refresh();
}

Expand All @@ -142,12 +163,13 @@ Hooks.on('getSceneControlButtons', controls => {
if(dayButton)
{
control.tools[dayButton].onClick = () => {changeLighting(game.settings.get("dynamic-illumination","dayLevel"), game.settings.get("dynamic-illumination","dayColor"))};
control.tools.splice(dayButton, 0, {
control.tools.splice(dayButton, 0, {
name: "dawn",
title: "Transition to Dawn",
icon: "far fa-sun",
visible: game.settings.get("dynamic-illumination", "showDawnDusk"),
onClick: () => {changeLighting(game.settings.get("dynamic-illumination","dawnLevel"), game.settings.get("dynamic-illumination","dawnColor"))}
onClick: () => {changeLighting(game.settings.get("dynamic-illumination","dawnLevel"), game.settings.get("dynamic-illumination","dawnColor"))},
button: true
});
}
else
Expand All @@ -165,7 +187,8 @@ Hooks.on('getSceneControlButtons', controls => {
title: "Transition to Dusk",
icon: "far fa-moon",
visible: game.settings.get("dynamic-illumination", "showDawnDusk"),
onClick: () => {changeLighting(game.settings.get("dynamic-illumination","duskLevel"), game.settings.get("dynamic-illumination","duskColor"))}
onClick: () => {changeLighting(game.settings.get("dynamic-illumination","duskLevel"), game.settings.get("dynamic-illumination","duskColor"))},
button: true
});

control.tools.splice(nightButton+2, 0, {
Expand All @@ -179,7 +202,8 @@ Hooks.on('getSceneControlButtons', controls => {
var colorChange = new SceneColorChange();

colorChange.displayWindow()
}
},
button: true
});
}
else
Expand Down Expand Up @@ -212,6 +236,15 @@ Hooks.once("init", () =>
range: {min: 0.0, max: 1.0, step: 0.05}
});*/

game.settings.register("dynamic-illumination", "allowInterrupt", {
name: game.i18n.localize("dynamic-illumination.allowInterrupt.name"),
hint: game.i18n.localize("dynamic-illumination.allowInterrupt.hint"),
scope: "world",
config: true,
default: false,
type: Boolean
});

game.settings.register("dynamic-illumination", "animateDarknessChange", {
name: game.i18n.localize("dynamic-illumination.animateDarknessChange.name"),
hint: game.i18n.localize("dynamic-illumination.animateDarknessChange.hint"),
Expand Down Expand Up @@ -328,11 +361,12 @@ Hooks.once("init", () =>

})

Hooks.once("canvasInit", () => {
Hooks.on("canvasReady", () => {
var color = canvas.scene.getFlag("dynamic-illumination","darknessColor");
if(game.user.isGM)
{
canvas.scene.unsetFlag("core","darknessColor"); // Delete darknessColor Flag to clean up old usage...Replace this with a button in options?
canvas.scene.setFlag("dynamic-illumination","_animating", false); // Get rid of any left over animating flags
// Set Canvas Darkness color to match flag

if(color == undefined)
Expand Down

0 comments on commit 271d9fc

Please sign in to comment.