From b06b07e864104d9e6a1a7868e157b58fdffc63c2 Mon Sep 17 00:00:00 2001 From: Paulo Roger Date: Wed, 21 Sep 2022 20:00:59 -0300 Subject: [PATCH] check if weather-control ouput to chat is checked, and thow an error to the user, added missing image --- images/heavyClouds.webp | Bin 0 -> 3660 bytes scripts/settings.js | 15 +++++++ scripts/weatherfx.js | 90 +++++++++++++++++++++++++++++++++------- 3 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 images/heavyClouds.webp diff --git a/images/heavyClouds.webp b/images/heavyClouds.webp new file mode 100644 index 0000000000000000000000000000000000000000..6f9593746455ce292f8f94bd8c14c7503f00bc23 GIT binary patch literal 3660 zcmV-S4zux6Nk&FQ4gdgGMM6+kP&iCD4gdfzKfn(VO(gDwjPJs$t+Uc!L)Uv1h349-^nfFBW& zUh;?#01z1>BT-Brh#_~+z!(bJwqX+fu)E73A|`-e1x&D6)55mxa3np2IO(1wYumPM z+qP}n-aWEy+qS)JGp?j6ssF#OB%PUS=4|=@65B{}B#F_p_riZ;^>j*XBgv5@W_9l# z&VOHDjOe6vZQCJ9x<7<6Qf0es+qP}4$M)>>1GKYk&#c8amPD^RabiL`@VGKnX;M zD2#BBAd~1K7AT;R>k9)OIADRCZqT5>f%r1iY;RY`K8;oXzbbtB=)7&L%c^0Xe{i4nn>9blv!CyPGg*_C!A9}^K&JP~fJ&Dbqz&9}L4XuO0-y{f4AoE)LL$;m z(-G1U)&YZbxHOowF3-bnI5UYI#6F*y^D=oY>V5V;%vDgQ(^?_;nxcWV9I5wt?o^g- zPSb+;V1oq;Wb4BAt9G2u(RJxqYq~L>2x71t096fTh!1KK<^~&bg1Lhsc!ChhVR97O zmTo8tWl=)>SQ)mbv@I-QNrIv{(bCl{jjNY#)-wlpT6)agTDX!{rR>w&F?`9^v`5VU z^EK;NFe|n&gN3iZ0co&60wAUeKos-@gRWbXM@1L)eOMxdK)Fg>2rKT2BjlknNTF2G z1i)A*g$lTaa>Z04N&))7f`xFbw68>u4b!~<-N7Bv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LK-eVVkS!53Xd;f_h9xNbH1;rSoAYPoBX@=)YB%<0v_l;v>$WZ? zoSpyI;Fqj*ug~pwYO3^2vhaSw$AABuPx=PN#tn_KG74#kvFp!R6ezMpp2@HQ2o|O& zFa!#E00aRS20#D^&FB-zdm84I`Ip^WvMZGb+xybbWA9F9cJ;rVPW*cXe`N$XP}y{B z!GP3Yg9fR<0(T|5>jKtX(mB|Q2X~}LSTql6&Uwl`^B&|GKRmr`2E=hd044;$#7K|` z34k&{f&fvFg8+en$S3DyYo_x<{&hJ^zF=;<6sv^%o51KQd3}rgxr(xAbcjf(lG!SZdig{e>+^WJytpiQmWiOYv?zOQ3QC?5s+Ca4gZ-Y{<$@;nrh zE4#BE8OTEsLJg)7AyP`s2=Zy32N*zs1`F(|zyPGujbQ=`jE11TSdH;EbivFRTx^L$ e6v$S1N;L&lUoHiant9l<^$41#+HC2s$fy8M#+#@B literal 0 HcmV?d00001 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


", + buttons: { + yes: { + icon: "", + label: "Activate", + callback: async () => { + await game.settings.set('weather-control', 'outputWeatherChat', true) + await game.settings.set("weatherfx", "currentWeather", game.settings.get("weather-control", "weatherData").precipitation) + // let currentWeather = game.settings.get("weatherfx", "currentWeather") + // weatherTrigger(currentWeather); + } + }, + no: { + icon: "", + label: "No, I won't", + callback: async () => { + return + } + }, + }, + default: "yes", + }).render(true); +} + + function checkSystem(system) { -if (system === 'dnd5e') - dnd5e = true + if (system === 'dnd5e') + dnd5e = true } // Trigger weather fx chain of events. 1st it transforms the whole message to lowercase so it's easier to check the cases without worrying for capital letters. 2nd start the check weather function, that checks the string for which weather was generated. @@ -152,7 +212,7 @@ function checkWeather(msgString) { // This function apply weather effects to the canvas, but first cleans any effects that are currently applied. function weatherEffects(effectCondition) { clearEffects(); - canvas.scene.setFlag("weatherfx", "active", "true"); + canvas.scene.setFlag("weatherfx", "active", true); if (effectCondition.effectsArray.length > 0) Hooks.call(particleWeather, effectCondition.effectsArray) @@ -191,8 +251,10 @@ async function weatherRoll(item) {

${weather.name}

${weather.description}
${saveButton}` - ChatMessage.create({ speaker: { alias: 'Weather Effects: ' }, content: msgContent, - whisper: ChatMessage.getWhisperRecipients("GM") }) + ChatMessage.create({ + speaker: { alias: 'Weather Effects: ' }, content: msgContent, + whisper: ChatMessage.getWhisperRecipients("GM") + }) } // Read the json weather 'item' file. @@ -204,7 +266,7 @@ async function jsonItem() { // remove all the current fx on the canvas, also stops all the sounds effects that matches the flag weatherfx.audio function clearEffects() { - canvas.scene.setFlag("weatherfx", "active", "false"); + canvas.scene.setFlag("weatherfx", "active", false); let src = canvas.scene.getFlag("weatherfx", "audio"); Hooks.call(particleWeather, []); FXMASTER.filters.setFilters([]);