Skip to content

feat(HealthColors): upgrade to v2.0.0 and refactor for improved stability#2202

Open
steverobertsuk wants to merge 17 commits intoRoll20:masterfrom
steverobertsuk:sr/update-health-colors
Open

feat(HealthColors): upgrade to v2.0.0 and refactor for improved stability#2202
steverobertsuk wants to merge 17 commits intoRoll20:masterfrom
steverobertsuk:sr/update-health-colors

Conversation

@steverobertsuk
Copy link
Copy Markdown

@steverobertsuk steverobertsuk commented Apr 8, 2026

Major modernization and stability refactor of the entire script, consolidating performance improvements, critical bug fixes, and new user control features. This version represents a complete overhaul from the v1.6.x series.

Added

  • Respect Manual Overrides — the script now only updates visual properties (Aura 1) when a token's internal health bar actually changes. This allows for manual customization of colors, radii, and shapes via the token settings dialog without script interference during movement.
  • Persistent Default Auras — tokens at 100% health now default to a clean Green Aura 1 (at the configured AuraSize) to indicate stability.
  • JSDoc Documentation — every function is now fully documented with parameter types, return values, and behavioral descriptions to improve maintainability.
  • Centralized Configuration — all default state values, FX definitions, and internal parameters are now managed via unified constants.
  • FX Recovery Commands — added !aura reset-fx (rebuild default heal/hurt custom FX objects) and !aura reset-all (restore all settings to defaults + rebuild default FX + force update).
  • Public Settings Snapshot — setting-changing !aura commands now post a read-only settings panel to game chat for table visibility.
  • Aura Detail Commands — added !aura a1shape, !aura a1tint, !aura a2size, !aura a2shape, and !aura a2tint to adjust displayed Aura 1/Aura 2 detail values from chat.
  • Settings Output Command — added !aura settings to post the current settings snapshot to game chat on demand.

Changed

  • _ (Underscore) dependency — no longer required.
  • buttonColor function — legacy function completely removed after
    verifying no external or internal dependencies; superseded by nameBtn.
  • Tautological FX condition (UseBlood !== "OFF" || UseBlood !== "NO").
  • !aura on/off semantics — now explicitly sets global enabled state instead of toggling on on.
  • Schema version — bumped to 1.1.0 to reflect incremental state/data migration changes in the v2.0.0 line.

Fixed

  • Consistent casing for checkInstall and handleToken throughout.
  • Initialization of OneOff state key to prevent undefined collisions.
  • Corrected logic in playDeath to ensure jukebox tracks are properly stopped before restarting.
  • Page scale calculation and aura radius math standardized for better precision.
  • Heal and hurt FX color assignment now resolves startColour/startColor and endColour/endColor consistently, preventing gray/white fallback artifacts.
  • Default heal/hurt FX random color channels are explicitly neutralized during spawn preparation to preserve configured color fidelity.
  • Added a fallback spawn path that updates and triggers default custom FX by id (spawnFx) when definition-based spawning renders colors inconsistently.
  • Tuned default heal/hurt particle profile values for clearer saturation and reduced washed-out appearance in experimental sandboxes.
  • !aura bar now validates 1|2|3, whispers confirmation on change, and immediately runs a full sync to apply the new bar selection.
  • Tokens with no max value on the configured bar now have aura/tint cleared, preventing stale health indicators.
  • Configuration output now explicitly includes Aura 2 detail rows in both the GM menu and public settings snapshot.
  • Prevented duplicate settings output: setting-changing commands now publish a single game-chat snapshot instead of both GM and public panels.
  • Aura 2 output values are now sourced from state-backed defaults (Aura2Size, Aura2Shape, Aura2Color) instead of hardcoded labels.
  • Added Aura 1 Shape/Tint rows to settings output and backed them with default state values (Aura1Shape, Aura1Color).
  • Default heal/hurt custom FX definitions are now synchronized proactively on install/reset and when FX colors change, preventing delayed/stale visual updates after color edits or token lifecycle events.

Signed-off-by: Steve Roberts steve@shadowcomputers.co.uk

…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>
@steverobertsuk steverobertsuk marked this pull request as draft April 9, 2026 13:18
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>
@steverobertsuk steverobertsuk marked this pull request as ready for review April 9, 2026 17:46
…l20 profile links of authors

Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
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.

1 participant