feat: Implement Daggerheart Token Spotlight module, adding a HUD button to toggle combatant spotlight with associated logic and styling.
This commit is contained in:
commit
a4f74efa60
4 changed files with 114 additions and 0 deletions
51
scripts/main.js
Normal file
51
scripts/main.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
Hooks.on('renderTokenHUD', (app, html, data) => {
|
||||
const token = app.object;
|
||||
if (!token?.combatant) return;
|
||||
|
||||
const viewedCombat = ui.combat?.viewed;
|
||||
if (!viewedCombat) return;
|
||||
|
||||
// In Daggerheart, the combatant with the spotlight is the one whose turn it currently is.
|
||||
const hasSpotlight = viewedCombat.combatant?.id === token.combatant.id;
|
||||
|
||||
// Determine icon and classes based on spotlight state
|
||||
const iconClass = hasSpotlight
|
||||
? "fa-solid fa-hand-sparkles dh-spotlight-glow"
|
||||
: "fa-regular fa-hand-sparkles";
|
||||
|
||||
const buttonHtml = `
|
||||
<div class="control-icon ${hasSpotlight ? 'active' : ''}" data-action="toggle-spotlight" title="Toggle Spotlight">
|
||||
<i class="${iconClass}"></i>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Append to the right column of the Token HUD
|
||||
const colRight = html.find('.col.right');
|
||||
colRight.append(buttonHtml);
|
||||
|
||||
// Add click listener
|
||||
html.find('[data-action="toggle-spotlight"]').click(async event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (ui.combat && typeof ui.combat.setCombatantSpotlight === "function") {
|
||||
const btn = $(event.currentTarget);
|
||||
const icon = btn.find('i');
|
||||
const wasActive = btn.hasClass('active');
|
||||
|
||||
// Optimistic UI update
|
||||
if (wasActive) {
|
||||
btn.removeClass('active');
|
||||
icon.removeClass('fa-solid dh-spotlight-glow').addClass('fa-regular');
|
||||
} else {
|
||||
btn.addClass('active');
|
||||
icon.removeClass('fa-regular').addClass('fa-solid dh-spotlight-glow');
|
||||
}
|
||||
|
||||
// Call the system's spotlight toggle function
|
||||
await ui.combat.setCombatantSpotlight(token.combatant.id);
|
||||
} else {
|
||||
ui.notifications.warn("System does not support spotlight or combat is not initialized.");
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue