diff --git a/module/applications/ui/combatTracker.mjs b/module/applications/ui/combatTracker.mjs index 37b4953c..2ed0e52b 100644 --- a/module/applications/ui/combatTracker.mjs +++ b/module/applications/ui/combatTracker.mjs @@ -161,9 +161,11 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C if (this.viewed.turn !== toggleTurn) { const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id); if (combatant.actor.type === 'character') { - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.characterSpotlight.id); + await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id, + CONFIG.DH.GENERAL.countdownProgressionTypes.characterSpotlight.id); + } else { + await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id); } const autoPoints = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).actionPoints; diff --git a/module/applications/ui/countdowns.mjs b/module/applications/ui/countdowns.mjs index 96315b17..42920a4a 100644 --- a/module/applications/ui/countdowns.mjs +++ b/module/applications/ui/countdowns.mjs @@ -245,14 +245,20 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application return super.close(options); } - static async updateCountdowns(progressType) { + /** + * Sends updates of the countdowns to the GM player. Since this is asynchronous, be sure to + * update all the countdowns at the same time. + * + * @param {...any} progressTypes Countdowns to be updated + */ + static async updateCountdowns(...progressTypes) { const { countdownAutomation } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation); if (!countdownAutomation) return; const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns); const updatedCountdowns = Object.keys(countdownSetting.countdowns).reduce((acc, key) => { const countdown = countdownSetting.countdowns[key]; - if (countdown.progress.type === progressType && countdown.progress.current > 0) { + if (progressTypes.indexOf(countdown.progress.type) !== -1 && countdown.progress.current > 0) { acc.push(key); } @@ -260,7 +266,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application }, []); const countdownData = countdownSetting.toObject(); - await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, { + const settings = { ...countdownData, countdowns: Object.keys(countdownData.countdowns).reduce((acc, key) => { const countdown = foundry.utils.deepClone(countdownData.countdowns[key]); @@ -271,14 +277,12 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application acc[key] = countdown; return acc; }, {}) + }; + await emitAsGM(GMUpdateEvent.UpdateCountdowns, + DhCountdowns.gmSetSetting.bind(settings), + settings, null, { + refreshType: RefreshType.Countdown }); - - const data = { refreshType: RefreshType.Countdown }; - await game.socket.emit(`system.${CONFIG.DH.id}`, { - action: socketEvent.Refresh, - data - }); - Hooks.callAll(socketEvent.Refresh, data); } async _onRender(context, options) { diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index abb75fd5..ce39ed6a 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -292,10 +292,12 @@ export const registerRollDiceHooks = () => { !config.skips?.updateCountdowns ) { const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id); if (config.roll.result.duality === -1) { - await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id); + await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id, + CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id); + } else { + await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.actionRoll.id); } }