Larkinabout / fvtt-token-action-hud-pf2e

Token Action HUD is a repositionable HUD of actions for a selected token.
10 stars 15 forks source link

[FEATURE] Call hook when hovering over and action #107

Closed Aedif closed 7 months ago

Aedif commented 7 months ago

Any chance the following DnD5e feature could be implemented for PF2e as well?

https://github.com/Larkinabout/fvtt-token-action-hud-dnd5e/issues/70

This would allow for integration with the Tactical Grid module's range highlight feature:

https://discord.com/channels/170995199584108546/648215359895240715/1191502424951750777

Silvertower commented 7 months ago

I am working to implement this as a pull request, though I do not understand enough about Tactical Grid to know how to test the functionality. It is easy enough to merge and adjust the code from the DnD5e module and see that the events are firing. @Aedif Can you describe a scenario where this could be used from Token Action HUD and how I might test it? Also, which UI elements would be useful for firing the hover events; 'action', 'feat', 'item', and 'spell' seem obvious choices. Perhaps 'elementalBlast', 'familiarAttack' and 'strike' as well? Thank you.

Aedif commented 7 months ago

What Tactical Grid does is highlight the range of an item if it has one.

All I need from these hover events is the instance or reference to an Item on mouseover, and for mouseleave it would suffice that it just fires.

Tactical Grid would be calling the following method on mouseover:

TacticalGrid.rangeHighlight(token, { item });

and this on mouseleave:

TacticalGrid.clearRangeHighlight(token);

With the hooks provided by the DnD5e version the module currently does this:


  // Get the token the Action HUD has been opened for
  let token;
  Hooks.on('renderTokenActionHud', (hud, html, opts) => {
    if (!itemRangeHighlightEnabled()) {
      token = null;
      return;
    }
    token = hud.token;
  });

  // Highlight Item range if it has one
  Hooks.on('tokenActionHudSystemActionHoverOn', (event, item) => {
    if (token) TacticalGrid.rangeHighlight(token, { item });
  });

  // Clear range highlight
  Hooks.on('tokenActionHudSystemActionHoverOff', (event, item) => {
    if (token) TacticalGrid.clearRangeHighlight(token);
  });

I'd be nice to have these hooks fire for any item that could conceivably have a range. Tactical Grid's support is not completel for PF2e yet, but I will be improving it, so it'd be nice if some future proofing was in place and you registered these hooks for items with ranges even if TG is not currently showing them.

Larkinabout commented 7 months ago

Added in 1.5.5.