Merge branch 'master' into develop
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
## 1.4.5
|
||||||
|
### Bugfixes
|
||||||
|
- Tiny tokens (0.5x0.5 or smaller) now snap to the coners of a square like they do in vanilla foundry ([#49](https://github.com/manuelVo/foundryvtt-drag-ruler/issues/49))
|
||||||
|
- Fixed a bug that could cause a meausred distance to be wrong when disabling token snapping using the shift key
|
||||||
|
- Fixed a bug where the highlighted path could have gaps when disabbling token snapping using the shift key
|
||||||
|
|
||||||
|
|
||||||
## 1.4.4
|
## 1.4.4
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- Fix snapping for tokens that are smaller than 1x1
|
- Fix snapping for tokens that are smaller than 1x1
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
"name": "drag-ruler",
|
"name": "drag-ruler",
|
||||||
"title": "Drag Ruler",
|
"title": "Drag Ruler",
|
||||||
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
||||||
"version": "1.4.4",
|
"version": "1.4.5",
|
||||||
"minimumCoreVersion" : "0.7.9",
|
"minimumCoreVersion" : "0.7.9",
|
||||||
"compatibleCoreVersion" : "0.7.9",
|
"compatibleCoreVersion" : "0.7.9",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
||||||
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.4.4.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.4.5.zip",
|
||||||
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
||||||
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
||||||
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
||||||
|
|||||||
@@ -108,9 +108,14 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
if (snap)
|
if (snap)
|
||||||
destination = getSnapPointForToken(destination.x, destination.y, this.draggedToken)
|
destination = getSnapPointForToken(destination.x, destination.y, this.draggedToken)
|
||||||
|
|
||||||
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS;
|
||||||
|
|
||||||
const waypoints = this.waypoints.concat([destination]);
|
const waypoints = this.waypoints.concat([destination]);
|
||||||
// Move the waypoints to the center of the grid if a size is used that measures from edge to edge
|
// Move the waypoints to the center of the grid if a size is used that measures from edge to edge
|
||||||
const centeredWaypoints = applyTokenSizeOffset(waypoints, this.draggedToken)
|
const centeredWaypoints = applyTokenSizeOffset(waypoints, this.draggedToken)
|
||||||
|
// Foundries native ruler requires the waypoints to sit in the dead center of the square to work properly
|
||||||
|
if (!terrainRulerAvailable)
|
||||||
|
centeredWaypoints.forEach(w => [w.x, w.y] = canvas.grid.getCenter(w.x, w.y));
|
||||||
|
|
||||||
const r = this.ruler;
|
const r = this.ruler;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
@@ -133,10 +138,10 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
centeredSegments.push({ray: centeredRay, label})
|
centeredSegments.push({ray: centeredRay, label})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const shape = getTokenShape(this.draggedToken)
|
const shape = getTokenShape(this.draggedToken)
|
||||||
|
|
||||||
// Compute measured distance
|
// Compute measured distance
|
||||||
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS
|
|
||||||
let distances
|
let distances
|
||||||
if (terrainRulerAvailable)
|
if (terrainRulerAvailable)
|
||||||
distances = game.terrainRuler.measureDistances(centeredSegments, {costFunction: (x, y) => getCostFromSpeedProvider(this.draggedToken, getAreaFromPositionAndShape({x, y}, shape), {x, y})});
|
distances = game.terrainRuler.measureDistances(centeredSegments, {costFunction: (x, y) => getCostFromSpeedProvider(this.draggedToken, getAreaFromPositionAndShape({x, y}, shape), {x, y})});
|
||||||
|
|||||||
+16
@@ -7,6 +7,9 @@ export function* zip(it1, it2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSnapPointForToken(x, y, token) {
|
export function getSnapPointForToken(x, y, token) {
|
||||||
|
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) {
|
||||||
|
return new PIXI.Point(x, y);
|
||||||
|
}
|
||||||
if (canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(token)) {
|
if (canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(token)) {
|
||||||
if (token.getFlag("hex-size-support", "borderSize") % 2 === 0) {
|
if (token.getFlag("hex-size-support", "borderSize") % 2 === 0) {
|
||||||
const snapPoint = CONFIG.hexSizeSupport.findVertexSnapPoint(x, y, token, canvas.grid.grid)
|
const snapPoint = CONFIG.hexSizeSupport.findVertexSnapPoint(x, y, token, canvas.grid.grid)
|
||||||
@@ -16,9 +19,22 @@ export function getSnapPointForToken(x, y, token) {
|
|||||||
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Tiny tokens can snap to the cells corners
|
||||||
|
if (!canvas.grid.isHex && token.data.width <= 0.5) {
|
||||||
|
const [topLeftX, topLeftY] = canvas.grid.getTopLeft(x, y);
|
||||||
|
const offsetX = x - topLeftX;
|
||||||
|
const offsetY = y - topLeftY;
|
||||||
|
const subGridWidth = Math.floor(canvas.grid.w / 2);
|
||||||
|
const subGridHeight = Math.floor(canvas.grid.h / 2);
|
||||||
|
const subGridPosX = Math.floor(offsetX / subGridWidth);
|
||||||
|
const subGridPosY = Math.floor(offsetY / subGridHeight);
|
||||||
|
return new PIXI.Point(topLeftX + (subGridPosX + 0.5) * subGridWidth, topLeftY + (subGridPosY + 0.5) * subGridHeight);
|
||||||
|
}
|
||||||
|
// Hex tokens, tokens with odd multipliers (1x1, 3x3, ...) and tokens smaller than 1x1 but bigger than 0.5x0.5 snap to the center of the grid cell
|
||||||
if (canvas.grid.isHex || Math.round(token.data.width) % 2 === 1 || token.data.width < 1) {
|
if (canvas.grid.isHex || Math.round(token.data.width) % 2 === 1 || token.data.width < 1) {
|
||||||
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
||||||
}
|
}
|
||||||
|
// All remaining tokens (those with even or fractional multipliers on square grids) snap to the intersection points of the grid
|
||||||
const [snappedX, snappedY] = canvas.grid.getCenter(x - canvas.grid.w / 2, y - canvas.grid.h / 2)
|
const [snappedX, snappedY] = canvas.grid.getCenter(x - canvas.grid.w / 2, y - canvas.grid.h / 2)
|
||||||
return new PIXI.Point(snappedX + canvas.grid.w / 2, snappedY + canvas.grid.h / 2)
|
return new PIXI.Point(snappedX + canvas.grid.w / 2, snappedY + canvas.grid.h / 2)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user