From f56ec53017b857fdbbebf40d7a8a11fbcf712684 Mon Sep 17 00:00:00 2001 From: Prototype Date: Sun, 26 May 2024 13:41:48 -0700 Subject: [PATCH] Fixes #802 --- RELEASE_NOTES.md | 8 ++++++++ system/src/apps/LightSourceTrackerSD.mjs | 2 +- system/src/hooks/light-source-tracker.mjs | 1 + system/src/utils/UtilitySD.mjs | 24 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b83e15edc..f049c0c71 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,11 @@ +# v2.2.2 + +## Bugfixes +* [#799] Character Generator incorrectly generating character stats +* [#802] Light sources counting down to quickly with multiple GMs logged in + +--- + # v2.2.1 ## Bugfixes diff --git a/system/src/apps/LightSourceTrackerSD.mjs b/system/src/apps/LightSourceTrackerSD.mjs index df05b4622..e6de085a4 100644 --- a/system/src/apps/LightSourceTrackerSD.mjs +++ b/system/src/apps/LightSourceTrackerSD.mjs @@ -484,7 +484,7 @@ export default class LightSourceTrackerSD extends Application { } async onUpdateWorldTime(worldTime, worldDelta) { - if (!(this._isEnabled() && game.user.isGM)) return; + if (!(this._isEnabled() && shadowdark.utils.isPrimaryGM())) return; if (this.updatingLightSources) return; const updateSecs = game.settings.get( diff --git a/system/src/hooks/light-source-tracker.mjs b/system/src/hooks/light-source-tracker.mjs index 2fbfb75ea..c8dde55bd 100644 --- a/system/src/hooks/light-source-tracker.mjs +++ b/system/src/hooks/light-source-tracker.mjs @@ -4,6 +4,7 @@ export const LightSourceTrackerHooks = { const lst = game.shadowdark.lightSourceTracker; if (game.user.isGM) { + game.user.setFlag("shadowdark", "primaryGM", false); game.shadowdark.lightSourceTracker.start(); Hooks.on("deleteActor", lst._deleteActorHook.bind(lst)); Hooks.on("deleteItem", lst._deleteItemHook.bind(lst)); diff --git a/system/src/utils/UtilitySD.mjs b/system/src/utils/UtilitySD.mjs index f599c1a98..1d1302fd4 100644 --- a/system/src/utils/UtilitySD.mjs +++ b/system/src/utils/UtilitySD.mjs @@ -234,4 +234,28 @@ export default class UtilitySD { } return itemObj; } + + static isPrimaryGM() { + if (!game.user.isGM) return false; + + // if primaryGM flag is true, return + if (game.user.getFlag("shadowdark", "primaryGM")) { + return true; + } + else { + // locate the primary GM + const primaryGMs = game.users.filter(x => + x.active === true && x.flags.shadowdark.primaryGM === true + ); + if (primaryGMs.length === 0) { + // if no primary GM, set current user as primary GM + game.user.setFlag("shadowdark", "primaryGM", true); + shadowdark.log("Promoted to Primary GM"); + return true; + } + else { + return false; + } + } + } }