From 47a6abddfb5bcfd38e68ee179eb1b1c479784dad Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sat, 7 Jun 2025 00:26:21 +0200 Subject: [PATCH] CombatTracker was throwing an error when there were no combatants --- module/ui/combatTracker.mjs | 4 ++-- templates/ui/combat/combatTracker.hbs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/module/ui/combatTracker.mjs b/module/ui/combatTracker.mjs index 46f7f318..8b71f627 100644 --- a/module/ui/combatTracker.mjs +++ b/module/ui/combatTracker.mjs @@ -30,8 +30,8 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C async _prepareTrackerContext(context, options) { await super._prepareTrackerContext(context, options); - const adversaries = context.turns.filter(x => x.isNPC); - const characters = context.turns.filter(x => !x.isNPC); + const adversaries = context.turns?.filter(x => x.isNPC) ?? []; + const characters = context.turns?.filter(x => !x.isNPC) ?? []; Object.assign(context, { actionTokens: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).actionTokens, diff --git a/templates/ui/combat/combatTracker.hbs b/templates/ui/combat/combatTracker.hbs index 8de5640a..13bd512e 100644 --- a/templates/ui/combat/combatTracker.hbs +++ b/templates/ui/combat/combatTracker.hbs @@ -1,4 +1,8 @@
- {{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Character.Plural") turns=this.characters}} - {{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Adversary.Plural") turns=this.adversaries}} + {{#if (gt this.characters.length 0)}} + {{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Character.Plural") turns=this.characters}} + {{/if}} + {{#if (gt this.adversaries.length 0)}} + {{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Adversary.Plural") turns=this.adversaries}} + {{/if}}
\ No newline at end of file