Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a54a47951 | |||
| 0b71504da3 | |||
| 0a7d8495c6 | |||
| 6e74582089 |
@@ -1,3 +1,11 @@
|
|||||||
|
## 1.3.5
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a regression where spaces could suddenly change their color during measurement
|
||||||
|
|
||||||
|
## 1.3.4
|
||||||
|
### Module compatibility
|
||||||
|
- Increased compatiblility with other modules (namely Drag Ruler and Terrain Ruler are no longer incompatible)
|
||||||
|
|
||||||
## 1.3.3
|
## 1.3.3
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- Speed Provider Settings are now being saved for non GM players
|
- Speed Provider Settings are now being saved for non GM players
|
||||||
|
|||||||
+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.3.3",
|
"version": "1.3.5",
|
||||||
"minimumCoreVersion" : "0.7.9",
|
"minimumCoreVersion" : "0.7.9",
|
||||||
"compatibleCoreVersion" : "0.7.9",
|
"compatibleCoreVersion" : "0.7.9",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -31,7 +31,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.3.3.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.3.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",
|
||||||
|
|||||||
+41
-1
@@ -166,7 +166,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Highlight grid positions
|
// Highlight grid positions
|
||||||
this._highlightMeasurement(ray, s.startDistance);
|
highlightMeasurementNative.call(this, ray, s.startDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw endpoints
|
// Draw endpoints
|
||||||
@@ -177,3 +177,43 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
// Return the measured segments
|
// Return the measured segments
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function highlightMeasurementNative(ray, startDistance) {
|
||||||
|
const spacer = canvas.scene.data.gridType === CONST.GRID_TYPES.SQUARE ? 1.41 : 1;
|
||||||
|
const nMax = Math.max(Math.floor(ray.distance / (spacer * Math.min(canvas.grid.w, canvas.grid.h))), 1);
|
||||||
|
const tMax = Array.fromRange(nMax+1).map(t => t / nMax);
|
||||||
|
|
||||||
|
// Track prior position
|
||||||
|
let prior = null;
|
||||||
|
|
||||||
|
// Iterate over ray portions
|
||||||
|
for ( let [i, t] of tMax.entries() ) {
|
||||||
|
let {x, y} = ray.project(t);
|
||||||
|
|
||||||
|
// Get grid position
|
||||||
|
let [x0, y0] = (i === 0) ? [null, null] : prior;
|
||||||
|
let [x1, y1] = canvas.grid.grid.getGridPositionFromPixels(x, y);
|
||||||
|
if ( x0 === x1 && y0 === y1 ) continue;
|
||||||
|
|
||||||
|
// Highlight the grid position
|
||||||
|
let [xg, yg] = canvas.grid.grid.getPixelsFromGridPosition(x1, y1);
|
||||||
|
let subDistance = canvas.grid.measureDistances([{ray: new Ray(ray.A, {x: xg, y: yg})}], {gridSpaces: true})[0]
|
||||||
|
let color = dragRuler.getColorForDistance.call(this, startDistance, subDistance)
|
||||||
|
canvas.grid.highlightPosition(this.name, {x: xg, y: yg, color: color});
|
||||||
|
|
||||||
|
// Skip the first one
|
||||||
|
prior = [x1, y1];
|
||||||
|
if ( i === 0 ) continue;
|
||||||
|
|
||||||
|
// If the positions are not neighbors, also highlight their halfway point
|
||||||
|
if ( !canvas.grid.isNeighbor(x0, y0, x1, y1) ) {
|
||||||
|
let th = tMax[i - 1] + (0.5 / nMax);
|
||||||
|
let {x, y} = ray.project(th);
|
||||||
|
let [x1h, y1h] = canvas.grid.grid.getGridPositionFromPixels(x, y);
|
||||||
|
let [xgh, ygh] = canvas.grid.grid.getPixelsFromGridPosition(x1h, y1h);
|
||||||
|
subDistance = canvas.grid.measureDistances([{ray: new Ray(ray.A, {x: xgh, y: ygh})}], {gridSpaces: true})[0]
|
||||||
|
color = dragRuler.getColorForDistance.call(this, startDistance, subDistance)
|
||||||
|
canvas.grid.highlightPosition(this.name, {x: xgh, y: ygh, color: color});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
-25
@@ -13,7 +13,6 @@ Hooks.once("init", () => {
|
|||||||
hookTokenDragHandlers()
|
hookTokenDragHandlers()
|
||||||
hookRulerFunctions()
|
hookRulerFunctions()
|
||||||
hookKeyboardManagerFunctions()
|
hookKeyboardManagerFunctions()
|
||||||
patchRulerHighlightMeasurement()
|
|
||||||
|
|
||||||
window.dragRuler = {
|
window.dragRuler = {
|
||||||
getColorForDistance,
|
getColorForDistance,
|
||||||
@@ -238,11 +237,6 @@ function deleteWaypoint() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function strInsertAfter(haystack, needle, strToInsert) {
|
|
||||||
const pos = haystack.indexOf(needle) + needle.length
|
|
||||||
return haystack.slice(0, pos) + strToInsert + haystack.slice(pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getColorForDistance(startDistance, subDistance=0) {
|
export function getColorForDistance(startDistance, subDistance=0) {
|
||||||
if (!this.isDragRuler)
|
if (!this.isDragRuler)
|
||||||
return this.color
|
return this.color
|
||||||
@@ -263,22 +257,3 @@ export function getColorForDistance(startDistance, subDistance=0) {
|
|||||||
}, {range: Infinity, color: getUnreachableColorFromSpeedProvider()})
|
}, {range: Infinity, color: getUnreachableColorFromSpeedProvider()})
|
||||||
return currentRange.color
|
return currentRange.color
|
||||||
}
|
}
|
||||||
|
|
||||||
// These patches were written with foundry-0.7.9.js as reference
|
|
||||||
function patchRulerHighlightMeasurement() {
|
|
||||||
let code = Ruler.prototype._highlightMeasurement.toString()
|
|
||||||
// Replace CRLF with LF in case foundry.js has CRLF for some reason
|
|
||||||
code = code.replace(/\r\n/g, "\n")
|
|
||||||
// Remove function signature and closing curly bracket (those are on the first and last line)
|
|
||||||
code = code.slice(code.indexOf("\n"), code.lastIndexOf("\n"))
|
|
||||||
|
|
||||||
const calcColorCode = `
|
|
||||||
let subDistance = canvas.grid.measureDistances([{ray: new Ray(ray.A, {x: xg, y: yg})}], {gridSpaces: true})[0]
|
|
||||||
let color = dragRuler.getColorForDistance.call(this, startDistance, subDistance)
|
|
||||||
`
|
|
||||||
|
|
||||||
code = strInsertAfter(code, "Position(x1, y1);\n", calcColorCode)
|
|
||||||
code = strInsertAfter(code, "Position(x1h, y1h);\n", calcColorCode.replace("x: xg, y: yg", "x: xgh, y: ygh"))
|
|
||||||
code = code.replace(/color: this\.color\}/g, "color}")
|
|
||||||
Ruler.prototype._highlightMeasurement = new Function("ray", "startDistance=undefined", code)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user