This commit is contained in:
Psitacus 2026-01-10 00:01:12 +00:00 committed by GitHub
commit 64c0e38664
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 97 additions and 19 deletions

View file

@ -15,6 +15,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
super(options);
this.setupHooks();
this._isFocused = false;
}
/** @inheritDoc */
@ -90,7 +91,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
countdown,
ownership: DhCountdowns.#getPlayerOwnership(game.user, setting, countdown)
}));
return values.filter(v => v.ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE);
return values.filter(v =>
v.ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE
);
}
/** @override */
@ -102,14 +105,18 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode) ===
CONFIG.DH.GENERAL.countdownAppMode.iconOnly;
const setting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
context.countdowns = this.#getCountdowns().reduce((acc, { key, countdown, ownership }) => {
const playersWithAccess = game.users.reduce((acc, user) => {
const ownership = DhCountdowns.#getPlayerOwnership(user, setting, countdown);
if (!user.isGM && ownership && ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE) {
acc.push(user);
}
return acc;
}, []);
const allCountdowns = this.#getCountdowns();
const { longTermCountdowns, otherCountdowns } = allCountdowns.reduce((acc, { key, countdown, ownership }) => {
const playersWithAccess = game.users.reduce((acc, user) => {
const ownership = DhCountdowns.#getPlayerOwnership(user, setting, countdown);
if (!user.isGM && ownership && ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE) {
acc.push(user);
}
return acc;
}, []);
const nonGmPlayers = game.users.filter(x => !x.isGM);
const countdownEditable = game.user.isGM || ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;
@ -125,7 +132,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
!countdownEditable ||
(isLooping && (countdown.progress.current > 0 || countdown.progress.start === '0'));
acc[key] = {
const countdownData = {
...countdown,
editable: countdownEditable,
noPlayerAccess: nonGmPlayers.length && playersWithAccess.length === 0,
@ -133,12 +140,37 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
loopDisabled: isLooping ? loopDisabled : null,
loopTooltip: isLooping && game.i18n.localize(loopTooltip)
};
if (countdown.type == CONFIG.DH.GENERAL.countdownBaseTypes.longterm.id){
if (this._isFocused){
acc.longTermCountdowns.push([key, countdownData]);
}
} else {
acc.otherCountdowns.push([key, countdownData])
}
return acc;
}, {longTermCountdowns: [], otherCountdowns: []});
// Combine: regular countdowns first, then long-term
context.countdowns = [...otherCountdowns, ...longTermCountdowns].reduce((acc, [key, countdown]) => {
acc[key]=countdown;
return acc;
}, {});
context.hasHiddenLongTerm = !this._isFocused && allCountdowns.some(
({countdown}) => countdown.type === CONFIG.DH.GENERAL.countdownBaseTypes.longterm.id
);
return context;
}
/**Filter countdowns based on focus state */
#shouldShowCountdown(countdown){
// Always show narrative and encounter countdowns
if (countdown.type !== CONFIG.DH.GENERAL.countdownBaseTypes.longterm.id){
return true;
}
// Only show longterm countdowns when focused/hovered
return this._isFocused;
}
static #getPlayerOwnership(user, setting, countdown) {
const playerOwnership = countdown.ownership[user.id];
return playerOwnership === undefined || playerOwnership === CONST.DOCUMENT_OWNERSHIP_LEVELS.INHERIT
@ -236,6 +268,19 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
setupHooks() {
Hooks.on(socketEvent.Refresh, this.cooldownRefresh.bind());
}
#onFocus() {
if (!this._isFocused){
this._isFocused = true;
this.render()
}
}
#onBlur() {
if (this._isFocused){
this._isFocused = false;
this.render()
}
}
async close(options) {
/* Opt out of Foundry's standard behavior of closing all application windows marked as UI when Escape is pressed */
@ -291,5 +336,10 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
if (options?.force) {
document.getElementById('ui-right-column-1')?.appendChild(this.element);
}
// Hover/focus listeners
this.element.addEventListener('mouseenter', this.#onFocus.bind(this));
this.element.addEventListener('mouseleave', this.#onBlur.bind(this));
this.element.addEventListener('focusin', this.#onFocus.bind(this));
this.element.addEventListener('focusout', this.#onBlur.bind(this));
}
}

View file

@ -690,6 +690,10 @@ export const countdownBaseTypes = {
encounter: {
id: 'encounter',
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter'
},
longterm: {
id: 'longterm',
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.longterm'
}
};