mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-24 16:33:38 +02:00
Also snap emanations when done from scene controls
This commit is contained in:
parent
68081bd7e1
commit
d997922fb2
1 changed files with 20 additions and 11 deletions
|
|
@ -43,7 +43,14 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
|
||||||
const hole = ui.controls.controls[this.options.name].tools.hole?.active ?? false;
|
const hole = ui.controls.controls[this.options.name].tools.hole?.active ?? false;
|
||||||
if (game.activeTool === 'inFront') return { type: 'cone', x: 0, y: 0, radius: 0, angle: 180, hole };
|
if (game.activeTool === 'inFront') return { type: 'cone', x: 0, y: 0, radius: 0, angle: 180, hole };
|
||||||
|
|
||||||
return super._createDragShapeData(event);
|
const shape = super._createDragShapeData(event);
|
||||||
|
const token = shape?.type === 'emanation' && shape.base?.type === 'token' ? this.#findTokenInBounds(event.interactionData.origin) : null;
|
||||||
|
if (token) {
|
||||||
|
shape.base.width = token.width;
|
||||||
|
shape.base.height = token.height;
|
||||||
|
event.interactionData.origin = token.getCenterPoint();
|
||||||
|
}
|
||||||
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
async placeRegion(data, options = {}) {
|
async placeRegion(data, options = {}) {
|
||||||
|
|
@ -51,17 +58,9 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
|
||||||
const shape = document.shapes[0];
|
const shape = document.shapes[0];
|
||||||
const isEmanation = shape.type === 'emanation';
|
const isEmanation = shape.type === 'emanation';
|
||||||
if (isEmanation) {
|
if (isEmanation) {
|
||||||
const { x, y } = shape.base.origin;
|
const token = this.#findTokenInBounds(shape.base.origin);
|
||||||
|
if (!token) return options.preConfirm?.() ?? true;
|
||||||
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.preConfirm?.() ?? true;
|
|
||||||
|
|
||||||
const shapeData = shape.toObject();
|
const shapeData = shape.toObject();
|
||||||
const token = inBounds[0];
|
|
||||||
document.updateSource({
|
document.updateSource({
|
||||||
shapes: [
|
shapes: [
|
||||||
{
|
{
|
||||||
|
|
@ -83,4 +82,14 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
|
||||||
|
|
||||||
super.placeRegion(data, { ...options, preConfirm });
|
super.placeRegion(data, { ...options, preConfirm });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Searches for token at origin point, returning null if there are no tokens or multiple overlapping tokens */
|
||||||
|
#findTokenInBounds(origin) {
|
||||||
|
const { x, y } = 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);
|
||||||
|
});
|
||||||
|
return inBounds.length === 1 ? inBounds[0] : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue