mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-24 11:29:54 +02:00
.
This commit is contained in:
parent
0961ad8d73
commit
114123ac50
1 changed files with 35 additions and 27 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
import { waitForDiceSoNice } from '../../helpers/utils.mjs';
|
import { waitForDiceSoNice } from '../../helpers/utils.mjs';
|
||||||
import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||||
|
import { SYSTEM } from './../../../module/config/system.mjs';
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||||
|
const { shortterm, longterm } = SYSTEM.GENERAL.countdownType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A UI element which displays the countdowns in this world.
|
* A UI element which displays the countdowns in this world.
|
||||||
|
|
@ -75,31 +77,20 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
||||||
async _onRender(context, options) {
|
async _onRender(context, options) {
|
||||||
await super._onRender(context, options);
|
await super._onRender(context, options);
|
||||||
|
|
||||||
/**/
|
/* Handle rendering/hiding/positioning of the countdown UI */
|
||||||
this.element.hidden = !game.user.isGM && this.#getCountdowns().length === 0;
|
this.element.hidden = !game.user.isGM && this.#getCountdowns().length === 0;
|
||||||
if (options?.force) {
|
if (options?.force) {
|
||||||
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)
|
||||||
|
.countdowns;
|
||||||
|
|
||||||
|
/* Handle animations to draw attention to countdown values changing */
|
||||||
if (this.changedCountdownsForAnimation.size) {
|
if (this.changedCountdownsForAnimation.size) {
|
||||||
if (this.countdownChangeAnimationTimeout)
|
if (this.countdownChangeAnimationTimeout)
|
||||||
clearTimeout(this.countdownChangeAnimationTimeout);
|
clearTimeout(this.countdownChangeAnimationTimeout);
|
||||||
|
|
||||||
for (const countdownKey of this.changedCountdownsForAnimation) {
|
|
||||||
this.element.querySelector(`.countdown-container[data-countdown="${countdownKey}"]`)
|
|
||||||
.classList.add('change-glow');
|
|
||||||
|
|
||||||
/* 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) ?? []
|
|
||||||
const countdown = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns)
|
|
||||||
.countdowns[countdownKey];
|
|
||||||
if (!visibleTypes.includes(countdown?.type)) {
|
|
||||||
this.element.querySelector(`.header-type-toggles .header-type[data-type="${countdown.type}"]`)
|
|
||||||
.classList.add('change-glow');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.countdownChangeAnimationTimeout = setTimeout(() => {
|
this.countdownChangeAnimationTimeout = setTimeout(() => {
|
||||||
this.changedCountdownsForAnimation.clear();
|
this.changedCountdownsForAnimation.clear();
|
||||||
for (const element of this.element.querySelectorAll('.countdown-container')) {
|
for (const element of this.element.querySelectorAll('.countdown-container')) {
|
||||||
|
|
@ -111,10 +102,25 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
|
||||||
|
|
||||||
this.previusCountdownData =
|
for (const countdownKey of this.changedCountdownsForAnimation) {
|
||||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns).countdowns;
|
/* 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)) {
|
||||||
|
this.element.querySelector(`.header-type-toggles .header-type[data-type="${countdown.type}"]`)
|
||||||
|
.classList.add('change-glow');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the countdown element is not rendered the user doesn't have permissiosn to it. No animation needed on the elment itself */
|
||||||
|
const countdownElement = this.element.querySelector(`.countdown-container[data-countdown="${countdownKey}"]`);
|
||||||
|
if (!countdownElement) continue;
|
||||||
|
|
||||||
|
countdownElement.classList.add('change-glow');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns countdown data filtered by ownership */
|
/** Returns countdown data filtered by ownership */
|
||||||
|
|
@ -178,13 +184,14 @@ 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 =
|
context.userCountdownTypes = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes)
|
||||||
game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes) ?? [];
|
?? [shortterm.id, longterm.id];
|
||||||
context.typeToggles = Object.values(CONFIG.DH.GENERAL.countdownType).map(type => ({
|
context.typeToggles =
|
||||||
type: type.id,
|
Object.values(CONFIG.DH.GENERAL.countdownType).map(type => ({
|
||||||
label: game.i18n.localize(type.label),
|
type: type.id,
|
||||||
active: context.userCountdownTypes.includes(type.id)
|
label: game.i18n.localize(type.label),
|
||||||
}));
|
active: context.userCountdownTypes.includes(type.id)
|
||||||
|
}));
|
||||||
|
|
||||||
context.countdowns = this._getCountdownData();
|
context.countdowns = this._getCountdownData();
|
||||||
|
|
||||||
|
|
@ -228,7 +235,8 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes)
|
||||||
|
?? [shortterm.id, longterm.id];
|
||||||
const { type } = target.dataset;
|
const { type } = target.dataset;
|
||||||
const newTypes = event.shiftKey ?
|
const newTypes = event.shiftKey ?
|
||||||
[type] :
|
[type] :
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue