Skip to content

feat(HealthColors): version 2.0.1 - better negative health value handling#2205

Merged
Alicekb merged 23 commits intoRoll20:masterfrom
steverobertsuk:sr/fix-negative-health-values
Apr 30, 2026
Merged

feat(HealthColors): version 2.0.1 - better negative health value handling#2205
Alicekb merged 23 commits intoRoll20:masterfrom
steverobertsuk:sr/fix-negative-health-values

Conversation

@steverobertsuk
Copy link
Copy Markdown
Contributor

  • Fixed behavior for tokens with health below zero to ensure consistent application of the "dead" marker.
  • Clamped negative health values to zero for accurate color mapping and visual feedback.
  • Refactored applyAuraAndDead to separate dead-marker logic from aura updates for better edge case handling.
  • Updated percentToHex to normalize input values, preventing invalid color calculations.
  • Improved code readability and maintainability by restructuring health percentage calculations.

…lity

Upgrade the script to version 2.0.0, performing a major modernisation refactor. This update ensures the script respects manual visual overrides by only triggering on health changes, removes the Underscore.js dependency, and adds JSDoc documentation to improve long-term maintainability. Fixes bugs where aura2 does not show, especially when changing health values.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…onfig function.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Increment SCHEMA_VERSION from 1.0.3 to 1.1.0 to track incremental state
migrations in the v2.0.0 line. Update UPDATED timestamp to 2026-04-09.
Fix two adjacent JSDoc spellings (behaviour, colours) in the same hunk.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Replace colour/colours with color/colors, artefacts with artifacts, and
specialised with specialized throughout JSDoc and inline comments.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…lt color

Add five new keys to DEFAULTS:
  Aura1Shape ("Circle"), Aura1Color ("00FF00"),
  Aura2Size (5), Aura2Shape ("Square"), Aura2Color ("806600").

Change the default HealFX color from 00FF00 to FDDC5C (gold) for better
visual contrast in the default heal particle effect.

Update JSDoc for the DEFAULTS object to document all new properties.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…olor key aliases

Replace placeholder FX_PARAM_DEFAULTS values (size 100, emissionRate 100,
opaque white start color, zero speed) with production-ready values that
render more clearly in-game: size 15, lifeSpan 50, emissionRate 10, speed 1,
neutral grey start color [128,128,128,1].

Add both British (startColour/endColour) and American (startColor/endColor)
property aliases and their Random counterparts so the defaults object is safe
to spread regardless of which key variant the Roll20 sandbox or caller uses.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…s in spawnFX

Add spawnFx to the global script declaration so the sandbox linter
recognises its use in the new fallback spawn path.

Improve hexToRgb: strip leading "#" and whitespace before regex match, and
log a warning when a non-empty invalid hex string is received.

Add getFxDefinition(fxObj): safely reads and deep-clones a Roll20 custfx
definition, handling both string-JSON and plain-object return forms.

Revamp spawnFX to pick the correct start/end color from the incoming fx
partial first, then the merged defaults, checking both British (startColour)
and American (startColor) key variants. Pass both aliases to
spawnFxWithDefinition so the definition is valid regardless of what the
Roll20 client expects. Also neutralize all random color channels.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…helpers

Add normalizeHex6(value, fallback): strips "#" and whitespace, upper-cases,
and validates a 6-digit hex string, returning the fallback on invalid input.

Add normalizeShape(value, fallback): normalizes a shape label to "Circle" or
"Square", returning the fallback for any other input.

Both helpers are used by the new !aura a1tint, !aura a2tint, !aura a1shape,
and !aura a2shape command handlers to validate user-supplied values.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Add buildDefaultFxDefinition(isHeal, baseDef): builds a normalized color and
particle payload for default heal/hurt custfx objects, applying tuned values
(maxParticles 220/size 12/lifeSpan 40 for heal; 200/10/22 for hurt) and
neutralizing all random color channels.

Add syncDefaultFxObjects(): applies current HealFX/HurtFX colors and profile
tuning to the campaign -DefaultHeal/-DefaultHurt custfx objects immediately.
Called from checkInstall so definitions are correct on first load and
whenever FX color settings change.

Add resetDefaultFxObjects(): removes stale default custfx objects and
recreates them via checkInstall; backs the !aura reset-fx command.

Add resetAllSettingsToDefaults() and runResetAllFlow(): restore all state to
DEFAULTS, rebuild default FX, and force-sync all tokens; backs !aura reset-all.

Document the optional update parameter in the getBarHealth JSDoc.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…d fallback

Refactor buildFXList to use getFxDefinition instead of calling
.get("definition") directly. In all code paths (heal, default hurt, custom
hurt), set both startColour/startColor and endColour/endColor to the
resolved RGB and neutralize all random color channels. This prevents
grey/white fallback artifacts from missing color key variants.

Add spawnDefaultFxById(obj, isHeal, useBlood): a fallback spawn path that
spawns the default custfx by ID using spawnFx(), bypassing
spawnFxWithDefinition color inconsistencies seen in some Roll20
sandbox/client combinations for default heal/hurt effects.

Call spawnDefaultFxById as an early exit in triggerFX before the
definition-based path so default heal/hurt visuals are consistent.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…eAll scope

In handleToken, check whether the configured health bar has a max value
before processing. If bar_max is empty, call clearAuras and return early,
preventing stale health indicators on tokens without a configured bar.

In menuForceUpdate, remove the filter that restricted the work queue to
tokens with a populated bar_max and bar_value. All tokens on the objects
layer are now included so the re-evaluation (including clearing auras on
unconfigured tokens) runs for the full map.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Add makePill(label, extraStyle): a styled non-interactive span element for
read-only display in the settings snapshot panel, styled to match the GM
menu look but without a clickable action.

Add showSettingsInGameChat(): renders the complete current settings as a
public game-chat panel using makePill elements so all players and the GM
can see active configuration. Includes colored boolean indicators, FX color
swatches, and Aura 1/2 detail rows backed by the new state keys.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
… labels

In showMenu:
  - Rename "Bar:" to "Health Bar:" for clarity.
  - Add Aura 1 Radius (ft) units suffix.
  - Add Aura 1 Shape and Aura 1 Color (Tint) interactive buttons backed by
    the new !aura a1shape and !aura a1tint commands.
  - Add Aura 2 Radius (ft), Aura 2 Shape, and Aura 2 Color (Tint) buttons
    backed by !aura a2size, !aura a2shape, and !aura a2tint commands.
  - Update HealFX Color default hint in the button URL to FDDC5C to match
    the new default.
  - Add aura1Style / aura2Style variables for colored button backgrounds.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…n, Aura1/2 commands, and post-change snapshot

Split !aura on/off into two explicit cases so on always enables and off
always disables, replacing the previous toggle on the on case.

Add input validation for !aura bar: accepts only 1, 2, or 3; whispers
confirmation and immediately calls menuForceUpdate on a valid change;
whispers a clear error on an invalid value.

Add new Aura 1/2 commands: !aura a1shape, !aura a1tint, !aura a2size,
!aura a2shape, !aura a2tint — each validated through normalizeShape or
normalizeHex6 before updating state.

Add !aura reset-fx and !aura reset-all recovery commands backed by
resetDefaultFxObjects and runResetAllFlow respectively.

Add !aura settings to output the current settings snapshot on demand.

Introduce a changedSetting flag: when any setting changes, call
showSettingsInGameChat instead of showMenu to post a single read-only
snapshot to game chat; non-mutating commands still show the GM menu.

Call syncDefaultFxObjects immediately after HEAL and HURT color changes.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
CHANGELOG (v2.0.0 section):
  - Added entries for !aura reset-fx, !aura reset-all, !aura settings,
    Aura 1/2 detail commands, public settings snapshot, and !aura on/off
    semantics change. Bumped schema version entry to 1.1.0.
  - Added Fixed entries for FX color assignment, random channel
    neutralization, spawnFx fallback path, particle profile tuning,
    BAR validation, empty bar_max handling, Aura 1/2 output rows,
    settings output deduplication, and proactive FX definition sync.

README:
  - Document !aura settings, !aura a1shape/a1tint/a2size/a2shape/a2tint,
    !aura reset-fx, and !aura reset-all commands.
  - Update !aura bar description to include immediate token sync behavior.
  - Update !aura heal default hint to FDDC5C.
  - Add note about Aura 1/2 detail rows in settings output.
  - Note that setting changes post a single game-chat snapshot.
  - Add troubleshooting notes for FX rendering variance and missing
    bar max value.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…l20 profile links of authors

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
- Fixed behavior for tokens with health below zero to ensure consistent application of the "dead" marker.
- Clamped negative health values to zero for accurate color mapping and visual feedback.
- Refactored `applyAuraAndDead` to separate dead-marker logic from aura updates for better edge case handling.
- Updated `percentToHex` to normalize input values, preventing invalid color calculations.
- Improved code readability and maintainability by restructuring health percentage calculations.
@Alicekb
Copy link
Copy Markdown
Contributor

Alicekb commented Apr 22, 2026

@steverobertsuk I closed your other PR as this seem to be the same thing, please add 1.6.1 version to the pervious version list in script.json

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
…release

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
@steverobertsuk
Copy link
Copy Markdown
Contributor Author

@steverobertsuk I closed your other PR as this seem to be the same thing, please add 1.6.1 version to the pervious version list in script.json

Corrections have been made to script.json.

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
@steverobertsuk steverobertsuk force-pushed the sr/fix-negative-health-values branch from b841cd1 to af758cc Compare April 28, 2026 18:25
@steverobertsuk
Copy link
Copy Markdown
Contributor Author

Corrected previousversions array in script.json

@Alicekb Alicekb merged commit 7f6d805 into Roll20:master Apr 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants