Compare commits

..

No commits in common. "4b651836ffb2ee6436258b6e12e33bf26b831de3" and "d76b4bb707fbfad3412c3a14882eeb7f4c4bcf64" have entirely different histories.

2 changed files with 189 additions and 232 deletions

View file

@ -275,18 +275,10 @@ export class DHActionDiceData extends foundry.abstract.DataModel {
}; };
} }
/**
* @returns {string} the formula associated with this damage field
*/
getFormula() { getFormula() {
if (this.custom.enabled) return this.custom.formula; const multiplier = this.multiplier === 'flat' ? this.flatMultiplier : `@${this.multiplier}`,
bonus = this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : '';
const multiplier = this.multiplier === 'flat' ? this.flatMultiplier : `@${this.multiplier}`; return this.custom.enabled ? this.custom.formula : `${multiplier ?? 1}${this.dice}${bonus}`;
if (!multiplier) return String(this.bonus || 0);
const dice = `${multiplier ?? 1}${this.dice}`;
const sign = this.bonus < 0 ? ' - ' : ' + ';
return this.bonus ? `${dice} ${sign} ${Math.abs(this.bonus)}` : dice;
} }
} }

View file

@ -4,55 +4,15 @@ 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 = {}) {
this.#wide = false; const { TextEditor } = foundry.applications.ux;
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; let html = options.html;
const key = element.dataset.tooltip?.match(/^#([\w-]+)#/)?.[1]; if (element.dataset.tooltip?.startsWith('#battlepoints#')) {
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.#wide = true;
this.#bordered = true; this.#bordered = true;
const html = await this.getBattlepointHTML(element.dataset.combatId); html = await this.getBattlepointHTML(element.dataset.combatId);
options.direction = this._determineItemTooltipDirection(element); options.direction = this._determineItemTooltipDirection(element);
super.activate(element, { ...options, html: html }); super.activate(element, { ...options, html: html });
@ -60,9 +20,13 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
lockedTooltip.querySelectorAll('.battlepoint-toggle-container input').forEach(element => { lockedTooltip.querySelectorAll('.battlepoint-toggle-container input').forEach(element => {
element.addEventListener('input', this.toggleModifier.bind(this)); element.addEventListener('input', this.toggleModifier.bind(this));
}); });
return;
} else {
this.#wide = false;
this.#bordered = false;
} }
async #activateEffectDisplay(element, options) { if (element.dataset.tooltip === '#effect-display#') {
this.#bordered = true; this.#bordered = true;
let effect = {}; let effect = {};
if (element.dataset.uuid) { if (element.dataset.uuid) {
@ -111,7 +75,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
}; };
} }
const html = await foundry.applications.handlebars.renderTemplate( html = await foundry.applications.handlebars.renderTemplate(
`systems/daggerheart/templates/ui/tooltip/effect-display.hbs`, `systems/daggerheart/templates/ui/tooltip/effect-display.hbs`,
{ {
effect effect
@ -120,11 +84,11 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
this.tooltip.innerHTML = html; this.tooltip.innerHTML = html;
options.direction = this._determineItemTooltipDirection(element); options.direction = this._determineItemTooltipDirection(element);
} else {
return html; this.#bordered = false;
} }
async #activateItem(element, options) { if (element.dataset.tooltip?.startsWith('#item#')) {
const itemUuid = element.dataset.tooltip.slice(6); const itemUuid = element.dataset.tooltip.slice(6);
const item = await foundry.utils.fromUuid(itemUuid); const item = await foundry.utils.fromUuid(itemUuid);
if (item) { if (item) {
@ -133,7 +97,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
await this.enrichText(item); await this.enrichText(item);
const type = isAction ? 'action' : isEffect ? 'effect' : item.type; const type = isAction ? 'action' : isEffect ? 'effect' : item.type;
const html = await foundry.applications.handlebars.renderTemplate( html = await foundry.applications.handlebars.renderTemplate(
`systems/daggerheart/templates/ui/tooltip/${type}.hbs`, `systems/daggerheart/templates/ui/tooltip/${type}.hbs`,
{ {
item: item, item: item,
@ -144,20 +108,17 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
); );
this.tooltip.innerHTML = html; this.tooltip.innerHTML = html;
options.direction ??= this._determineItemTooltipDirection(element); options.direction = this._determineItemTooltipDirection(element);
return html;
} }
} else {
return null; const attack = element.dataset.tooltip?.startsWith('#attack#');
} if (attack) {
async #activateAttack(element, options) {
const actorUuid = element.dataset.tooltip.slice(8); const actorUuid = element.dataset.tooltip.slice(8);
const actor = await foundry.utils.fromUuid(actorUuid); const actor = await foundry.utils.fromUuid(actorUuid);
const attack = actor.system.attack; const attack = actor.system.attack;
const description = await foundry.applications.ux.TextEditor.enrichHTML(attack.description); const description = await TextEditor.enrichHTML(attack.description);
const html = await foundry.applications.handlebars.renderTemplate( html = await foundry.applications.handlebars.renderTemplate(
`systems/daggerheart/templates/ui/tooltip/attack.hbs`, `systems/daggerheart/templates/ui/tooltip/attack.hbs`,
{ {
attack: attack, attack: attack,
@ -168,57 +129,19 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
); );
this.tooltip.innerHTML = html; this.tooltip.innerHTML = html;
return html;
} }
async #activateAdvantageDisadvantage(element, options) { const shortRest = element.dataset.tooltip?.startsWith('#shortRest#');
const isAdvantage = element.dataset.tooltip?.startsWith('#advantage#'); const longRest = element.dataset.tooltip?.startsWith('#longRest#');
const actorUuid = element.dataset.tooltip.slice(isAdvantage ? 11 : 14); if (shortRest || longRest) {
const actor = await foundry.utils.fromUuid(actorUuid); const key = element.dataset.tooltip.slice(shortRest ? 11 : 10);
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[ const moves = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).restMoves[
element.dataset.restType element.dataset.restType
].moves; ].moves;
const move = moves[key]; const move = moves[key];
const description = await foundry.applications.ux.TextEditor.enrichHTML(move.description); const description = await TextEditor.enrichHTML(move.description);
const html = await foundry.applications.handlebars.renderTemplate( html = await foundry.applications.handlebars.renderTemplate(
`systems/daggerheart/templates/ui/tooltip/downtime.hbs`, `systems/daggerheart/templates/ui/tooltip/downtime.hbs`,
{ {
move: move, move: move,
@ -231,7 +154,49 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
element, element,
this.constructor.TOOLTIP_DIRECTIONS.RIGHT this.constructor.TOOLTIP_DIRECTIONS.RIGHT
); );
return html; }
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 });
} }
_setAnchor(direction) { _setAnchor(direction) {