mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Implement @Lookup enricher (#1196)
This commit is contained in:
parent
952779000d
commit
86eeba0648
6 changed files with 50 additions and 68 deletions
|
|
@ -501,6 +501,7 @@ export default class DhpActor extends Actor {
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
getRollData() {
|
getRollData() {
|
||||||
const rollData = super.getRollData();
|
const rollData = super.getRollData();
|
||||||
|
rollData.name = this.name;
|
||||||
rollData.system = this.system.getRollData();
|
rollData.system = this.system.getRollData();
|
||||||
rollData.prof = this.system.proficiency ?? 1;
|
rollData.prof = this.system.proficiency ?? 1;
|
||||||
rollData.cast = this.system.spellcastModifier ?? 1;
|
rollData.cast = this.system.spellcastModifier ?? 1;
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,8 @@
|
||||||
|
import { parseInlineParams } from './parser.mjs';
|
||||||
|
|
||||||
export default function DhDamageEnricher(match, _options) {
|
export default function DhDamageEnricher(match, _options) {
|
||||||
const parts = match[1].split('|').map(x => x.trim());
|
const { value, type, inline } = parseInlineParams(match[1]);
|
||||||
|
if (!value || !type) return match[0];
|
||||||
let value = null,
|
|
||||||
type = null,
|
|
||||||
inline = false;
|
|
||||||
|
|
||||||
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;
|
|
||||||
case 'inline':
|
|
||||||
inline = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!value || !value) return match[0];
|
|
||||||
|
|
||||||
return getDamageMessage(value, type, inline, match[0]);
|
return getDamageMessage(value, type, inline, match[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
8
module/enrichers/LookupEnricher.mjs
Normal file
8
module/enrichers/LookupEnricher.mjs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { parseInlineParams } from './parser.mjs';
|
||||||
|
|
||||||
|
export default function DhLookupEnricher(match, { rollData }) {
|
||||||
|
const results = parseInlineParams(match[1], { first: 'formula'});
|
||||||
|
const element = document.createElement('span');
|
||||||
|
element.textContent = Roll.replaceFormulaData(String(results.formula), rollData);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
@ -1,49 +1,18 @@
|
||||||
|
import { parseInlineParams } from './parser.mjs';
|
||||||
|
|
||||||
export default function DhTemplateEnricher(match, _options) {
|
export default function DhTemplateEnricher(match, _options) {
|
||||||
const parts = match[1].split('|').map(x => x.trim());
|
const params = parseInlineParams(match[1]);
|
||||||
|
const { type, angle = CONFIG.MeasuredTemplate.defaults.angle, inline = false } = params;
|
||||||
let type = null,
|
const direction = Number(params.direction) || 0;
|
||||||
range = null,
|
const range =
|
||||||
angle = CONFIG.MeasuredTemplate.defaults.angle,
|
params.range && Number.isNaN(params.range)
|
||||||
direction = 0,
|
? Object.values(CONFIG.DH.GENERAL.templateRanges).find(
|
||||||
inline = false;
|
|
||||||
|
|
||||||
parts.forEach(part => {
|
|
||||||
const split = part.split(':').map(x => x.toLowerCase().trim());
|
|
||||||
if (split.length === 2) {
|
|
||||||
switch (split[0]) {
|
|
||||||
case 'type':
|
|
||||||
const matchedType = Object.values(CONFIG.DH.GENERAL.templateTypes).find(
|
|
||||||
x => x.toLowerCase() === split[1]
|
|
||||||
);
|
|
||||||
type = matchedType;
|
|
||||||
break;
|
|
||||||
case 'range':
|
|
||||||
if (Number.isNaN(Number(split[1]))) {
|
|
||||||
const matchedRange = Object.values(CONFIG.DH.GENERAL.templateRanges).find(
|
|
||||||
x => x.id.toLowerCase() === split[1] || x.short === split[1]
|
x => x.id.toLowerCase() === split[1] || x.short === split[1]
|
||||||
);
|
)?.id
|
||||||
range = matchedRange?.id;
|
: params.range;
|
||||||
} else {
|
if (!(type in CONFIG.MeasuredTemplate.types) || !range) return match[0];
|
||||||
range = split[1];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'inline':
|
|
||||||
inline = true;
|
|
||||||
break;
|
|
||||||
case 'angle':
|
|
||||||
angle = split[1];
|
|
||||||
break;
|
|
||||||
case 'direction':
|
|
||||||
direction = split[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!type || !range) return match[0];
|
|
||||||
|
|
||||||
const label = game.i18n.localize(`DAGGERHEART.CONFIG.TemplateTypes.${type}`);
|
const label = game.i18n.localize(`DAGGERHEART.CONFIG.TemplateTypes.${type}`);
|
||||||
|
|
||||||
const rangeDisplay = Number.isNaN(Number(range)) ? game.i18n.localize(`DAGGERHEART.CONFIG.Range.${range}.name`) : range;
|
const rangeDisplay = Number.isNaN(Number(range)) ? game.i18n.localize(`DAGGERHEART.CONFIG.Range.${range}.name`) : range;
|
||||||
|
|
||||||
let angleDisplay = '';
|
let angleDisplay = '';
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { default as DhDamageEnricher, renderDamageButton } from './DamageEnriche
|
||||||
import { default as DhDualityRollEnricher, renderDualityButton } from './DualityRollEnricher.mjs';
|
import { default as DhDualityRollEnricher, renderDualityButton } from './DualityRollEnricher.mjs';
|
||||||
import { default as DhEffectEnricher } from './EffectEnricher.mjs';
|
import { default as DhEffectEnricher } from './EffectEnricher.mjs';
|
||||||
import { default as DhTemplateEnricher, renderMeasuredTemplate } from './TemplateEnricher.mjs';
|
import { default as DhTemplateEnricher, renderMeasuredTemplate } from './TemplateEnricher.mjs';
|
||||||
|
import { default as DhLookupEnricher } from './LookupEnricher.mjs';
|
||||||
|
|
||||||
export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEnricher };
|
export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEnricher };
|
||||||
|
|
||||||
|
|
@ -21,6 +22,10 @@ export const enricherConfig = [
|
||||||
{
|
{
|
||||||
pattern: /@Template\[(.*)\]({.*})?/g,
|
pattern: /@Template\[(.*)\]({.*})?/g,
|
||||||
enricher: DhTemplateEnricher
|
enricher: DhTemplateEnricher
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: /@Lookup\[(.*)\]({.*})?/g,
|
||||||
|
enricher: DhLookupEnricher
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
20
module/enrichers/parser.mjs
Normal file
20
module/enrichers/parser.mjs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* @param {string} paramString The parameter inside the brackets of something like @Template[] to parse
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {string} options.first If set, the first parameter is treated as a value with this as its key
|
||||||
|
* @returns {Record<string, string | undefined> | null}
|
||||||
|
*/
|
||||||
|
export function parseInlineParams(paramString, { first } = {}) {
|
||||||
|
const parts = paramString.split('|').map(x => x.trim());
|
||||||
|
const params = {};
|
||||||
|
for (const [idx, param] of parts.entries()) {
|
||||||
|
if (first && idx === 0) {
|
||||||
|
params[first] = param;
|
||||||
|
} else {
|
||||||
|
const parts = param.split(':');
|
||||||
|
params[parts[0]] = parts.length > 1 ? parts[1] : true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue