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) {
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;

View file

@ -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)) {