From ec5ad470f8725aef4b02ef9e2b6035024072322d Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 15 Feb 2025 15:41:48 -0700 Subject: [PATCH] Apply PR feedback --- module/Apps/sidebar/CombatTracker.mjs | 12 ++++++---- module/documents/combat.mjs | 17 +++++--------- module/documents/combatant.mjs | 32 ++++++++++++++++++--------- module/documents/token.mjs | 13 ++++++++--- module/settings/metaSettings.mjs | 6 +++-- module/utils/distanceBetweenFates.mjs | 4 ++-- 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/module/Apps/sidebar/CombatTracker.mjs b/module/Apps/sidebar/CombatTracker.mjs index bbef58f..8cffd77 100644 --- a/module/Apps/sidebar/CombatTracker.mjs +++ b/module/Apps/sidebar/CombatTracker.mjs @@ -2,6 +2,10 @@ const { CombatTracker } = foundry.applications.sidebar.tabs; export class RipCryptCombatTracker extends CombatTracker { /** + * Changes the way the combat tracker renders combatant rows to account for + * multiple combatants being in the same combat "group", thus all going at the + * same time. + * * @override */ async _prepareTurnContext(combat, combatant, index) { @@ -14,7 +18,7 @@ export class RipCryptCombatTracker extends CombatTracker { if (groupKey && combat.started) { turn.active ||= combat.combatant?.groupKey === groupKey; if (turn.active && !turn.css.includes(`active`)) { - turn.css += `active`; + turn.css += ` active`; }; }; @@ -26,8 +30,8 @@ export class RipCryptCombatTracker extends CombatTracker { // Purge the combat controls that I don't want to exist because they don't // make sense in the system. - this.element.querySelector(`[data-action="resetAll"]`)?.remove(); - this.element.querySelector(`[data-action="rollNPC"]`)?.remove(); - this.element.querySelector(`[data-action="rollAll"]`)?.remove(); + this.element?.querySelector(`[data-action="resetAll"]`)?.remove(); + this.element?.querySelector(`[data-action="rollNPC"]`)?.remove(); + this.element?.querySelector(`[data-action="rollAll"]`)?.remove(); }; }; diff --git a/module/documents/combat.mjs b/module/documents/combat.mjs index 18cfc48..fa76361 100644 --- a/module/documents/combat.mjs +++ b/module/documents/combat.mjs @@ -44,7 +44,7 @@ export class RipCryptCombat extends Combat { }; async nextTurn() { - if ( this.round === 0 ) {return this.nextRound()} + if (this.round === 0) {return this.nextRound()} const turn = this.turn ?? -1; @@ -61,7 +61,7 @@ export class RipCryptCombat extends Combat { }; // Maybe advance to the next round - if ( (nextTurn === null) || (nextTurn >= this.turns.length) ) {return this.nextRound()} + if ((nextTurn === null) || (nextTurn >= this.turns.length)) {return this.nextRound()} const advanceTime = this.getTimeDelta(this.round, this.turn, this.round, nextTurn); @@ -107,9 +107,12 @@ export class RipCryptCombat extends Combat { }; /** - * Update display of Token combat turn markers. + * Overridden to make it so that there can be multiple tokens with turn markers + * visible at the same time. + * * @protected * @internal + * @override */ _updateTurnMarkers() { if (!canvas.ready) { return }; @@ -133,12 +136,4 @@ export class RipCryptCombat extends Combat { } } } - - async _manageTurnEvents() { - try { - await super._manageTurnEvents(); - } catch { - this._updateTurnMarkers(); - }; - }; }; diff --git a/module/documents/combatant.mjs b/module/documents/combatant.mjs index 21e1ba8..6de765b 100644 --- a/module/documents/combatant.mjs +++ b/module/documents/combatant.mjs @@ -24,11 +24,13 @@ export class RipCryptCombatant extends Combatant { total += distanceBetweenFates(start, end); const whoFirst = game.settings.get(`ripcrypt`, `whoFirst`); - const disposition = this.disposition; - if (disposition === `unknown`) { - total += 0.25; - } else if (whoFirst && whoFirst !== disposition) { - total += 0.5; + if (whoFirst) { + const disposition = this.disposition; + if (disposition === `unknown`) { + total += 0.25; + } else if (whoFirst !== disposition) { + total += 0.5; + }; }; return total; @@ -46,15 +48,23 @@ export class RipCryptCombatant extends Combatant { return `${path}:${disposition}`; }; + /** + * Used to create the turn marker when the combatant is added if they're in + * the group whose turn it is. + * + * @override + */ _onCreate() { - if (this.token) { - this.token._object._refreshTurnMarker(); - }; + this.token?._object?._refreshTurnMarker(); }; + /** + * Used to remove the turn marker when the combatant is removed from combat + * if they had it visible so that it doesn't stick around infinitely. + * + * @override + */ _onDelete() { - if (this.token) { - this.token._object._refreshTurnMarker(); - }; + this.token?._object?._refreshTurnMarker(); }; }; diff --git a/module/documents/token.mjs b/module/documents/token.mjs index 2b66aac..458230e 100644 --- a/module/documents/token.mjs +++ b/module/documents/token.mjs @@ -1,6 +1,13 @@ const { TokenTurnMarker } = foundry.canvas.placeables.tokens; export class RipCryptToken extends Token { + /** + * Overridden using a slightly modified implementation in order to make it so + * that the turn marker shows up on tokens if they're in the same group as the + * currently active combatant + * + * @override + */ _refreshTurnMarker() { // Should a Turn Marker be active? const {turnMarker} = this.document; @@ -12,13 +19,13 @@ export class RipCryptToken extends Token { const markerActive = markersEnabled && isTurn && !isDefeated; // Activate a Turn Marker - if ( markerActive ) { - if ( !this.turnMarker ) { + if (markerActive) { + if (!this.turnMarker) { this.turnMarker = this.addChildAt(new TokenTurnMarker(this), 0); }; canvas.tokens.turnMarkers.add(this); this.turnMarker.draw(); - } else if ( this.turnMarker ) { + } else if (this.turnMarker) { canvas.tokens.turnMarkers.delete(this); this.turnMarker.destroy(); this.turnMarker = null; diff --git a/module/settings/metaSettings.mjs b/module/settings/metaSettings.mjs index d0b6798..7694088 100644 --- a/module/settings/metaSettings.mjs +++ b/module/settings/metaSettings.mjs @@ -14,8 +14,10 @@ export function registerMetaSettings() { type: String, config: false, requiresReload: false, - onChange: () => { - ui.crypt.render({ parts: [ `fate` ] }); + onChange: async () => { + await ui.crypt.render({ parts: [ `fate` ] }); + await game.combat.setupTurns(); + await ui.combat.render({ parts: [ `tracker` ] }); }, }); diff --git a/module/utils/distanceBetweenFates.mjs b/module/utils/distanceBetweenFates.mjs index 78a603a..4eaaddd 100644 --- a/module/utils/distanceBetweenFates.mjs +++ b/module/utils/distanceBetweenFates.mjs @@ -4,8 +4,8 @@ import { Logger } from "./Logger.mjs"; const { FatePath } = gameTerms; export function isOppositeFates(a, b) { - return a === FatePath.NORTH && b === FatePath.SOUTH - || a === FatePath.EAST && FatePath.WEST; + return (a === FatePath.NORTH && b === FatePath.SOUTH) + || (a === FatePath.EAST && b === FatePath.WEST); }; export function distanceBetweenFates(start, end) {