tickwerk/src/apps/sidebar/combat-tracker.ts

45 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-05-16 02:08:27 +02:00
// 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
}
2022-05-16 03:46:53 +02:00
2022-05-16 02:08:27 +02:00
override activateListeners(html: JQuery): void {
super.activateListeners(html);
html.find('.combatant-control[data-control="toggleWaiting"]').on('click', this._onToggleWaiting.bind(this));
}
2022-05-16 03:46:53 +02:00
/**
* Handle clicks on the Combatant waiting control button.
* @param event The originating click event
*/
2022-05-16 02:08:27 +02:00
_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();
}
};
};