mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Swap item macro tooltip with system item tooltips (#2092)
This commit is contained in:
parent
d76b4bb707
commit
c181a47cc2
1 changed files with 202 additions and 167 deletions
|
|
@ -4,15 +4,55 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
#wide = false;
|
||||
#bordered = false;
|
||||
|
||||
/** @inheritdoc */
|
||||
async activate(element, options = {}) {
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
this.#wide = false;
|
||||
this.#bordered = false;
|
||||
|
||||
const isMacro = document.getElementById('action-bar').contains(element);
|
||||
const macro = isMacro ? game.macros.get(game.user.hotbar[Number(element.dataset.slot)] ?? null) : null;
|
||||
const macroItemUuid = macro?.type === 'script' ? macro.command.match(/await game\.system\.api\.applications\.ui\.DhHotbar\.useItem\("([^"]+)"\);/)?.[1] : null;
|
||||
if (macroItemUuid && await fromUuid(macroItemUuid, { strict: false })) {
|
||||
element.dataset.tooltip = `#item#${macroItemUuid}`;
|
||||
options.direction = this.constructor.TOOLTIP_DIRECTIONS.UP;
|
||||
}
|
||||
|
||||
let html = options.html;
|
||||
if (element.dataset.tooltip?.startsWith('#battlepoints#')) {
|
||||
const key = element.dataset.tooltip?.match(/^#([\w-]+)#/)?.[1];
|
||||
switch (key) {
|
||||
case 'battlepoints':
|
||||
return this.#activateBattlepoints(element, options);
|
||||
case 'effect-display':
|
||||
html = await this.#activateEffectDisplay(element, options);
|
||||
break;
|
||||
case 'item':
|
||||
html = await this.#activateItem(element, options);
|
||||
break;
|
||||
case 'attack':
|
||||
html = await this.#activateAttack(element, options);
|
||||
break;
|
||||
case 'shortRest':
|
||||
case 'longRest':
|
||||
html = await this.#activateRest(element, options);
|
||||
break;
|
||||
case 'advantage':
|
||||
case 'disadvantage':
|
||||
html = await this.#activateAdvantageDisadvantage(element, options);
|
||||
break;
|
||||
case 'deathMove':
|
||||
html = await this.#activateDeathMove(element, options);
|
||||
break;
|
||||
}
|
||||
|
||||
this.noOffset = options.noOffset;
|
||||
super.activate(element, { ...options, html });
|
||||
}
|
||||
|
||||
async #activateBattlepoints(element, options) {
|
||||
this.#wide = true;
|
||||
this.#bordered = true;
|
||||
|
||||
html = await this.getBattlepointHTML(element.dataset.combatId);
|
||||
const html = await this.getBattlepointHTML(element.dataset.combatId);
|
||||
options.direction = this._determineItemTooltipDirection(element);
|
||||
super.activate(element, { ...options, html: html });
|
||||
|
||||
|
|
@ -20,13 +60,9 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
lockedTooltip.querySelectorAll('.battlepoint-toggle-container input').forEach(element => {
|
||||
element.addEventListener('input', this.toggleModifier.bind(this));
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
this.#wide = false;
|
||||
this.#bordered = false;
|
||||
}
|
||||
|
||||
if (element.dataset.tooltip === '#effect-display#') {
|
||||
async #activateEffectDisplay(element, options) {
|
||||
this.#bordered = true;
|
||||
let effect = {};
|
||||
if (element.dataset.uuid) {
|
||||
|
|
@ -75,7 +111,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
};
|
||||
}
|
||||
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/effect-display.hbs`,
|
||||
{
|
||||
effect
|
||||
|
|
@ -84,11 +120,11 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
|
||||
this.tooltip.innerHTML = html;
|
||||
options.direction = this._determineItemTooltipDirection(element);
|
||||
} else {
|
||||
this.#bordered = false;
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
if (element.dataset.tooltip?.startsWith('#item#')) {
|
||||
async #activateItem(element, options) {
|
||||
const itemUuid = element.dataset.tooltip.slice(6);
|
||||
const item = await foundry.utils.fromUuid(itemUuid);
|
||||
if (item) {
|
||||
|
|
@ -97,7 +133,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
await this.enrichText(item);
|
||||
|
||||
const type = isAction ? 'action' : isEffect ? 'effect' : item.type;
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/${type}.hbs`,
|
||||
{
|
||||
item: item,
|
||||
|
|
@ -108,17 +144,20 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
options.direction = this._determineItemTooltipDirection(element);
|
||||
options.direction ??= this._determineItemTooltipDirection(element);
|
||||
return html;
|
||||
}
|
||||
} else {
|
||||
const attack = element.dataset.tooltip?.startsWith('#attack#');
|
||||
if (attack) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async #activateAttack(element, options) {
|
||||
const actorUuid = element.dataset.tooltip.slice(8);
|
||||
const actor = await foundry.utils.fromUuid(actorUuid);
|
||||
const attack = actor.system.attack;
|
||||
|
||||
const description = await TextEditor.enrichHTML(attack.description);
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
const description = await foundry.applications.ux.TextEditor.enrichHTML(attack.description);
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/attack.hbs`,
|
||||
{
|
||||
attack: attack,
|
||||
|
|
@ -129,19 +168,57 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
return html;
|
||||
}
|
||||
|
||||
const shortRest = element.dataset.tooltip?.startsWith('#shortRest#');
|
||||
const longRest = element.dataset.tooltip?.startsWith('#longRest#');
|
||||
if (shortRest || longRest) {
|
||||
const key = element.dataset.tooltip.slice(shortRest ? 11 : 10);
|
||||
async #activateAdvantageDisadvantage(element, options) {
|
||||
const isAdvantage = element.dataset.tooltip?.startsWith('#advantage#');
|
||||
const actorUuid = element.dataset.tooltip.slice(isAdvantage ? 11 : 14);
|
||||
const actor = await foundry.utils.fromUuid(actorUuid);
|
||||
|
||||
if (actor) {
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/advantage.hbs`,
|
||||
{
|
||||
sources: isAdvantage ? actor.system.advantageSources : actor.system.disadvantageSources
|
||||
}
|
||||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
return html;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async #activateDeathMove(element, options) {
|
||||
const name = element.dataset.deathName;
|
||||
const img = element.dataset.deathImg;
|
||||
const description = element.dataset.deathDescription;
|
||||
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/death-move.hbs`,
|
||||
{
|
||||
move: { name: name, img: img, description: description }
|
||||
}
|
||||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
options.direction = this._determineItemTooltipDirection(
|
||||
element,
|
||||
this.constructor.TOOLTIP_DIRECTIONS.RIGHT
|
||||
);
|
||||
return html;
|
||||
}
|
||||
|
||||
async #activateRest(element, options) {
|
||||
const isShortRest = element.dataset.tooltip?.startsWith('#shortRest#');
|
||||
const key = element.dataset.tooltip.slice(isShortRest ? 11 : 10);
|
||||
const moves = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).restMoves[
|
||||
element.dataset.restType
|
||||
].moves;
|
||||
const move = moves[key];
|
||||
const description = await TextEditor.enrichHTML(move.description);
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
const description = await foundry.applications.ux.TextEditor.enrichHTML(move.description);
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/downtime.hbs`,
|
||||
{
|
||||
move: move,
|
||||
|
|
@ -154,49 +231,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
|||
element,
|
||||
this.constructor.TOOLTIP_DIRECTIONS.RIGHT
|
||||
);
|
||||
}
|
||||
|
||||
const isAdvantage = element.dataset.tooltip?.startsWith('#advantage#');
|
||||
const isDisadvantage = element.dataset.tooltip?.startsWith('#disadvantage#');
|
||||
if (isAdvantage || isDisadvantage) {
|
||||
const actorUuid = element.dataset.tooltip.slice(isAdvantage ? 11 : 14);
|
||||
const actor = await foundry.utils.fromUuid(actorUuid);
|
||||
|
||||
if (actor) {
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/advantage.hbs`,
|
||||
{
|
||||
sources: isAdvantage ? actor.system.advantageSources : actor.system.disadvantageSources
|
||||
}
|
||||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
const deathMove = element.dataset.tooltip?.startsWith('#deathMove#');
|
||||
if (deathMove) {
|
||||
const name = element.dataset.deathName;
|
||||
const img = element.dataset.deathImg;
|
||||
const description = element.dataset.deathDescription;
|
||||
|
||||
html = await foundry.applications.handlebars.renderTemplate(
|
||||
`systems/daggerheart/templates/ui/tooltip/death-move.hbs`,
|
||||
{
|
||||
move: { name: name, img: img, description: description }
|
||||
}
|
||||
);
|
||||
|
||||
this.tooltip.innerHTML = html;
|
||||
options.direction = this._determineItemTooltipDirection(
|
||||
element,
|
||||
this.constructor.TOOLTIP_DIRECTIONS.RIGHT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.noOffset = options.noOffset;
|
||||
super.activate(element, { ...options, html: html });
|
||||
return html;
|
||||
}
|
||||
|
||||
_setAnchor(direction) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue