mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +01:00
Added DamageEnricher
This commit is contained in:
parent
615df65415
commit
6772a8fbd8
3 changed files with 117 additions and 15 deletions
|
|
@ -3,7 +3,7 @@ import * as applications from './module/applications/_module.mjs';
|
||||||
import * as models from './module/data/_module.mjs';
|
import * as models from './module/data/_module.mjs';
|
||||||
import * as documents from './module/documents/_module.mjs';
|
import * as documents from './module/documents/_module.mjs';
|
||||||
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
||||||
import { DhDualityRollEnricher, DhTemplateEnricher } from './module/enrichers/_module.mjs';
|
import { enricherConfig } from './module/enrichers/_module.mjs';
|
||||||
import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs';
|
import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs';
|
||||||
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
||||||
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
||||||
|
|
@ -20,6 +20,7 @@ import { placeables } from './module/canvas/_module.mjs';
|
||||||
import { registerRollDiceHooks } from './module/dice/dhRoll.mjs';
|
import { registerRollDiceHooks } from './module/dice/dhRoll.mjs';
|
||||||
import { registerDHActorHooks } from './module/documents/actor.mjs';
|
import { registerDHActorHooks } from './module/documents/actor.mjs';
|
||||||
import './node_modules/@yaireo/tagify/dist/tagify.css';
|
import './node_modules/@yaireo/tagify/dist/tagify.css';
|
||||||
|
import { renderDamageButton } from './module/enrichers/DamageEnricher.mjs';
|
||||||
|
|
||||||
Hooks.once('init', () => {
|
Hooks.once('init', () => {
|
||||||
CONFIG.DH = SYSTEM;
|
CONFIG.DH = SYSTEM;
|
||||||
|
|
@ -29,18 +30,7 @@ Hooks.once('init', () => {
|
||||||
documents
|
documents
|
||||||
};
|
};
|
||||||
|
|
||||||
CONFIG.TextEditor.enrichers.push(
|
CONFIG.TextEditor.enrichers.push(...enricherConfig);
|
||||||
...[
|
|
||||||
{
|
|
||||||
pattern: /\[\[\/dr\s?(.*?)\]\]/g,
|
|
||||||
enricher: DhDualityRollEnricher
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: /^@Template\[(.*)\]$/g,
|
|
||||||
enricher: DhTemplateEnricher
|
|
||||||
}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
CONFIG.statusEffects = [
|
CONFIG.statusEffects = [
|
||||||
...CONFIG.statusEffects.filter(x => !['dead', 'unconscious'].includes(x.id)),
|
...CONFIG.statusEffects.filter(x => !['dead', 'unconscious'].includes(x.id)),
|
||||||
|
|
@ -178,6 +168,10 @@ Hooks.on('ready', () => {
|
||||||
Hooks.once('dicesoniceready', () => {});
|
Hooks.once('dicesoniceready', () => {});
|
||||||
|
|
||||||
Hooks.on('renderChatMessageHTML', (_, element) => {
|
Hooks.on('renderChatMessageHTML', (_, element) => {
|
||||||
|
element
|
||||||
|
.querySelectorAll('.enriched-damage-button')
|
||||||
|
.forEach(element => element.addEventListener('click', renderDamageButton));
|
||||||
|
|
||||||
element
|
element
|
||||||
.querySelectorAll('.duality-roll-button')
|
.querySelectorAll('.duality-roll-button')
|
||||||
.forEach(element => element.addEventListener('click', renderDualityButton));
|
.forEach(element => element.addEventListener('click', renderDualityButton));
|
||||||
|
|
@ -188,6 +182,10 @@ Hooks.on('renderChatMessageHTML', (_, element) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on('renderJournalEntryPageProseMirrorSheet', (_, element) => {
|
Hooks.on('renderJournalEntryPageProseMirrorSheet', (_, element) => {
|
||||||
|
element
|
||||||
|
.querySelectorAll('.enriched-damage-button')
|
||||||
|
.forEach(element => element.addEventListener('click', renderDamageButton));
|
||||||
|
|
||||||
element
|
element
|
||||||
.querySelectorAll('.duality-roll-button')
|
.querySelectorAll('.duality-roll-button')
|
||||||
.forEach(element => element.addEventListener('click', renderDualityButton));
|
.forEach(element => element.addEventListener('click', renderDualityButton));
|
||||||
|
|
@ -198,6 +196,10 @@ Hooks.on('renderJournalEntryPageProseMirrorSheet', (_, element) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on('renderHandlebarsApplication', (_, element) => {
|
Hooks.on('renderHandlebarsApplication', (_, element) => {
|
||||||
|
element
|
||||||
|
.querySelectorAll('.enriched-damage-button')
|
||||||
|
.forEach(element => element.addEventListener('click', renderDamageButton));
|
||||||
|
|
||||||
element
|
element
|
||||||
.querySelectorAll('.duality-roll-button')
|
.querySelectorAll('.duality-roll-button')
|
||||||
.forEach(element => element.addEventListener('click', renderDualityButton));
|
.forEach(element => element.addEventListener('click', renderDualityButton));
|
||||||
|
|
|
||||||
82
module/enrichers/DamageEnricher.mjs
Normal file
82
module/enrichers/DamageEnricher.mjs
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
import { rollCommandToJSON } from '../helpers/utils.mjs';
|
||||||
|
|
||||||
|
export default function DhDamageEnricher(match, _options) {
|
||||||
|
const parts = match[1].split('|').map(x => x.trim());
|
||||||
|
|
||||||
|
let value = null,
|
||||||
|
type = null;
|
||||||
|
|
||||||
|
parts.forEach(part => {
|
||||||
|
const split = part.split(':').map(x => x.toLowerCase().trim());
|
||||||
|
if (split.length === 2) {
|
||||||
|
switch (split[0]) {
|
||||||
|
case 'value':
|
||||||
|
value = split[1];
|
||||||
|
break;
|
||||||
|
case 'type':
|
||||||
|
type = split[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!value || !value) return match[0];
|
||||||
|
|
||||||
|
return getDamageMessage(value, type, match[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDamageMessage(damage, type, defaultElement) {
|
||||||
|
const dualityElement = document.createElement('span');
|
||||||
|
const typeIcons = type
|
||||||
|
.replace('[', '')
|
||||||
|
.replace(']', '')
|
||||||
|
.split(',')
|
||||||
|
.map(x => x.trim())
|
||||||
|
.map(x => {
|
||||||
|
return CONFIG.DH.GENERAL.damageTypes[x]?.icon ?? null;
|
||||||
|
})
|
||||||
|
.filter(x => x);
|
||||||
|
|
||||||
|
if (!typeIcons.length) return defaultElement;
|
||||||
|
|
||||||
|
const iconNodes = typeIcons.map(x => `<i class="fa-solid ${x}"></i>`).join('');
|
||||||
|
|
||||||
|
dualityElement.innerHTML = `
|
||||||
|
<button class="enriched-damage-button"
|
||||||
|
data-value="${damage}"
|
||||||
|
data-type="${type}"
|
||||||
|
data-tooltip="${game.i18n.localize('DAGGERHEART.GENERAL.damage')}"
|
||||||
|
>
|
||||||
|
${damage}
|
||||||
|
${iconNodes}
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
|
||||||
|
return dualityElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const renderDamageButton = async event => {
|
||||||
|
const button = event.currentTarget,
|
||||||
|
value = button.dataset.value,
|
||||||
|
type = button.dataset.type
|
||||||
|
.replace('[', '')
|
||||||
|
.replace(']', '')
|
||||||
|
.split(',')
|
||||||
|
.map(x => x.trim());
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
event: event,
|
||||||
|
title: game.i18n.localize('Damage Roll'),
|
||||||
|
data: { bonuses: [] },
|
||||||
|
source: {},
|
||||||
|
roll: [
|
||||||
|
{
|
||||||
|
formula: value,
|
||||||
|
applyTo: CONFIG.DH.GENERAL.healingTypes.hitPoints.id,
|
||||||
|
type: type
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG.Dice.daggerheart.DamageRoll.build(config);
|
||||||
|
};
|
||||||
|
|
@ -1,2 +1,20 @@
|
||||||
export { default as DhDualityRollEnricher } from './DualityRollEnricher.mjs';
|
import { default as DhDamageEnricher } from './DamageEnricher.mjs';
|
||||||
export { default as DhTemplateEnricher } from './TemplateEnricher.mjs';
|
import { default as DhDualityRollEnricher } from './DualityRollEnricher.mjs';
|
||||||
|
import { default as DhTemplateEnricher } from './TemplateEnricher.mjs';
|
||||||
|
|
||||||
|
export { DhDamageEnricher, DhDualityRollEnricher, DhTemplateEnricher };
|
||||||
|
|
||||||
|
export const enricherConfig = [
|
||||||
|
{
|
||||||
|
pattern: /^@Damage\[(.*)\]$/g,
|
||||||
|
enricher: DhDamageEnricher
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: /\[\[\/dr\s?(.*?)\]\]/g,
|
||||||
|
enricher: DhDualityRollEnricher
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: /^@Template\[(.*)\]$/g,
|
||||||
|
enricher: DhTemplateEnricher
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue