mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Added so that emanation templates auto size their base to any token at the spot its placed
This commit is contained in:
parent
37c53ad74e
commit
3146dc2e63
2 changed files with 38 additions and 116 deletions
|
|
@ -45,4 +45,42 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
|
|||
|
||||
return super._createDragShapeData(event);
|
||||
}
|
||||
|
||||
async placeRegion(data, options = {}) {
|
||||
const preConfirm = ({ _event, document, _create, _options }) => {
|
||||
const shape = document.shapes[0];
|
||||
const isEmanation = shape.type === 'emanation';
|
||||
if (isEmanation) {
|
||||
const { x, y } = shape.base.origin;
|
||||
|
||||
const gridSize = canvas.grid.size;
|
||||
const inBounds = canvas.scene.tokens.filter(t => {
|
||||
return x.between(t.x, t.x + t.width * gridSize) && y.between(t.y, t.y + t.height * gridSize);
|
||||
});
|
||||
|
||||
if (inBounds.length !== 1) return options.basePreConfirm?.() ?? true;
|
||||
|
||||
const shapeData = shape.toObject();
|
||||
const token = inBounds[0];
|
||||
document.updateSource({
|
||||
shapes: [
|
||||
{
|
||||
...shapeData,
|
||||
base: {
|
||||
...shapeData.base,
|
||||
height: token.height,
|
||||
width: token.width,
|
||||
x: token.x,
|
||||
y: token.y
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
return options?.basePreConfirm?.() ?? true;
|
||||
};
|
||||
|
||||
super.placeRegion(data, { ...options, preConfirm });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue