Move visible countdown types to getter

This commit is contained in:
Carlos Fernandez 2026-06-13 19:30:43 -04:00
parent 919e872f68
commit 759829585f
2 changed files with 22 additions and 11 deletions

View file

@ -13,14 +13,14 @@ const { shortterm, longterm } = SYSTEM.GENERAL.countdownType;
*/ */
export default class DhCountdowns extends HandlebarsApplicationMixin(ApplicationV2) { export default class DhCountdowns extends HandlebarsApplicationMixin(ApplicationV2) {
previusCountdownData = null; previousCountdownData = null;
changedCountdownsForAnimation = new Set(); changedCountdownsForAnimation = new Set();
countdownChangeAnimationTimeout = null; countdownChangeAnimationTimeout = null;
constructor(options = {}) { constructor(options = {}) {
super(options); super(options);
this.previusCountdownData = this.previousCountdownData =
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns).countdowns; game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns).countdowns;
this.setupHooks(); 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) { async _renderFrame(options) {
const frame = await super._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); 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; .countdowns;
/* Handle animations to draw attention to countdown values changing */ /* Handle animations to draw attention to countdown values changing */
@ -103,10 +113,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
}, 3000); }, 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) { 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) const countdown = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns)
.countdowns[countdownKey]; .countdowns[countdownKey];
if (!visibleTypes.includes(countdown?.type)) { 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) game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode)
=== CONFIG.DH.GENERAL.countdownAppMode.iconOnly; === CONFIG.DH.GENERAL.countdownAppMode.iconOnly;
context.userCountdownTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) context.userCountdownTypes = this.visibleCountdownTypes;
?? [shortterm.id, longterm.id];
context.typeToggles = context.typeToggles =
Object.values(CONFIG.DH.GENERAL.countdownType).map(type => ({ Object.values(CONFIG.DH.GENERAL.countdownType).map(type => ({
@ -231,6 +239,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
return true; return true;
} }
/** @this {DhCountdowns} */
static async #onToggleViewMode() { static async #onToggleViewMode() {
const currentMode = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode); const currentMode = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode);
const appMode = CONFIG.DH.GENERAL.countdownAppMode; const appMode = CONFIG.DH.GENERAL.countdownAppMode;
@ -242,9 +251,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
this.render(); this.render();
} }
/** @this {DhCountdowns} */
static async #onToggleCountdownTypes(event, target) { static async #onToggleCountdownTypes(event, target) {
const currentTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) const currentTypes = this.visibleCountdownTypes;
?? [shortterm.id, longterm.id];
const { type } = target.dataset; const { type } = target.dataset;
const newTypes = event.shiftKey ? const newTypes = event.shiftKey ?
[type] : [type] :
@ -254,10 +263,12 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
this.render(); this.render();
} }
/** @this {DhCountdowns} */
static async #onEditCountdowns() { static async #onEditCountdowns() {
new game.system.api.applications.ui.CountdownEdit().render(true); new game.system.api.applications.ui.CountdownEdit().render(true);
} }
/** @this {DhCountdowns} */
static async #onLoopCountdown(_, target) { static async #onLoopCountdown(_, target) {
if (!DhCountdowns.canPerformEdit()) return; if (!DhCountdowns.canPerformEdit()) return;

View file

@ -15,7 +15,7 @@ export default class DhCountdowns extends foundry.abstract.DataModel {
} }
handleChange() { handleChange() {
const previousCountdowns = foundry.ui.countdowns.previusCountdownData; const previousCountdowns = foundry.ui.countdowns.previousCountdownData;
const changedCountdowns = Object.entries(this.countdowns).reduce((acc, [key, countdown]) => { const changedCountdowns = Object.entries(this.countdowns).reduce((acc, [key, countdown]) => {
const previousCountdown = previousCountdowns[key]; const previousCountdown = previousCountdowns[key];
if (!previousCountdown || (previousCountdown.progress.current !== countdown.progress.current)) { if (!previousCountdown || (previousCountdown.progress.current !== countdown.progress.current)) {