Don't show the drag ruler to players who cannot se the dragged token
As a side effect this will now also show the coloring to other players
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
# In development
|
||||||
|
## New features
|
||||||
|
- The drag ruler will now be colored for other players than the dragging player as well
|
||||||
|
- The drag ruler won't be shown to other players if they cannot see the dragged token
|
||||||
+26
-4
@@ -6,7 +6,7 @@ import {registerSettings, settingsKey} from "./settings.js"
|
|||||||
Hooks.once("init", () => {
|
Hooks.once("init", () => {
|
||||||
registerSettings()
|
registerSettings()
|
||||||
hookTokenDragHandlers()
|
hookTokenDragHandlers()
|
||||||
hookRulerHandlers()
|
hookRulerFunctions()
|
||||||
patchRulerMeasure()
|
patchRulerMeasure()
|
||||||
patchRulerHighlightMeasurement()
|
patchRulerHighlightMeasurement()
|
||||||
|
|
||||||
@@ -26,12 +26,14 @@ Hooks.once("ready", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Hooks.on("canvasReady", () => {
|
Hooks.on("canvasReady", () => {
|
||||||
canvas.controls.ruler.draggedToken = null
|
canvas.controls.rulers.children.forEach(ruler => {
|
||||||
Object.defineProperty(canvas.controls.ruler, "isDragRuler", {
|
ruler.draggedToken = null
|
||||||
|
Object.defineProperty(ruler, "isDragRuler", {
|
||||||
get: function isDragRuler() {
|
get: function isDragRuler() {
|
||||||
return Boolean(this.draggedToken) // If draggedToken is set this is a drag ruler
|
return Boolean(this.draggedToken) // If draggedToken is set this is a drag ruler
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function hookTokenDragHandlers() {
|
function hookTokenDragHandlers() {
|
||||||
@@ -62,7 +64,7 @@ function hookTokenDragHandlers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hookRulerHandlers() {
|
function hookRulerFunctions() {
|
||||||
const originalMoveTokenHandler = Ruler.prototype.moveToken
|
const originalMoveTokenHandler = Ruler.prototype.moveToken
|
||||||
Ruler.prototype.moveToken = function (event) {
|
Ruler.prototype.moveToken = function (event) {
|
||||||
const eventHandled = onRulerMoveToken.call(this, event)
|
const eventHandled = onRulerMoveToken.call(this, event)
|
||||||
@@ -70,6 +72,22 @@ function hookRulerHandlers() {
|
|||||||
return originalMoveTokenHandler.call(this, event)
|
return originalMoveTokenHandler.call(this, event)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalToJSON = Ruler.prototype.toJSON
|
||||||
|
Ruler.prototype.toJSON = function () {
|
||||||
|
const json = originalToJSON.call(this)
|
||||||
|
if (this.draggedToken)
|
||||||
|
json["draggedToken"] = this.draggedToken.data._id
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalUpdate = Ruler.prototype.update
|
||||||
|
Ruler.prototype.update = function (data) {
|
||||||
|
if (data.draggedToken) {
|
||||||
|
this.draggedToken = canvas.tokens.get(data.draggedToken)
|
||||||
|
}
|
||||||
|
originalUpdate.call(this, data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTokenLeftDragStart(event) {
|
function onTokenLeftDragStart(event) {
|
||||||
@@ -127,6 +145,10 @@ function patchRulerMeasure() {
|
|||||||
code = code.slice(code.indexOf("\n"), code.lastIndexOf("\n"))
|
code = code.slice(code.indexOf("\n"), code.lastIndexOf("\n"))
|
||||||
code = strInsertAfter(code, "for ( let [i, d] of distances.entries() ) {\n", "segments[i].startDistance = totalDistance\n")
|
code = strInsertAfter(code, "for ( let [i, d] of distances.entries() ) {\n", "segments[i].startDistance = totalDistance\n")
|
||||||
code = strInsertAfter(code, "this._highlightMeasurement(ray", ", s.startDistance")
|
code = strInsertAfter(code, "this._highlightMeasurement(ray", ", s.startDistance")
|
||||||
|
|
||||||
|
// Don't show ruler if the measured token is invisible
|
||||||
|
code = "if (this.isDragRuler && !this.draggedToken.isVisible) return [];" + code
|
||||||
|
|
||||||
Ruler.prototype.measure = new Function("destination", "{gridSpaces=true}={}", code)
|
Ruler.prototype.measure = new Function("destination", "{gridSpaces=true}={}", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user