mclemente / healthEstimate

See the state of a character's health with a simple mouse-hover.
MIT License
22 stars 34 forks source link

Hit Points Attribute Data Path setting ignored on tokens with zero HP #212

Closed tech-ticks closed 1 year ago

tech-ticks commented 1 year ago

Describe the bug GenericEstimationProvider ignores the "Hit Points Attribute Data Path" (core.custom.FractionHP) setting on tokens with zero HP. The following code is responsible:

const hpPath = sGet("core.custom.FractionHP");
let hp = (hpPath && getNestedData(token, hpPath))
    || (game.system.primaryTokenAttribute
        && getNestedData(token, `actor.system.${game.system.primaryTokenAttribute}`))
    || token.actor.system.attributes?.hp
    || token.actor.system.hp;

If the value returned by getNestedData is zero, the || operator will incorrectly evaluate the alternative paths. token.actor.system.hp is an object rather than a number in the system I tested with, so the module throws errors on each token with zero HP.

To Reproduce

  1. Create a world with the Pokérole system
  2. Create an actor with 0 HP
  3. Set the "Hit Points Attribute Data Path" setting to actor.system.hp.value
  4. Reload and observe errors in the console

Expected behavior The "Hit Points Attribute Data Path" should be used regardless of the underlying HP value.

Game Specifics (please complete the following information):