diff --git a/module/ui/combat-hud.mjs b/module/ui/combat-hud.mjs index 0b45fa5a..5a5fe992 100644 --- a/module/ui/combat-hud.mjs +++ b/module/ui/combat-hud.mjs @@ -187,6 +187,7 @@ export class CombatHUD extends Application { isOwner: combatant.isOwner, totalTurns: combatant.totalTurns, token: combatant.token, + faction: combatant.faction, effects: activeEffects, img: game.settings.get(SYSTEM, SETTINGS.optionCombatHudPortrait) === 'token' @@ -337,6 +338,7 @@ export class CombatHUD extends Application { html.find('a[data-action=start-turn]').click((event) => ui.combat.handleStartTurn(event)); html.find('a[data-action=end-turn]').click((event) => ui.combat.handleEndTurn(event)); + html.find('a[data-action=take-turn-out-of-turn]').click((event) => ui.combat.handleTakeTurnOutOfTurn(event)); } _doHudDragStart(event) { diff --git a/module/ui/combat-tracker.mjs b/module/ui/combat-tracker.mjs index 29a9291b..176a663e 100644 --- a/module/ui/combat-tracker.mjs +++ b/module/ui/combat-tracker.mjs @@ -36,7 +36,6 @@ export class FUCombatTracker extends CombatTracker { if (data.turns.size === 0) { console.error(`Found no available turns on combat ${combat}`); } - data.factions = await this.getFactions(data.turns, combat); } return data; } @@ -145,7 +144,7 @@ export class FUCombatTracker extends CombatTracker { async handleTakeTurnOutOfTurn(event) { if (event.shiftKey) { - await this.handleEndTurn(event); + await this.handleStartTurn(event); } else { ui.notifications.info('FU.CombatTakeTurnOutOfTurn', { localize: true }); } diff --git a/module/ui/combat.mjs b/module/ui/combat.mjs index 758a8509..1e30b5c5 100644 --- a/module/ui/combat.mjs +++ b/module/ui/combat.mjs @@ -369,11 +369,37 @@ export class FUCombat extends Combat { data.combatant = this.combatant; // ID : Turns Left data.turnsLeft = this.countTurnsLeft(); + data.factions = this.getFactions(); // What faction's turn it is data.currentTurn = this.getCurrentTurn(); data.outOfTurn = false; data.round = this.round; data.isGM = game.user.isGM; + + console.debug(`Combat round ${this.round}, current faction ${data.currentTurn}`); + for (const combatant of this.combatants) { + console.debug(`- Combatant: ${combatant.name}, faction: ${combatant.faction}, isOwner: ${combatant.isOwner}`); + } + } + + /** + * @param turns + * @param {FUCombat} combat + * @return {Object.<"friendly"|"neutral"|"hostile", {}[]>} + */ + getFactions() { + return this.combatants.reduce( + (agg, combatant) => { + //const combatant = combat.combatants.get(combatantData.id); + if (combatant.token.disposition === foundry.CONST.TOKEN_DISPOSITIONS.FRIENDLY) { + agg.friendly.push(combatant); + } else { + agg.hostile.push(combatant); + } + return agg; + }, + { friendly: [], hostile: [] }, + ); } /** diff --git a/templates/ui/partials/combat-hud-turn.hbs b/templates/ui/partials/combat-hud-turn.hbs index 14fc5dfd..8c6a0a35 100644 --- a/templates/ui/partials/combat-hud-turn.hbs +++ b/templates/ui/partials/combat-hud-turn.hbs @@ -1,32 +1,33 @@ {{#if @root.hasCombatStarted}} + {{! If the combatant HAS turns left }} {{#if (and @root.round (lookup @root.turnsLeft this.id))}} + {{! If a combatant has already started a turn }} {{#if @root.turnStarted}} {{#if (eq @root.combatant.id this.id)}} check_circle {{/if}} + {{! If a combatant can start a turn }} {{else}} - - counter_{{lookup @root.turnsLeft this.id}} - - {{/if}} - {{else}} - {{#if @root.outOfTurn}} - {{#if this.owner}} - - {{# if (gt (lookup @root.totalTurns this.id) 1)}} - counter_{{lookup @root.turnsLeft this.id}} - {{else}} - check_circle - {{/if}} + {{! If the combatant's faction CAN take a turn}} + {{#if (eq @root.currentTurn this.faction)}} + + counter_{{lookup @root.turnsLeft this.id}} + {{! If the turn is taken out of order due to some mechanic }} {{else}} - - check_circle - + {{#if this.isOwner}} + + counter_{{lookup @root.turnsLeft this.id}} + + {{/if}} {{/if}} {{/if}} + {{! If the combatant has NO turns left }} + {{else}} + + check_circle + {{/if}} {{/if}} \ No newline at end of file