2022-05-16 02:08:27 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
export const registerCombatTrackerFunctionality = () => {
|
2022-11-28 00:52:31 +01:00
|
|
|
CONFIG.ui.combat = CombatTrackerMixin(CONFIG.ui.combat);
|
2022-05-16 02:08:27 +02:00
|
|
|
};
|
|
|
|
|
2022-11-28 00:52:31 +01: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 {
|
2022-11-28 00:52:31 +01:00
|
|
|
/** @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',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-28 00:52:31 +01:00
|
|
|
/** @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-11-28 00:52:31 +01:00
|
|
|
};
|
2022-05-16 02:08:27 +02:00
|
|
|
}
|
2022-05-16 03:46:53 +02:00
|
|
|
|
2022-11-28 00:52:31 +01: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.
|
2022-11-28 00:52:31 +01:00
|
|
|
* @param {JQuery.ClickEvent} event The originating click event
|
2022-05-16 03:46:53 +02:00
|
|
|
*/
|
2022-11-28 00:52:31 +01: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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|