diff --git a/images/heavyClouds.webp b/images/heavyClouds.webp new file mode 100644 index 0000000..6f95937 Binary files /dev/null and b/images/heavyClouds.webp differ diff --git a/scripts/settings.js b/scripts/settings.js index 16cb2dc..21b8a76 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -7,6 +7,7 @@ export let blizzardSound = 'modules/michaelghelfi/ambience/Snowing.ogg'; export let rainSound = 'modules/ivan-duch-music-packs/audio/rain-sfx.ogg'; export let thunderstormSound = 'modules/michaelghelfi/ambience/RainandThunder.ogg'; export let heavyRainSound = 'modules/ivan-duch-music-packs/audio/rain-sfx.ogg'; +export let currentWeather = null export function registerSettings() { game.settings.register(MODULE, 'autoApply', { @@ -103,6 +104,19 @@ export function registerSettings() { cacheWfxSettings(); }, }); + + game.settings.register(MODULE, 'currentWeather', { + name: 'weatherData', + hint: '', + scope: 'world', + config: false, + type: Object, + default: currentWeather, + restricted: true, + onChange: () => { + cacheWfxSettings(); + }, + }); } // function that get the settings options and assign to the variables @@ -114,4 +128,5 @@ export function cacheWfxSettings() { rainSound = game.settings.get(MODULE, 'rainSound'); thunderstormSound = game.settings.get(MODULE, 'thunderstormSound'); heavyRainSound = game.settings.get(MODULE, 'heavyRainSound'); + currentWeather = game.settings.get(MODULE, 'currentWeather'); } \ No newline at end of file diff --git a/scripts/weatherfx.js b/scripts/weatherfx.js index a443c60..7500a05 100644 --- a/scripts/weatherfx.js +++ b/scripts/weatherfx.js @@ -23,20 +23,36 @@ Hooks.once('ready', async function () { //compatibility with v9 if (fvttVersion < 10) { particleWeather = 'fxmaster.updateWeather' - } + } +}); + +Hooks.on('canvasReady', async function () { + // console.log("🐺 ==================== canvas ready") if (canvas.scene.getFlag("weatherfx", "active")) if (enableSound) if (canvas.scene.getFlag("weatherfx", "audio") != "") AudioHelper.play({ src: canvas.scene.getFlag("weatherfx", "audio"), volume: 0.8, loop: true }, true); -}); + if (!canvas.scene.getFlag("weatherfx", "active")) + clearEffects(); +}) + +Hooks.once('renderWeatherApplication', async function (app, html, data) { + if (!isChatOutputOn()) { + noChatOutputDialog() + } + // console.log("🐺 ==================== message object", data) + // console.log("🐺 ==================== message html", html) + // console.log("🐺 ==================== message app", app) + +}) // Hook on every created message, if this is a message created with the alias "Today's Weather", then trigger the Weather FX part. -Hooks.on('createChatMessage', async function (message) { +Hooks.on('createChatMessage', async function (message, html, data) { if (fvttVersion < 10) //compatibility with v9 message = message.data - console.log(message) if (message.speaker.alias == `Today's Weather:`) { - canvas.scene.setFlag("weatherfx", "currentWeather", message.content); + // canvas.scene.setFlag("weatherfx", "currentWeather", message.content); + await game.settings.set(MODULE, "currentWeather", message.content); if (autoApply) weatherTrigger(message.content); } @@ -58,7 +74,7 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => { // game.settings.get("", "enableWeatherFX"), onClick: () => { clearEffects() - ChatMessage.create({ speaker: { alias: 'Weather Effects: ' }, content: "Weather effects for: " + canvas.scene.getFlag("weatherfx", "currentWeather") + " removed", whisper: ChatMessage.getWhisperRecipients("GM") }); + ChatMessage.create({ speaker: { alias: 'Weather Effects: ' }, content: "Weather effects for: " + game.settings.get("weatherfx", "currentWeather") + " removed", whisper: ChatMessage.getWhisperRecipients("GM") }); }, }, { @@ -71,16 +87,60 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => { // && // game.settings.get("", "enableWeatherFX"), onClick: () => { - let currentWeather = canvas.scene.getFlag("weatherfx", "currentWeather") - weatherTrigger(currentWeather); + if (isChatOutputOn()) { + let currentWeather = game.settings.get("weatherfx", "currentWeather") + weatherTrigger(currentWeather); + } + else noChatOutputDialog() + }, } ); }); +function isChatOutputOn() { + let outputWeatherChat = game.settings.get('weather-control', 'outputWeatherChat') + // let precipitation = app.weatherTracker.weatherData.precipitation + if (!outputWeatherChat) { + const errorMessage = "Weather FX cannot initialize and requires Weather Control 'Output weather to chat?' setting checked in order to get the current weather and apply effects to the current canvas."; + console.error(errorMessage); + ui.notifications.error(errorMessage); + } + return outputWeatherChat +} + +function noChatOutputDialog() { + + new Dialog({ + title: "No weather data!", + content: "
Please activate Weather Control output to chat, otherwise Weather FX can't access its data