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

53 lines
1.6 KiB
JavaScript
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);
2022-05-16 02:08:27 +02:00
};
/**
* Enhance a combat tracker class with functionality for Tickwerk.
* @param {typeof CombatTracker} BaseCombatTracker The combat tracker class to enhance
* @returns The enhanced combat tracker class
*/
const CombatTrackerMixin = (BaseCombatTracker) => {
2022-05-16 02:08:27 +02:00
return class TickwerkCombatTracker extends BaseCombatTracker {
/** @override */
static get defaultOptions() {
2022-05-16 02:08:27 +02:00
return foundry.utils.mergeObject(super.defaultOptions, {
template: 'modules/tickwerk/templates/combat-tracker.hbs',
});
}
/** @override */
async getData(options) {
2022-05-16 02:08:27 +02:00
const data = await super.getData(options);
return {
...data,
turns: data.turns.map((turn) => ({ ...turn, waiting: this.viewed?.combatants.get(turn.id)?.waiting })),
};
2022-05-16 02:08:27 +02:00
}
2022-05-16 03:46:53 +02:00
/** @override */
activateListeners(html) {
2022-05-16 02:08:27 +02:00
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 {JQuery.ClickEvent} event The originating click event
2022-05-16 03:46:53 +02:00
*/
_onToggleWaiting(event) {
2022-05-16 02:08:27 +02:00
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();
}
};
};