diff --git a/src/module/healthEstimate.js b/src/module/healthEstimate.js index 5008216..9633bbd 100644 --- a/src/module/healthEstimate.js +++ b/src/module/healthEstimate.js @@ -12,6 +12,9 @@ Hooks.once("ready", () => game.healthEstimate.ready()); // Canvas Hooks.once("canvasReady", HealthEstimateHooks.onceCanvasReady); +Hooks.on("combatStart", HealthEstimateHooks.onCombatStart); +Hooks.on("updateCombat", HealthEstimateHooks.onUpdateCombat); +Hooks.on("deleteCombat", HealthEstimateHooks.onUpdateCombat); Hooks.on("canvasReady", HealthEstimateHooks.onCanvasReady); Hooks.on("3DCanvasSceneReady", () => setTimeout(HealthEstimateHooks.onCanvasReady, 10)); Hooks.on("createToken", HealthEstimateHooks.onCreateToken); diff --git a/src/module/hooks.js b/src/module/hooks.js index 3408cef..bee13cf 100644 --- a/src/module/hooks.js +++ b/src/module/hooks.js @@ -10,7 +10,6 @@ export class HealthEstimateHooks { static onceCanvasReady() { game.healthEstimate.combatOnly = sGet("core.combatOnly"); - if (game.healthEstimate.combatOnly) HealthEstimateHooks.combatHooks(game.healthEstimate.combatOnly); game.healthEstimate.alwaysShow = sGet("core.alwaysShow"); game.healthEstimate.combatRunning = game.healthEstimate.isCombatRunning(); Hooks.on("refreshToken", HealthEstimateHooks.refreshToken); @@ -111,21 +110,8 @@ export class HealthEstimateHooks { game.healthEstimate._handleOverlay(token, game.healthEstimate.showCondition(token.hover)); } - // Not an actual hook - static combatHooks(value) { - if (!canvas.ready) return; - if (value) { - Hooks.on("combatStart", HealthEstimateHooks.onCombatStart); - Hooks.on("updateCombat", HealthEstimateHooks.onUpdateCombat); - Hooks.on("deleteCombat", HealthEstimateHooks.onUpdateCombat); - } else { - Hooks.off("combatStart", HealthEstimateHooks.onCombatStart); - Hooks.off("updateCombat", HealthEstimateHooks.onUpdateCombat); - Hooks.off("deleteCombat", HealthEstimateHooks.onUpdateCombat); - } - } - static onCombatStart(combat, updateData) { + if (!game.healthEstimate.combatOnly) return; game.healthEstimate.combatRunning = true; canvas.tokens?.placeables.forEach((token) => { game.healthEstimate._handleOverlay(token, game.healthEstimate.showCondition(token.hover)); @@ -133,6 +119,7 @@ export class HealthEstimateHooks { } static onUpdateCombat(combat, options, userId) { + if (!game.healthEstimate.combatOnly) return; game.healthEstimate.combatRunning = game.healthEstimate.isCombatRunning(); canvas.tokens?.placeables.forEach((token) => { game.healthEstimate._handleOverlay(token, game.healthEstimate.showCondition(token.hover)); diff --git a/src/module/settings.js b/src/module/settings.js index 88efae9..4d0425a 100644 --- a/src/module/settings.js +++ b/src/module/settings.js @@ -90,7 +90,6 @@ export const registerSettings = function () { default: false, onChange: (value) => { game.healthEstimate.combatOnly = value; - HealthEstimateHooks.combatHooks(value); }, }); addMenuSetting("core.showDescription", {