mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Added handling for multiselect toggleCombat
This commit is contained in:
parent
9b3d1cddc4
commit
4cf01f7427
1 changed files with 23 additions and 3 deletions
|
|
@ -1,6 +1,9 @@
|
|||
export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart']
|
||||
classes: ['daggerheart'],
|
||||
actions: {
|
||||
combat: DHTokenHUD.#onToggleCombat
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
|
|
@ -11,11 +14,14 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
}
|
||||
};
|
||||
|
||||
static #nonCombatTypes = ['environment', 'companion'];
|
||||
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
const nonCombatTypes = ['environment', 'companion'];
|
||||
|
||||
context.canToggleCombat = nonCombatTypes.includes(this.actor.type) ? false : context.canToggleCombat;
|
||||
context.canToggleCombat = DHTokenHUD.#nonCombatTypes.includes(this.actor.type)
|
||||
? false
|
||||
: context.canToggleCombat;
|
||||
context.systemStatusEffects = Object.keys(context.statusEffects).reduce((acc, key) => {
|
||||
const effect = context.statusEffects[key];
|
||||
if (effect.systemEffect) acc[key] = effect;
|
||||
|
|
@ -39,6 +45,20 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
return context;
|
||||
}
|
||||
|
||||
static async #onToggleCombat() {
|
||||
const tokens = canvas.tokens.controlled
|
||||
.filter(t => !t.actor || !DHTokenHUD.#nonCombatTypes.includes(t.actor.type))
|
||||
.map(t => t.document);
|
||||
if (!this.object.controlled) tokens.push(this.document);
|
||||
|
||||
try {
|
||||
if (this.document.inCombat) await TokenDocument.implementation.deleteCombatants(tokens);
|
||||
else await TokenDocument.implementation.createCombatants(tokens);
|
||||
} catch (err) {
|
||||
ui.notifications.warn(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
_getStatusEffectChoices() {
|
||||
// Include all HUD-enabled status effects
|
||||
const choices = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue