mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Add extra features to the Temple Enricher and fix the mousewheel issues with the Template Manager (#1147)
Co-authored-by: Chris Ryan <chrisr@blackhole>
This commit is contained in:
parent
2c6aabb97a
commit
58f039ce96
2 changed files with 63 additions and 18 deletions
|
|
@ -3,6 +3,8 @@ export default function DhTemplateEnricher(match, _options) {
|
|||
|
||||
let type = null,
|
||||
range = null,
|
||||
angle = CONFIG.MeasuredTemplate.defaults.angle,
|
||||
direction = 0,
|
||||
inline = false;
|
||||
|
||||
parts.forEach(part => {
|
||||
|
|
@ -16,14 +18,24 @@ export default function DhTemplateEnricher(match, _options) {
|
|||
type = matchedType;
|
||||
break;
|
||||
case 'range':
|
||||
const matchedRange = Object.values(CONFIG.DH.GENERAL.templateRanges).find(
|
||||
x => x.id.toLowerCase() === split[1] || x.short === split[1]
|
||||
);
|
||||
range = matchedRange?.id;
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -32,10 +44,32 @@ export default function DhTemplateEnricher(match, _options) {
|
|||
|
||||
const label = game.i18n.localize(`DAGGERHEART.CONFIG.TemplateTypes.${type}`);
|
||||
|
||||
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) {
|
||||
directionDisplay = 'direction:' + direction;
|
||||
}
|
||||
|
||||
let extraDisplay = '';
|
||||
if (angleDisplay != '' && directionDisplay != '') {
|
||||
extraDisplay = ' (' + angleDisplay + '|' + directionDisplay + ')';
|
||||
} else if (angleDisplay != '') {
|
||||
extraDisplay = ' (' + angleDisplay + ')';
|
||||
} else if (directionDisplay != '') {
|
||||
extraDisplay = ' (' + directionDisplay + ')';
|
||||
}
|
||||
|
||||
const templateElement = document.createElement('span');
|
||||
templateElement.innerHTML = `
|
||||
<button type="button" class="measured-template-button${inline ? ' inline' : ''}" data-type="${type}" data-range="${range}">
|
||||
${label} - ${game.i18n.localize(`DAGGERHEART.CONFIG.Range.${range}.name`)}
|
||||
<button type="button" class="measured-template-button${inline ? ' inline' : ''}"
|
||||
data-type="${type}" data-range="${range}" data-angle="${angle}" data-direction="${direction}">
|
||||
${label} - ${rangeDisplay}${extraDisplay}
|
||||
</button>
|
||||
`;
|
||||
|
||||
|
|
@ -45,21 +79,25 @@ export default function DhTemplateEnricher(match, _options) {
|
|||
export const renderMeasuredTemplate = async event => {
|
||||
const button = event.currentTarget,
|
||||
type = button.dataset.type,
|
||||
range = button.dataset.range;
|
||||
range = button.dataset.range,
|
||||
angle = button.dataset.angle,
|
||||
direction = button.dataset.direction;
|
||||
|
||||
if (!type || !range || !game.canvas.scene) return;
|
||||
|
||||
const usedType = type === 'inFront' ? 'cone' : type === 'emanation' ? 'circle' : type;
|
||||
const angle =
|
||||
const usedAngle =
|
||||
type === CONST.MEASURED_TEMPLATE_TYPES.CONE
|
||||
? CONFIG.MeasuredTemplate.defaults.angle
|
||||
? (angle ?? CONFIG.MeasuredTemplate.defaults.angle)
|
||||
: type === CONFIG.DH.GENERAL.templateTypes.INFRONT
|
||||
? '180'
|
||||
: undefined;
|
||||
|
||||
const baseDistance = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement[
|
||||
range
|
||||
];
|
||||
let baseDistance = range;
|
||||
if (Number.isNaN(Number(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;
|
||||
|
||||
const { width, height } = game.canvas.scene.dimensions;
|
||||
|
|
@ -69,7 +107,8 @@ export const renderMeasuredTemplate = async event => {
|
|||
t: usedType,
|
||||
distance: distance,
|
||||
width: type === CONST.MEASURED_TEMPLATE_TYPES.RAY ? 5 : undefined,
|
||||
angle: angle
|
||||
angle: usedAngle,
|
||||
direction: direction
|
||||
};
|
||||
|
||||
CONFIG.ux.TemplateManager.createPreview(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue