export default class DhCombatTracker extends foundry.applications.sidebar.tabs.CombatTracker { static DEFAULT_OPTIONS = { actions: { requestSpotlight: this.requestSpotlight, toggleSpotlight: this.toggleSpotlight, setActionTokens: this.setActionTokens } }; static PARTS = { header: { template: 'systems/daggerheart/templates/ui/combat/combatTrackerHeader.hbs' }, tracker: { template: 'systems/daggerheart/templates/ui/combat/combatTracker.hbs' }, footer: { template: 'systems/daggerheart/templates/ui/combat/combatTrackerFooter.hbs' } }; async _prepareCombatContext(context, options) { await super._prepareCombatContext(context, options); Object.assign(context, { fear: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear) }); } async _prepareTrackerContext(context, options) { await super._prepareTrackerContext(context, options); Object.assign(context, { actionTokens: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).actionTokens }); } async _prepareTurnContext(combat, combatant, index) { const turn = await super._prepareTurnContext(combat, combatant, index); return { ...turn, isNPC: combatant.isNPC, system: combatant.system.toObject() }; } _getCombatContextOptions() { return [ { name: 'COMBAT.ClearMovementHistories', icon: '', condition: () => game.user.isGM && this.viewed?.combatants.size > 0, callback: () => this.viewed.clearMovementHistories() }, { name: 'COMBAT.Delete', icon: '', condition: () => game.user.isGM && !!this.viewed, callback: () => this.viewed.endCombat() } ]; } static async requestSpotlight(_, target) { const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {}; const combatant = this.viewed.combatants.get(combatantId); await combatant.update({ 'system.spotlight': { requesting: !combatant.system.spotlight.requesting } }); this.render(); } static async toggleSpotlight(_, target) { const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {}; for (var combatant of this.viewed.combatants) { const giveSpotlight = combatant.id === combatantId; await combatant.update({ 'system.spotlight': { requesting: giveSpotlight ? false : combatant.system.spotlight.requesting, active: giveSpotlight ? !combatant.system.spotlight.active : false } }); } } static async setActionTokens(_, target) { const { combatantId, tokenIndex } = target.closest('[data-combatant-id]')?.dataset ?? {}; const combatant = this.viewed.combatants.get(combatantId); const changeIndex = Number(tokenIndex); const newIndex = combatant.system.actionTokens > changeIndex ? changeIndex : changeIndex + 1; await combatant.update({ 'system.actionTokens': newIndex }); this.render(); } }