Skip to content

Commit

Permalink
Merge pull request #24 from delVhariant/dev
Browse files Browse the repository at this point in the history
Fixes and new features
  • Loading branch information
delVhariant authored Nov 15, 2020
2 parents 956bd53 + 4574161 commit e146d75
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 20 deletions.
6 changes: 3 additions & 3 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.3.3",
"minimumCoreVersion": "0.6.4",
"compatibleCoreVersion": "0.6.5",
"version": "0.7.7",
"minimumCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.7",
"scripts": ["scripts/dynamic-illumination.js"],
"languages": [
{
Expand Down
4 changes: 2 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"dynamic-illumination.darknessThreshold.hint": "The scene darkness level at which global illumination is deactivated.",
"dynamic-illumination.animateDarknessChange.name": "Animate Darkness Change",
"dynamic-illumination.animateDarknessChange.hint": "Should the scene darkness transition be animated? (Animations will not occur if Global Illumination is changed).",
"dynamic-illumination.interpolateColor.name": "Interpolate Color Change (Experimental)",
"dynamic-illumination.interpolateColor.hint": "Attempt to interpolate between the two scene colors. Animate Darkness change must also be enabled. May not work correctly and sends a lot of scene updates.",
"dynamic-illumination.changeFogColor.name": "Change Fog Color (Experimental)",
"dynamic-illumination.changeFogColor.hint": "Change the color of the fog in explored area to match the scene color. Only changes color moving forward, not current explored fog.",
"dynamic-illumination.animationColorChangeDelay.name": "Color Change Time",
"dynamic-illumination.animationColorChangeDelay.hint": "How many seconds will the color change take. Does not change lighting animation time.",
"dynamic-illumination.showDawnDusk.name": "Show Lighting Options for Dawn/Dusk",
Expand Down
8 changes: 5 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"title": "Dynamic Illumination",
"description": "Adds additional setting for lighting time of day color, additional lighting 'times' (Dawn/Dusk)",
"author": "delVhar",
"version": "0.7.61",
"version": "0.7.7",
"minimumCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.7",

"scripts": ["scripts/dynamic-illumination.js"],
"languages": [
{
Expand All @@ -17,5 +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.61.zip"
"download": "https://github.com/delVhariant/illumination/archive/0.7.7.zip"

}
84 changes: 72 additions & 12 deletions scripts/dynamic-illumination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
class SceneColorChange
{
constructor()
{
this.messageDialog = null;
}

displayWindow()
{
var current = {"color": canvas.scene.getFlag("dynamic-illumination","darknessColor"), "darknessLevel": canvas.lighting.darknessLevel}
renderTemplate("modules/dynamic-illumination/templates/color_template.html", current).then((selections) => {
let d = new Dialog({
title: "Monologue",
content: selections,
buttons: {
select: {
icon: '<i class="fas fa-check"></i>',
label: "Change Color",
callback: () => {changeLighting($('#di-level').val(), $('#di-color').val())}
}
},
default: "select",
close: () => {console.log("This always is logged no matter which option is chosen")}
});
d.render(true);
});
}
}


function changeLighting(level, color)
{
if(game.settings.get("dynamic-illumination","animateDarknessChange"))
if(game.settings.get("dynamic-illumination","animateDarknessChange"))
{
canvas.scene.update({darkness: level}, {animateDarkness: true}).then(() => {
interpolateSceneColor(color)
Expand All @@ -16,12 +46,17 @@ 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,
Expand All @@ -34,8 +69,9 @@ async function interpolateSceneColor(target="#FFFEFF")
}
}
}).then(() => {
//Set it to the target at the end in case it wasn't there for some reason
SendColorChange(target);
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);
});
}

Expand Down Expand Up @@ -67,8 +103,12 @@ function SendColorChange(color)
var convertedColor = PIXI.utils.string2hex(color);
canvas.scene.setFlag("dynamic-illumination","darknessColor", color).then(()=> {
CONFIG.Canvas.darknessColor = convertedColor;
CONFIG.Canvas.unexploredColor = convertedColor;
CONFIG.Canvas.exploredColor = convertedColor;
if(game.settings.get("dynamic-illumination", "changeFogColor"))
{
CONFIG.Canvas.exploredColor = convertedColor;
canvas.sight.refresh();
}

game.socket.emit("module.dynamic-illumination");
canvas.getLayer("LightingLayer").refresh();
}).then(() => {
Expand All @@ -81,8 +121,12 @@ function ReceiveColorChange()
{
var convertedColor = PIXI.utils.string2hex(canvas.scene.getFlag("dynamic-illumination","darknessColor"));
CONFIG.Canvas.darknessColor = convertedColor;
CONFIG.Canvas.unexploredColor = convertedColor;
CONFIG.Canvas.exploredColor = convertedColor;
if(game.settings.get("dynamic-illumination", "changeFogColor"))
{
CONFIG.Canvas.exploredColor = convertedColor;
canvas.sight.refresh();
}

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

Expand Down Expand Up @@ -123,6 +167,20 @@ Hooks.on('getSceneControlButtons', controls => {
visible: game.settings.get("dynamic-illumination", "showDawnDusk"),
onClick: () => {changeLighting(game.settings.get("dynamic-illumination","duskLevel"), game.settings.get("dynamic-illumination","duskColor"))}
});

control.tools.splice(nightButton+2, 0, {
name: "custom",
title: "Set to Custom",
icon: "fas fa-sliders-h",
visible: game.settings.get("dynamic-illumination", "showDawnDusk"),
onClick: () => {

if(!colorChange)
var colorChange = new SceneColorChange();

colorChange.displayWindow()
}
});
}
else
{
Expand All @@ -133,6 +191,8 @@ Hooks.on('getSceneControlButtons', controls => {

Hooks.once("init", () =>
{
loadTemplates(["modules/dynamic-illumination/templates/color_template.html"]); // Load the popup template

/*game.settings.register("dynamic-illumination", "linkGlobalLight", {
name: game.i18n.localize("dynamic-illumination.linkGlobalLight.name"),
hint: game.i18n.localize("dynamic-illumination.linkGlobalLight.hint"),
Expand Down Expand Up @@ -161,14 +221,14 @@ Hooks.once("init", () =>
type: Boolean
});

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

game.settings.register("dynamic-illumination", "animationColorChangeDelay", {
name: game.i18n.localize("dynamic-illumination.animationColorChangeDelay.name"),
Expand Down
26 changes: 26 additions & 0 deletions templates/color_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="form-group">
<label>Darkness Level</label>
<div class="form-fields">
<input type="range" id="di-level" name="darknessLevel" value="{{darknessLevel}}" min="0" max="1" step="0.05" data-dtype="Number">
<span class="range-value" id="di-level-display">{{darknessLevel}}</span>
</div>
</div>
<div class="form-group">
<label>Scene Color</label>
<div class="form-fields">
<input type="text" id="di-color-text" name="sceneColor" value="{{color}}" data-dtype="String">
<input type="color" id="di-color" value="{{color}}" data-edit="sceneColor">
</div>
</div>
<script>

$("#di-level").change(function() {
$("#di-level-display").html($(this).val());
});
$("#di-color-text").change(function() {
$("#di-color").val($(this).val());
})
$("#di-color").change(function() {
$("#di-color-text").val($(this).val());
})
</script>

0 comments on commit e146d75

Please sign in to comment.