Skip to content

Commit

Permalink
Fix combat hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mclemente committed Jul 10, 2024
1 parent f169ac2 commit b537248
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/module/healthEstimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 2 additions & 15 deletions src/module/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -111,28 +110,16 @@ 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));
});
}

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));
Expand Down
1 change: 0 additions & 1 deletion src/module/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const registerSettings = function () {
default: false,
onChange: (value) => {
game.healthEstimate.combatOnly = value;
HealthEstimateHooks.combatHooks(value);
},
});
addMenuSetting("core.showDescription", {
Expand Down

0 comments on commit b537248

Please sign in to comment.