feat: add requst spotlight feature for players and update tooltips
This commit is contained in:
parent
b01167c6d8
commit
59527962ba
3 changed files with 66 additions and 16 deletions
|
|
@ -4,8 +4,8 @@
|
||||||
"description": "Adds a button to the token hover HUD to toggle the spotlight for Daggerheart.",
|
"description": "Adds a button to the token hover HUD to toggle the spotlight for Daggerheart.",
|
||||||
"url": "https://git.geeks.gay/cosmo/dh-token-spotlight",
|
"url": "https://git.geeks.gay/cosmo/dh-token-spotlight",
|
||||||
"manifest": "https://git.geeks.gay/cosmo/dh-token-spotlight/raw/branch/main/module.json",
|
"manifest": "https://git.geeks.gay/cosmo/dh-token-spotlight/raw/branch/main/module.json",
|
||||||
"download": "https://git.geeks.gay/cosmo/dh-token-spotlight/releases/download/1.0.2/dh-token-spotlight.zip",
|
"download": "https://git.geeks.gay/cosmo/dh-token-spotlight/releases/download/1.1.0/dh-token-spotlight.zip",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": "13",
|
"minimum": "13",
|
||||||
"verified": "13"
|
"verified": "13"
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,28 @@ Hooks.on('renderTokenHUD', (app, html, data) => {
|
||||||
|
|
||||||
// In Daggerheart, the combatant with the spotlight is the one whose turn it currently is.
|
// In Daggerheart, the combatant with the spotlight is the one whose turn it currently is.
|
||||||
const hasSpotlight = viewedCombat.combatant?.id === token.combatant.id;
|
const hasSpotlight = viewedCombat.combatant?.id === token.combatant.id;
|
||||||
|
const isRequesting = token.combatant.system?.spotlight?.requesting;
|
||||||
|
|
||||||
// Determine icon and classes based on spotlight state
|
// Determine icon and classes based on spotlight state
|
||||||
const iconClass = hasSpotlight
|
let iconClass = "fa-regular fa-hand-sparkles";
|
||||||
? "fa-solid fa-hand-sparkles dh-spotlight-glow"
|
let activeClass = "";
|
||||||
: "fa-regular fa-hand-sparkles";
|
if (hasSpotlight) {
|
||||||
|
iconClass = "fa-solid fa-hand-sparkles dh-spotlight-glow";
|
||||||
|
activeClass = "active";
|
||||||
|
} else if (isRequesting) {
|
||||||
|
iconClass = "fa-solid fa-hand-sparkles dh-spotlight-request";
|
||||||
|
activeClass = "active";
|
||||||
|
}
|
||||||
|
|
||||||
|
let tooltipText = "";
|
||||||
|
if (game.user.isGM) {
|
||||||
|
tooltipText = hasSpotlight ? "Take Spotlight" : "Grant Spotlight";
|
||||||
|
} else {
|
||||||
|
tooltipText = hasSpotlight ? "Remove Spotlight" : (isRequesting ? "Cancel Spotlight Request" : "Request Spotlight");
|
||||||
|
}
|
||||||
|
|
||||||
const buttonHtml = `
|
const buttonHtml = `
|
||||||
<div class="control-icon ${hasSpotlight ? 'active' : ''}" data-action="toggle-spotlight" title="Toggle Spotlight">
|
<div class="control-icon ${activeClass}" data-action="toggle-spotlight" title="${tooltipText}">
|
||||||
<i class="${iconClass}"></i>
|
<i class="${iconClass}"></i>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
@ -28,22 +42,52 @@ Hooks.on('renderTokenHUD', (app, html, data) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
if (ui.combat && typeof ui.combat.setCombatantSpotlight === "function") {
|
if (ui.combat) {
|
||||||
const btn = $(event.currentTarget);
|
const btn = $(event.currentTarget);
|
||||||
const icon = btn.find('i');
|
const icon = btn.find('i');
|
||||||
const wasActive = btn.hasClass('active');
|
const wasActive = btn.hasClass('active');
|
||||||
|
const isRequestingMsg = icon.hasClass('dh-spotlight-request');
|
||||||
|
|
||||||
// Optimistic UI update
|
if (game.user.isGM) {
|
||||||
if (wasActive) {
|
if (typeof ui.combat.setCombatantSpotlight === "function") {
|
||||||
btn.removeClass('active');
|
// Optimistic UI update for GM
|
||||||
icon.removeClass('fa-solid dh-spotlight-glow').addClass('fa-regular');
|
if (wasActive && !isRequestingMsg) {
|
||||||
|
btn.removeClass('active');
|
||||||
|
icon.removeClass('fa-solid dh-spotlight-glow').addClass('fa-regular');
|
||||||
|
} else {
|
||||||
|
btn.addClass('active');
|
||||||
|
icon.removeClass('fa-regular dh-spotlight-request').addClass('fa-solid dh-spotlight-glow');
|
||||||
|
}
|
||||||
|
await ui.combat.setCombatantSpotlight(token.combatant.id);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
btn.addClass('active');
|
// Players request the spotlight
|
||||||
icon.removeClass('fa-regular').addClass('fa-solid dh-spotlight-glow');
|
const combat = ui.combat.viewed;
|
||||||
|
if (!combat) return;
|
||||||
|
|
||||||
|
const characters = combat.turns?.filter(x => !x.isNPC) ?? [];
|
||||||
|
// Fallback to maxRequestIndex = 0 if necessary
|
||||||
|
const orderValues = characters.map(c => c.system?.spotlight?.requestOrderIndex || 0);
|
||||||
|
const maxRequestIndex = orderValues.length > 0 ? Math.max(...orderValues) : 0;
|
||||||
|
|
||||||
|
const currentlyRequesting = !!token.combatant.system?.spotlight?.requesting;
|
||||||
|
|
||||||
|
// Optimistic UI update for Player
|
||||||
|
if (currentlyRequesting) {
|
||||||
|
btn.removeClass('active');
|
||||||
|
icon.removeClass('fa-solid dh-spotlight-request').addClass('fa-regular');
|
||||||
|
} else {
|
||||||
|
btn.addClass('active');
|
||||||
|
icon.removeClass('fa-regular').addClass('fa-solid dh-spotlight-request');
|
||||||
|
}
|
||||||
|
|
||||||
|
await token.combatant.update({
|
||||||
|
'system.spotlight': {
|
||||||
|
requesting: !currentlyRequesting,
|
||||||
|
requestOrderIndex: !currentlyRequesting ? maxRequestIndex + 1 : 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the system's spotlight toggle function
|
|
||||||
await ui.combat.setCombatantSpotlight(token.combatant.id);
|
|
||||||
} else {
|
} else {
|
||||||
ui.notifications.warn("System does not support spotlight or combat is not initialized.");
|
ui.notifications.warn("System does not support spotlight or combat is not initialized.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,9 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Player spotlight request effect */
|
||||||
|
#token-hud .control-icon.active i.dh-spotlight-request {
|
||||||
|
color: #4da6ff;
|
||||||
|
text-shadow: 0 0 5px #007bff, 0 0 10px #007bff;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue