Calculate the correct snappig for measured templates when placing a waypoint
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## In development
|
## In development
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
- Fixed a bug that prevented waypoints for measurement templates from snapping to any other point than a grid cell corner (or grid cell center on hex)
|
||||||
- Fixed a bug that could cause the ruler to not end up at the token's center (especially if the token is being moved very quickly and then stopped abruptly)
|
- Fixed a bug that could cause the ruler to not end up at the token's center (especially if the token is being moved very quickly and then stopped abruptly)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {Line} from "./geometry.js";
|
|||||||
import {getColorForDistance} from "./main.js"
|
import {getColorForDistance} from "./main.js"
|
||||||
import {trackRays} from "./movement_tracking.js"
|
import {trackRays} from "./movement_tracking.js"
|
||||||
import {recalculate} from "./socket.js";
|
import {recalculate} from "./socket.js";
|
||||||
import {applyTokenSizeOffset, getSnapPointForMeasuredTemplate, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
import {applyTokenSizeOffset, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
||||||
|
|
||||||
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
||||||
export async function moveEntities(draggedEntity, selectedEntities) {
|
export async function moveEntities(draggedEntity, selectedEntities) {
|
||||||
@@ -144,10 +144,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
if (snap) {
|
if (snap) {
|
||||||
if (isToken)
|
destination = getSnapPointForEntity(destination.x, destination.y, this.draggedEntity);
|
||||||
destination = getSnapPointForToken(destination.x, destination.y, this.draggedEntity);
|
|
||||||
else
|
|
||||||
destination = getSnapPointForMeasuredTemplate(destination.x, destination.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const terrainRulerAvailable = isToken && game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
const terrainRulerAvailable = isToken && game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
||||||
|
|||||||
+4
-3
@@ -1,7 +1,7 @@
|
|||||||
import {measure} from "./foundry_imports.js"
|
import {measure} from "./foundry_imports.js"
|
||||||
import {getMovementHistory} from "./movement_tracking.js";
|
import {getMovementHistory} from "./movement_tracking.js";
|
||||||
import {settingsKey} from "./settings.js";
|
import {settingsKey} from "./settings.js";
|
||||||
import {getSnapPointForToken} from "./util.js";
|
import {getSnapPointForEntity} from "./util.js";
|
||||||
|
|
||||||
export class DragRulerRuler extends Ruler {
|
export class DragRulerRuler extends Ruler {
|
||||||
// Functions below are overridden versions of functions in Ruler
|
// Functions below are overridden versions of functions in Ruler
|
||||||
@@ -65,8 +65,9 @@ export class DragRulerRuler extends Ruler {
|
|||||||
|
|
||||||
// The functions below aren't present in the orignal Ruler class and are added by Drag Ruler
|
// The functions below aren't present in the orignal Ruler class and are added by Drag Ruler
|
||||||
dragRulerAddWaypoint(point, snap=true) {
|
dragRulerAddWaypoint(point, snap=true) {
|
||||||
if (snap)
|
if (snap) {
|
||||||
point = getSnapPointForToken(point.x, point.y, this.draggedEntity);
|
point = getSnapPointForEntity(point.x, point.y, this.draggedEntity);
|
||||||
|
}
|
||||||
this.waypoints.push(new PIXI.Point(point.x, point.y));
|
this.waypoints.push(new PIXI.Point(point.x, point.y));
|
||||||
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ export function getSnapPointForMeasuredTemplate(x, y) {
|
|||||||
return new PIXI.Point(snappedX, snappedY);
|
return new PIXI.Point(snappedX, snappedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSnapPointForEntity(x, y, entity) {
|
||||||
|
const isToken = entity instanceof Token;
|
||||||
|
if (isToken)
|
||||||
|
return getSnapPointForToken(x, y, entity);
|
||||||
|
else
|
||||||
|
return getSnapPointForMeasuredTemplate(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
export function highlightTokenShape(position, shape, color, alpha) {
|
export function highlightTokenShape(position, shape, color, alpha) {
|
||||||
const layer = canvas.grid.highlightLayers[this.name];
|
const layer = canvas.grid.highlightLayers[this.name];
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
|
|||||||
Reference in New Issue
Block a user