Start measuring immediately when the token is being dragged

This commit is contained in:
Manuel Vögele
2021-02-05 11:11:32 +01:00
parent 46edfa8ae6
commit f1542b7789
3 changed files with 23 additions and 2 deletions
+1
View File
@@ -1,6 +1,7 @@
## In development ## In development
### Bugfixes ### Bugfixes
- Fixed a bug where tokens wouldn't be moved to the corect end position on gridless maps - Fixed a bug where tokens wouldn't be moved to the corect end position on gridless maps
- Ruler now appears immediately when the token is being dragged
## v1.1.0 ## v1.1.0
### New features ### New features
+20
View File
@@ -74,3 +74,23 @@ function calculateTokenOffset(tokenA, tokenB) {
function applyOffsetToRay(ray, offset) { function applyOffsetToRay(ray, offset) {
return new Ray({x: ray.A.x + offset.x, y: ray.A.y + offset.y}, {x: ray.B.x + offset.x, y: ray.B.y + offset.y}) return new Ray({x: ray.A.x + offset.x, y: ray.A.y + offset.y}, {x: ray.B.x + offset.x, y: ray.B.y + offset.y})
} }
// This is a modified version of Ruler._onMouseMove from foundry 0.7.9
export function onMouseMove(event) {
if (this._state === Ruler.STATES.MOVING) return;
// Extract event data
const mt = event._measureTime || 0;
const { destination, originalEvent } = event.data;
// Hide any existing Token HUD
canvas.hud.token.clear();
delete event.data.hudState;
// Draw measurement updates
if (Date.now() - mt > 50) {
this.measure(destination, { gridSpaces: !originalEvent.shiftKey });
event._measureTime = Date.now();
this._state = Ruler.STATES.MEASURING;
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
"use strict" "use strict"
import {availableSpeedProviders, currentSpeedProvider, registerModule, registerSystem, setCurrentSpeedProvider} from "./api.js" import {availableSpeedProviders, currentSpeedProvider, registerModule, registerSystem, setCurrentSpeedProvider} from "./api.js"
import {moveTokens} from "./foundry_imports.js" import {moveTokens, onMouseMove} from "./foundry_imports.js"
import {registerSettings, settingsKey} from "./settings.js" import {registerSettings, settingsKey} from "./settings.js"
Hooks.once("init", () => { Hooks.once("init", () => {
@@ -98,7 +98,7 @@ function onTokenLeftDragStart(event) {
function onTokenLeftDragMove(event) { function onTokenLeftDragMove(event) {
if (canvas.controls.ruler.isDragRuler) if (canvas.controls.ruler.isDragRuler)
canvas.controls.ruler._onMouseMove(event) onMouseMove.call(canvas.controls.ruler, event)
} }
function onTokenDragLeftDrop(event) { function onTokenDragLeftDrop(event) {