40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
||
|
//
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
export const registerCombatTrackerFunctionality = () => {
|
||
|
CONFIG.ui.combat = CombatTrackerMixin(CONFIG.ui.combat as typeof CombatTracker); // TODO: improve upstream types
|
||
|
};
|
||
|
|
||
|
const CombatTrackerMixin = (BaseCombatTracker: typeof CombatTracker) => {
|
||
|
return class TickwerkCombatTracker extends BaseCombatTracker {
|
||
|
static override get defaultOptions(): ApplicationOptions {
|
||
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
||
|
template: 'modules/tickwerk/templates/combat-tracker.hbs',
|
||
|
});
|
||
|
}
|
||
|
|
||
|
override async getData(options?: Partial<ApplicationOptions>): Promise<CombatTracker.Data> {
|
||
|
const data = await super.getData(options);
|
||
|
return {
|
||
|
...data,
|
||
|
turns: data.turns.map((turn) => ({ ...turn, waiting: this.viewed?.combatants.get(turn.id)?.waiting })),
|
||
|
} as CombatTracker.Data; // TODO: Improve upstream types
|
||
|
}
|
||
|
override activateListeners(html: JQuery): void {
|
||
|
super.activateListeners(html);
|
||
|
html.find('.combatant-control[data-control="toggleWaiting"]').on('click', this._onToggleWaiting.bind(this));
|
||
|
}
|
||
|
|
||
|
_onToggleWaiting(event: JQuery.ClickEvent) {
|
||
|
event.preventDefault();
|
||
|
event.stopPropagation();
|
||
|
const button = event.currentTarget;
|
||
|
const li = button.closest('.combatant');
|
||
|
const combat = this.viewed;
|
||
|
const combatant = combat?.combatants.get(li.dataset.combatantId);
|
||
|
combatant?.toggleWaiting();
|
||
|
}
|
||
|
};
|
||
|
};
|