Skip to content

Commit

Permalink
added backwards compatibility with fvtt v9
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-roger committed Sep 20, 2022
1 parent e624ff4 commit 7d00d96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 5 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "weatherfx",
"id": "weatherfx",
"title": "Weather FX",
"description": "Weather effects for Foundry VTT with a homebrew for D&D 5e",
"version": "1.0",
"library": "false",
"manifestPlusVersion": "1.2.0",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"compatibility": {
"minimum": 10,
"verified": 10,
"minimum": 9,
"verified": 9,
"maximum": 10
},
"authors": [
Expand Down
23 changes: 18 additions & 5 deletions scripts/weatherfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import { MODULE, MODULE_DIR, JSON_ITEM } from "./const.js";

let dnd5e = false

//Compatibility with v9
let fvttVersion
let particleWeather = 'fxmaster.updateParticleEffects'

// Hook that trigger once when the game is initiated. Register and cache settings.
Hooks.once("init", () => {
// registerWrappers();
checkSystem(game.system.id);
checkSystem(game.system.id); //check if dnd5e
registerSettings();
cacheWfxSettings();
});

// Hook that triggers when the game is ready. Check if there is a weather effect been played, then check if sound is enabled and restart the sound that should be played.
Hooks.once('ready', async function () {
fvttVersion = parseInt(game.version)
console.log("🐺 ==================== FoundryVTT Version: ", fvttVersion)
//compatibility with v9
if (fvttVersion < 10) {
particleWeather = 'fxmaster.updateWeather'
}
if (canvas.scene.getFlag("weatherfx", "active"))
if (enableSound)
if (canvas.scene.getFlag("weatherfx", "audio") != "")
Expand All @@ -22,6 +32,9 @@ Hooks.once('ready', async function () {

// 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) {
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);
if (autoApply)
Expand All @@ -37,7 +50,7 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => {
{
name: "clearWeather",
title: "Clear Weather",
icon: "fas fa-cloud-slash",
icon: "fas fa-tint-slash",
button: true,
visible:
game.user.isGM,
Expand All @@ -51,7 +64,7 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => {
{
name: "applyWeatherFX",
title: "Apply Weather FX",
icon: "fas fa-cloud",
icon: "fas fa-tint",
button: true,
visible:
game.user.isGM,
Expand Down Expand Up @@ -142,7 +155,7 @@ function weatherEffects(effectCondition) {
canvas.scene.setFlag("weatherfx", "active", "true");

if (effectCondition.effectsArray.length > 0)
Hooks.call('fxmaster.updateParticleEffects', effectCondition.effectsArray)
Hooks.call(particleWeather, effectCondition.effectsArray)

if (effectCondition.filtersArray.length > 0) {
FXMASTER.filters.setFilters(effectCondition.filtersArray)
Expand Down Expand Up @@ -193,7 +206,7 @@ async function jsonItem() {
function clearEffects() {
canvas.scene.setFlag("weatherfx", "active", "false");
let src = canvas.scene.getFlag("weatherfx", "audio");
Hooks.call('fxmaster.updateParticleEffects', []);
Hooks.call(particleWeather, []);
FXMASTER.filters.setFilters([]);
for (let [key, sound] of game.audio.playing) {
if (sound.src !== src) continue;
Expand Down

0 comments on commit 7d00d96

Please sign in to comment.