Allow deleting of waypoints with the 'X' key (resolves #14)

This commit is contained in:
Manuel Vögele
2021-02-08 18:29:49 +01:00
parent 4bd1473310
commit 2b66b43c55
2 changed files with 27 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
- Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar - Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar
- The module can now be configured use a fixed color instead of the player color for the first speed range - The module can now be configured use a fixed color instead of the player color for the first speed range
- On gridless maps the ruler will now change it's color to indicate the different speed ranges - On gridless maps the ruler will now change it's color to indicate the different speed ranges
- As an alternative to right click (or spacebar, if you have swapped right and spacebar behavior) waypoints can now also be deleted with the `X` key
### Bugfixes ### Bugfixes
- Disabling snap to grid with shift now works as expected - Disabling snap to grid with shift now works as expected
+26
View File
@@ -8,6 +8,7 @@ Hooks.once("init", () => {
registerSettings() registerSettings()
hookTokenDragHandlers() hookTokenDragHandlers()
hookRulerFunctions() hookRulerFunctions()
hookKeyboardManagerFunctions()
patchRulerHighlightMeasurement() patchRulerHighlightMeasurement()
availableSpeedProviders["native"] = nativeSpeedProvider availableSpeedProviders["native"] = nativeSpeedProvider
@@ -100,6 +101,31 @@ function hookRulerFunctions() {
} }
} }
function hookKeyboardManagerFunctions() {
const originalHandleKeys = KeyboardManager.prototype._handleKeys
KeyboardManager.prototype._handleKeys = function (event, key, up) {
const eventHandled = handleKeys.call(this, event, key, up)
if (!eventHandled)
originalHandleKeys.call(this, event, key, up)
}
}
function handleKeys(event, key, up) {
if (up || event.repeat || this.hasFocus)
return false
if (key.toLowerCase() === "x") return onKeyDownX()
return false
}
function onKeyDownX() {
if (!canvas.controls.ruler.isDragRuler)
return false
deleteWaypoint()
return true
}
function onTokenLeftDragStart(event) { function onTokenLeftDragStart(event) {
canvas.controls.ruler.draggedToken = this canvas.controls.ruler.draggedToken = this
const tokenCenter = {x: this.x + canvas.grid.grid.w / 2, y: this.y + canvas.grid.grid.h / 2} const tokenCenter = {x: this.x + canvas.grid.grid.w / 2, y: this.y + canvas.grid.grid.h / 2}