mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-14 04:31:07 +01:00
Merged with development
This commit is contained in:
commit
6d3e5302eb
62 changed files with 1776 additions and 660 deletions
|
|
@ -1,29 +1,8 @@
|
|||
import { parseInlineParams } from './parser.mjs';
|
||||
|
||||
export default function DhDamageEnricher(match, _options) {
|
||||
const parts = match[1].split('|').map(x => x.trim());
|
||||
|
||||
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];
|
||||
|
||||
const { value, type, inline } = parseInlineParams(match[1]);
|
||||
if (!value || !type) return 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,55 +1,25 @@
|
|||
import { parseInlineParams } from './parser.mjs';
|
||||
|
||||
export default function DhTemplateEnricher(match, _options) {
|
||||
const parts = match[1].split('|').map(x => x.trim());
|
||||
|
||||
let type = null,
|
||||
range = null,
|
||||
angle = CONFIG.MeasuredTemplate.defaults.angle,
|
||||
direction = 0,
|
||||
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]
|
||||
);
|
||||
range = matchedRange?.id;
|
||||
} else {
|
||||
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 params = parseInlineParams(match[1]);
|
||||
const { type, angle = CONFIG.MeasuredTemplate.defaults.angle, inline = false } = params;
|
||||
const direction = Number(params.direction) || 0;
|
||||
const range =
|
||||
params.range && Number.isNaN(params.range)
|
||||
? Object.values(CONFIG.DH.GENERAL.templateRanges).find(
|
||||
x => x.id.toLowerCase() === split[1] || x.short === split[1]
|
||||
)?.id
|
||||
: params.range;
|
||||
if (!(type in CONFIG.MeasuredTemplate.types) || !range) return match[0];
|
||||
|
||||
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 = '';
|
||||
if (angle != CONFIG.MeasuredTemplate.defaults.angle) {
|
||||
angleDisplay = 'angle:' + angle;
|
||||
|
||||
}
|
||||
let directionDisplay = '';
|
||||
if (direction != 0) {
|
||||
|
|
@ -95,8 +65,9 @@ export const renderMeasuredTemplate = async event => {
|
|||
|
||||
let baseDistance = range;
|
||||
if (Number.isNaN(Number(range))) {
|
||||
baseDistance =
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement[range];
|
||||
baseDistance = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement[
|
||||
range
|
||||
];
|
||||
}
|
||||
const distance = type === CONFIG.DH.GENERAL.templateTypes.EMANATION ? baseDistance + 2.5 : baseDistance;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { default as DhDamageEnricher, renderDamageButton } from './DamageEnriche
|
|||
import { default as DhDualityRollEnricher, renderDualityButton } from './DualityRollEnricher.mjs';
|
||||
import { default as DhEffectEnricher } from './EffectEnricher.mjs';
|
||||
import { default as DhTemplateEnricher, renderMeasuredTemplate } from './TemplateEnricher.mjs';
|
||||
import { default as DhLookupEnricher } from './LookupEnricher.mjs';
|
||||
|
||||
export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEnricher };
|
||||
|
||||
|
|
@ -21,6 +22,10 @@ export const enricherConfig = [
|
|||
{
|
||||
pattern: /@Template\[(.*)\]({.*})?/g,
|
||||
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