mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
146 - Measured Templates (#147)
* Added DhMeasuredTemplate * Added TemplateEnricher for Template buttons in text
This commit is contained in:
parent
7802d18a4d
commit
96ed90b5fc
9 changed files with 168 additions and 66 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { abilities } from '../config/actorConfig.mjs';
|
||||
import { rollCommandToJSON } from '../helpers/utils.mjs';
|
||||
import { getCommandTarget, rollCommandToJSON } from '../helpers/utils.mjs';
|
||||
|
||||
export function dualityRollEnricher(match, _options) {
|
||||
export default function DhDualityRollEnricher(match, _options) {
|
||||
const roll = rollCommandToJSON(match[1]);
|
||||
if (!roll) return match[0];
|
||||
|
||||
|
|
@ -39,3 +39,24 @@ export function getDualityMessage(roll) {
|
|||
|
||||
return dualityElement;
|
||||
}
|
||||
|
||||
export const renderDualityButton = async event => {
|
||||
const button = event.currentTarget,
|
||||
traitValue = button.dataset.trait?.toLowerCase(),
|
||||
target = getCommandTarget();
|
||||
if (!target) return;
|
||||
|
||||
const config = {
|
||||
event: event,
|
||||
title: button.dataset.title,
|
||||
roll: {
|
||||
modifier: traitValue ? target.system.traits[traitValue].value : null,
|
||||
label: button.dataset.label,
|
||||
type: button.dataset.actionType ?? null // Need check
|
||||
},
|
||||
chatMessage: {
|
||||
template: 'systems/daggerheart/templates/chat/duality-roll.hbs'
|
||||
}
|
||||
};
|
||||
await target.diceRoll(config);
|
||||
};
|
||||
|
|
|
|||
60
module/enrichers/TemplateEnricher.mjs
Normal file
60
module/enrichers/TemplateEnricher.mjs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { range as configRange } from '../config/generalConfig.mjs';
|
||||
|
||||
export default function DhTemplateEnricher(match, _options) {
|
||||
const parts = match[1].split('|').map(x => x.trim());
|
||||
|
||||
let type = null,
|
||||
range = null;
|
||||
|
||||
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(CONST.MEASURED_TEMPLATE_TYPES).find(
|
||||
x => x.toLowerCase() === split[1]
|
||||
);
|
||||
type = matchedType;
|
||||
break;
|
||||
case 'range':
|
||||
const matchedRange = Object.values(configRange).find(
|
||||
x => x.id.toLowerCase() === split[1] || x.short === split[1]
|
||||
);
|
||||
range = matchedRange?.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!type || !range) return match[0];
|
||||
|
||||
const templateElement = document.createElement('span');
|
||||
templateElement.innerHTML = `
|
||||
<button class="measured-template-button" data-type="${type}" data-range="${range}">
|
||||
${game.i18n.localize(`TEMPLATE.TYPES.${type}`)} - ${game.i18n.localize(`DAGGERHEART.Range.${range}.name`)}
|
||||
</button>
|
||||
`;
|
||||
|
||||
return templateElement;
|
||||
}
|
||||
|
||||
export const renderMeasuredTemplate = async event => {
|
||||
const button = event.currentTarget,
|
||||
type = button.dataset.type,
|
||||
range = button.dataset.range;
|
||||
|
||||
if (!type || !range || !game.canvas.scene) return;
|
||||
|
||||
const distance = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement)[range];
|
||||
const { width, height } = game.canvas.scene.dimensions;
|
||||
canvas.scene.createEmbeddedDocuments('MeasuredTemplate', [
|
||||
{
|
||||
x: width / 2,
|
||||
y: height / 2,
|
||||
t: type,
|
||||
distance: distance,
|
||||
width: type === CONST.MEASURED_TEMPLATE_TYPES.RAY ? 5 : undefined,
|
||||
angle: type === CONST.MEASURED_TEMPLATE_TYPES.CONE ? CONFIG.MeasuredTemplate.defaults.angle : undefined
|
||||
}
|
||||
]);
|
||||
};
|
||||
4
module/enrichers/_module.mjs
Normal file
4
module/enrichers/_module.mjs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import DhDualityRollEnricher from './DualityRollEnricher.mjs';
|
||||
import DhTemplateEnricher from './TemplateEnricher.mjs';
|
||||
|
||||
export { DhDualityRollEnricher, DhTemplateEnricher };
|
||||
Loading…
Add table
Add a link
Reference in a new issue