44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
/**
|
|
* token-hooks.js
|
|
* Registers Foundry canvas token hooks for the NPC Quick Card Deck.
|
|
*
|
|
* controlToken → when the GM selects an NPC token, bring that card to front.
|
|
* hoverToken → after 1.5 s of hovering over an NPC token, show the accent tooltip.
|
|
*/
|
|
|
|
export function registerTokenHooks(deck) {
|
|
|
|
// ── controlToken ────────────────────────────────────────────────────────────
|
|
// Fires whenever any token is selected or deselected.
|
|
Hooks.on("controlToken", (token, controlled) => {
|
|
if (!controlled) return; // only react to selection, not deselection
|
|
if (!game.user.isGM) return; // GM only
|
|
if (!token.actor) return; // token may not be linked to an actor
|
|
// Skip player-owned actors (PCs). Using hasPlayerOwner instead of checking
|
|
// actor.type means this works in SLA Mothership and other single-type systems.
|
|
if (token.actor.hasPlayerOwner) return;
|
|
|
|
deck.bringCardToFront(token.actor.id);
|
|
});
|
|
|
|
// ── hoverToken ──────────────────────────────────────────────────────────────
|
|
// Fires on mouse-enter and mouse-leave over a token.
|
|
let hoverTimer = null;
|
|
|
|
Hooks.on("hoverToken", (token, hovered) => {
|
|
if (!game.user.isGM) return;
|
|
if (!token.actor || token.actor.hasPlayerOwner) return;
|
|
|
|
if (hovered) {
|
|
// Delay before showing tooltip so it doesn't flash on quick mouse passes
|
|
hoverTimer = setTimeout(() => {
|
|
deck.showTooltip(token.actor.id, token);
|
|
}, 1500);
|
|
} else {
|
|
clearTimeout(hoverTimer);
|
|
hoverTimer = null;
|
|
deck.hideTooltip();
|
|
}
|
|
});
|
|
}
|