From 759829585fb58355841c4f4086d2bb06ec844ff3 Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Sat, 13 Jun 2026 19:30:43 -0400 Subject: [PATCH] Move visible countdown types to getter --- module/applications/ui/countdowns.mjs | 31 ++++++++++++++++++--------- module/data/countdowns.mjs | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/module/applications/ui/countdowns.mjs b/module/applications/ui/countdowns.mjs index e63a244d..72a6ef6f 100644 --- a/module/applications/ui/countdowns.mjs +++ b/module/applications/ui/countdowns.mjs @@ -13,14 +13,14 @@ const { shortterm, longterm } = SYSTEM.GENERAL.countdownType; */ export default class DhCountdowns extends HandlebarsApplicationMixin(ApplicationV2) { - previusCountdownData = null; + previousCountdownData = null; changedCountdownsForAnimation = new Set(); countdownChangeAnimationTimeout = null; constructor(options = {}) { super(options); - this.previusCountdownData = + this.previousCountdownData = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns).countdowns; this.setupHooks(); } @@ -61,6 +61,16 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application } }; + /** + * Returns all visible countdown types + * @returns {string[]} + */ + get visibleCountdownTypes() { + const { shortterm, longterm } = SYSTEM.GENERAL.countdownType; + return game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) + ?? [shortterm.id, longterm.id]; + } + async _renderFrame(options) { const frame = await super._renderFrame(options); @@ -83,7 +93,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application document.getElementById('ui-right-column-1')?.appendChild(this.element); } - this.previusCountdownData = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns) + this.previousCountdownData = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns) .countdowns; /* Handle animations to draw attention to countdown values changing */ @@ -103,10 +113,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application }, 3000); + /* If the countdown is not currently visible, add a glow to the CountdownType pill */ + const visibleTypes = this.visibleCountdownTypes; for (const countdownKey of this.changedCountdownsForAnimation) { - /* If the countdown is not currently visible, add a glow to the CountdownType pill */ - const visibleTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) - ?? [shortterm.id, longterm.id] const countdown = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns) .countdowns[countdownKey]; if (!visibleTypes.includes(countdown?.type)) { @@ -184,8 +193,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode) === CONFIG.DH.GENERAL.countdownAppMode.iconOnly; - context.userCountdownTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) - ?? [shortterm.id, longterm.id]; + context.userCountdownTypes = this.visibleCountdownTypes; context.typeToggles = Object.values(CONFIG.DH.GENERAL.countdownType).map(type => ({ @@ -231,6 +239,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application return true; } + /** @this {DhCountdowns} */ static async #onToggleViewMode() { const currentMode = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode); const appMode = CONFIG.DH.GENERAL.countdownAppMode; @@ -242,9 +251,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application this.render(); } + /** @this {DhCountdowns} */ static async #onToggleCountdownTypes(event, target) { - const currentTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) - ?? [shortterm.id, longterm.id]; + const currentTypes = this.visibleCountdownTypes; const { type } = target.dataset; const newTypes = event.shiftKey ? [type] : @@ -254,10 +263,12 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application this.render(); } + /** @this {DhCountdowns} */ static async #onEditCountdowns() { new game.system.api.applications.ui.CountdownEdit().render(true); } + /** @this {DhCountdowns} */ static async #onLoopCountdown(_, target) { if (!DhCountdowns.canPerformEdit()) return; diff --git a/module/data/countdowns.mjs b/module/data/countdowns.mjs index f9cad1de..da7ae321 100644 --- a/module/data/countdowns.mjs +++ b/module/data/countdowns.mjs @@ -15,7 +15,7 @@ export default class DhCountdowns extends foundry.abstract.DataModel { } handleChange() { - const previousCountdowns = foundry.ui.countdowns.previusCountdownData; + const previousCountdowns = foundry.ui.countdowns.previousCountdownData; const changedCountdowns = Object.entries(this.countdowns).reduce((acc, [key, countdown]) => { const previousCountdown = previousCountdowns[key]; if (!previousCountdown || (previousCountdown.progress.current !== countdown.progress.current)) {