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,199 +4,234 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
|
||||||
#wide = false;
|
#wide = false;
|
||||||
#bordered = false;
|
#bordered = false;
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
async activate(element, options = {}) {
|
async activate(element, options = {}) {
|
||||||
const { TextEditor } = foundry.applications.ux;
|
this.#wide = false;
|
||||||
|
this.#bordered = false;
|
||||||
|
|
||||||
let html = options.html;
|
const isMacro = document.getElementById('action-bar').contains(element);
|
||||||
if (element.dataset.tooltip?.startsWith('#battlepoints#')) {
|
const macro = isMacro ? game.macros.get(game.user.hotbar[Number(element.dataset.slot)] ?? null) : null;
|
||||||
this.#wide = true;
|
const macroItemUuid = macro?.type === 'script' ? macro.command.match(/await game\.system\.api\.applications\.ui\.DhHotbar\.useItem\("([^"]+)"\);/)?.[1] : null;
|
||||||
this.#bordered = true;
|
if (macroItemUuid && await fromUuid(macroItemUuid, { strict: false })) {
|
||||||
|
element.dataset.tooltip = `#item#${macroItemUuid}`;
|
||||||
html = await this.getBattlepointHTML(element.dataset.combatId);
|
options.direction = this.constructor.TOOLTIP_DIRECTIONS.UP;
|
||||||
options.direction = this._determineItemTooltipDirection(element);
|
|
||||||
super.activate(element, { ...options, html: html });
|
|
||||||
|
|
||||||
const lockedTooltip = this.lockTooltip();
|
|
||||||
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#') {
|
let html = options.html;
|
||||||
this.#bordered = true;
|
const key = element.dataset.tooltip?.match(/^#([\w-]+)#/)?.[1];
|
||||||
let effect = {};
|
switch (key) {
|
||||||
if (element.dataset.uuid) {
|
case 'battlepoints':
|
||||||
const effectItem = await foundry.utils.fromUuid(element.dataset.uuid);
|
return this.#activateBattlepoints(element, options);
|
||||||
const effectData = effectItem.toObject();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
effect = {
|
this.noOffset = options.noOffset;
|
||||||
...effectData,
|
super.activate(element, { ...options, html });
|
||||||
name: game.i18n.localize(effectData.name)
|
}
|
||||||
|
|
||||||
|
async #activateBattlepoints(element, options) {
|
||||||
|
this.#wide = true;
|
||||||
|
this.#bordered = true;
|
||||||
|
|
||||||
|
const html = await this.getBattlepointHTML(element.dataset.combatId);
|
||||||
|
options.direction = this._determineItemTooltipDirection(element);
|
||||||
|
super.activate(element, { ...options, html: html });
|
||||||
|
|
||||||
|
const lockedTooltip = this.lockTooltip();
|
||||||
|
lockedTooltip.querySelectorAll('.battlepoint-toggle-container input').forEach(element => {
|
||||||
|
element.addEventListener('input', this.toggleModifier.bind(this));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async #activateEffectDisplay(element, options) {
|
||||||
|
this.#bordered = true;
|
||||||
|
let effect = {};
|
||||||
|
if (element.dataset.uuid) {
|
||||||
|
const effectItem = await foundry.utils.fromUuid(element.dataset.uuid);
|
||||||
|
const effectData = effectItem.toObject();
|
||||||
|
|
||||||
|
effect = {
|
||||||
|
...effectData,
|
||||||
|
name: game.i18n.localize(effectData.name)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (effectData.type === 'beastform') {
|
||||||
|
const beastformData = {
|
||||||
|
features: [],
|
||||||
|
advantageOn: effectData.system.advantageOn,
|
||||||
|
beastformAttackData: game.system.api.data.items.DHBeastform.getBeastformAttackData(effectItem)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (effectData.type === 'beastform') {
|
const features = effectItem.parent.items.filter(x => effectItem.system.featureIds.includes(x.id));
|
||||||
const beastformData = {
|
for (const feature of features) {
|
||||||
features: [],
|
const featureData = feature.toObject();
|
||||||
advantageOn: effectData.system.advantageOn,
|
featureData.enrichedDescription = await feature.system.getEnrichedDescription();
|
||||||
beastformAttackData: game.system.api.data.items.DHBeastform.getBeastformAttackData(effectItem)
|
beastformData.features.push(featureData);
|
||||||
};
|
|
||||||
|
|
||||||
const features = effectItem.parent.items.filter(x => effectItem.system.featureIds.includes(x.id));
|
|
||||||
for (const feature of features) {
|
|
||||||
const featureData = feature.toObject();
|
|
||||||
featureData.enrichedDescription = await feature.system.getEnrichedDescription();
|
|
||||||
beastformData.features.push(featureData);
|
|
||||||
}
|
|
||||||
|
|
||||||
effect.description = await foundry.applications.handlebars.renderTemplate(
|
|
||||||
'systems/daggerheart/templates/ui/tooltip/parts/beastformData.hbs',
|
|
||||||
{
|
|
||||||
item: { system: beastformData }
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
effect.description = game.i18n.localize(
|
|
||||||
effectData.description ?? effectData.parent.system.description
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const conditions = CONFIG.DH.GENERAL.conditions();
|
|
||||||
const condition = conditions[element.dataset.condition];
|
|
||||||
effect = {
|
|
||||||
...condition,
|
|
||||||
name: game.i18n.localize(condition.name),
|
|
||||||
description: game.i18n.localize(condition.description),
|
|
||||||
appliedBy: element.dataset.appliedBy,
|
|
||||||
isLockedCondition: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
html = await foundry.applications.handlebars.renderTemplate(
|
effect.description = await foundry.applications.handlebars.renderTemplate(
|
||||||
`systems/daggerheart/templates/ui/tooltip/effect-display.hbs`,
|
'systems/daggerheart/templates/ui/tooltip/parts/beastformData.hbs',
|
||||||
|
{
|
||||||
|
item: { system: beastformData }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
effect.description = game.i18n.localize(
|
||||||
|
effectData.description ?? effectData.parent.system.description
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const conditions = CONFIG.DH.GENERAL.conditions();
|
||||||
|
const condition = conditions[element.dataset.condition];
|
||||||
|
effect = {
|
||||||
|
...condition,
|
||||||
|
name: game.i18n.localize(condition.name),
|
||||||
|
description: game.i18n.localize(condition.description),
|
||||||
|
appliedBy: element.dataset.appliedBy,
|
||||||
|
isLockedCondition: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await foundry.applications.handlebars.renderTemplate(
|
||||||
|
`systems/daggerheart/templates/ui/tooltip/effect-display.hbs`,
|
||||||
|
{
|
||||||
|
effect
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.tooltip.innerHTML = html;
|
||||||
|
options.direction = this._determineItemTooltipDirection(element);
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
async #activateItem(element, options) {
|
||||||
|
const itemUuid = element.dataset.tooltip.slice(6);
|
||||||
|
const item = await foundry.utils.fromUuid(itemUuid);
|
||||||
|
if (item) {
|
||||||
|
const isAction = item instanceof game.system.api.models.actions.actionsTypes.base;
|
||||||
|
const isEffect = item instanceof ActiveEffect;
|
||||||
|
await this.enrichText(item);
|
||||||
|
|
||||||
|
const type = isAction ? 'action' : isEffect ? 'effect' : item.type;
|
||||||
|
const html = await foundry.applications.handlebars.renderTemplate(
|
||||||
|
`systems/daggerheart/templates/ui/tooltip/${type}.hbs`,
|
||||||
{
|
{
|
||||||
effect
|
item: item,
|
||||||
|
description: item.system?.enrichedDescription ?? item.enrichedDescription,
|
||||||
|
config: CONFIG.DH,
|
||||||
|
allDomains: CONFIG.DH.DOMAIN.allDomains()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.tooltip.innerHTML = html;
|
this.tooltip.innerHTML = html;
|
||||||
options.direction = this._determineItemTooltipDirection(element);
|
options.direction ??= this._determineItemTooltipDirection(element);
|
||||||
} else {
|
return html;
|
||||||
this.#bordered = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.dataset.tooltip?.startsWith('#item#')) {
|
return null;
|
||||||
const itemUuid = element.dataset.tooltip.slice(6);
|
}
|
||||||
const item = await foundry.utils.fromUuid(itemUuid);
|
|
||||||
if (item) {
|
|
||||||
const isAction = item instanceof game.system.api.models.actions.actionsTypes.base;
|
|
||||||
const isEffect = item instanceof ActiveEffect;
|
|
||||||
await this.enrichText(item);
|
|
||||||
|
|
||||||
const type = isAction ? 'action' : isEffect ? 'effect' : item.type;
|
async #activateAttack(element, options) {
|
||||||
html = await foundry.applications.handlebars.renderTemplate(
|
const actorUuid = element.dataset.tooltip.slice(8);
|
||||||
`systems/daggerheart/templates/ui/tooltip/${type}.hbs`,
|
const actor = await foundry.utils.fromUuid(actorUuid);
|
||||||
{
|
const attack = actor.system.attack;
|
||||||
item: item,
|
|
||||||
description: item.system?.enrichedDescription ?? item.enrichedDescription,
|
|
||||||
config: CONFIG.DH,
|
|
||||||
allDomains: CONFIG.DH.DOMAIN.allDomains()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.tooltip.innerHTML = html;
|
const description = await foundry.applications.ux.TextEditor.enrichHTML(attack.description);
|
||||||
options.direction = this._determineItemTooltipDirection(element);
|
const html = await foundry.applications.handlebars.renderTemplate(
|
||||||
|
`systems/daggerheart/templates/ui/tooltip/attack.hbs`,
|
||||||
|
{
|
||||||
|
attack: attack,
|
||||||
|
description: description,
|
||||||
|
parent: actor,
|
||||||
|
config: CONFIG.DH
|
||||||
}
|
}
|
||||||
} else {
|
);
|
||||||
const attack = element.dataset.tooltip?.startsWith('#attack#');
|
|
||||||
if (attack) {
|
|
||||||
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);
|
this.tooltip.innerHTML = html;
|
||||||
html = await foundry.applications.handlebars.renderTemplate(
|
return html;
|
||||||
`systems/daggerheart/templates/ui/tooltip/attack.hbs`,
|
}
|
||||||
{
|
|
||||||
attack: attack,
|
|
||||||
description: description,
|
|
||||||
parent: actor,
|
|
||||||
config: CONFIG.DH
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.tooltip.innerHTML = html;
|
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);
|
||||||
|
|
||||||
const shortRest = element.dataset.tooltip?.startsWith('#shortRest#');
|
if (actor) {
|
||||||
const longRest = element.dataset.tooltip?.startsWith('#longRest#');
|
const html = await foundry.applications.handlebars.renderTemplate(
|
||||||
if (shortRest || longRest) {
|
`systems/daggerheart/templates/ui/tooltip/advantage.hbs`,
|
||||||
const key = element.dataset.tooltip.slice(shortRest ? 11 : 10);
|
{
|
||||||
|
sources: isAdvantage ? actor.system.advantageSources : actor.system.disadvantageSources
|
||||||
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(
|
|
||||||
`systems/daggerheart/templates/ui/tooltip/downtime.hbs`,
|
|
||||||
{
|
|
||||||
move: move,
|
|
||||||
description: description
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.tooltip.innerHTML = html;
|
|
||||||
options.direction = this._determineItemTooltipDirection(
|
|
||||||
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#');
|
this.tooltip.innerHTML = html;
|
||||||
if (deathMove) {
|
return html;
|
||||||
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
this.noOffset = options.noOffset;
|
async #activateDeathMove(element, options) {
|
||||||
super.activate(element, { ...options, html: html });
|
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 foundry.applications.ux.TextEditor.enrichHTML(move.description);
|
||||||
|
const html = await foundry.applications.handlebars.renderTemplate(
|
||||||
|
`systems/daggerheart/templates/ui/tooltip/downtime.hbs`,
|
||||||
|
{
|
||||||
|
move: move,
|
||||||
|
description: description
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.tooltip.innerHTML = html;
|
||||||
|
options.direction = this._determineItemTooltipDirection(
|
||||||
|
element,
|
||||||
|
this.constructor.TOOLTIP_DIRECTIONS.RIGHT
|
||||||
|
);
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setAnchor(direction) {
|
_setAnchor(direction) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue