diff --git a/scripts/helpers.mjs b/scripts/helpers.mjs index 39034a4..cab5f23 100755 --- a/scripts/helpers.mjs +++ b/scripts/helpers.mjs @@ -23,7 +23,7 @@ ST_Config.PhaseValues = { }; // Saving the default core Darkness color for reference. -ST_Config.coreDarknessColor = '2368584'; +ST_Config.coreDarknessColor = 2368584; // Default offset from the Player List window when pinned, // an Epoch offset for game systems that don't start at midnight, diff --git a/scripts/smalltime-app.mjs b/scripts/smalltime-app.mjs index 3eba330..a8661c5 100644 --- a/scripts/smalltime-app.mjs +++ b/scripts/smalltime-app.mjs @@ -279,6 +279,25 @@ Hooks.on('init', () => { }); }); +Hooks.on('canvasInit', () => { + // Start by resetting the Darkness color to the core value. + CONFIG.Canvas.darknessColor = ST_Config.coreDarknessColor; + + if (game.modules.get('foundryvtt-simple-calendar')?.active) { + if (game.scenes.viewed.getFlag('smalltime', 'darkness-link')) { + // Set the global Darkness color to the color of the first moon in Simple Calendar, if configured. + // The pSBC function drops the brightness to an appropriate level. + // Ignore if the moon is set to its default color of white. + if (SimpleCalendar.api.getAllMoons()[0].color != '#ffffff') { + const darknessColorFromMoon = Helpers.pSBC(-0.9, SimpleCalendar.api.getAllMoons()[0].color); + CONFIG.Canvas.darknessColor = darknessColorFromMoon; + } + } + } + // Re-draw the canvas with the new Darkness color. + canvas.colorManager.initialize() +}); + // Set the initial state for newly rendered scenes. Hooks.on('canvasReady', () => { // Account for the extra border art in certain game systems. @@ -376,20 +395,6 @@ Hooks.on('canvasReady', () => { thisScene.setFlag('smalltime', 'player-vis', visDefault); } - CONFIG.Canvas.darknessColor = ST_Config.coreDarknessColor; - - if (game.modules.get('foundryvtt-simple-calendar')?.active) { - if (thisScene.getFlag('smalltime', 'darkness-link')) { - // Set the global Darkness color to the color of the first moon in Simple Calendar, if configured. - // The pSBC function drops the brightness to an appropriate level. - // Ignore if the moon is set to its default color of white. - if (SimpleCalendar.api.getAllMoons()[0].color != '#ffffff') { - const darknessColorFromMoon = Helpers.pSBC(-0.9, SimpleCalendar.api.getAllMoons()[0].color); - CONFIG.Canvas.darknessColor = darknessColorFromMoon; - } - } - } - // Refresh the current scene's Darkness level if it should be linked. if (thisScene.getFlag('smalltime', 'darkness-link')) { SmallTimeApp.timeTransition(Helpers.getWorldTimeAsDayTime());