Allow swapping of right click and spacebar behavior (resolves #4)
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## In development
|
||||
### New features
|
||||
- Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar
|
||||
|
||||
## v1.1.1
|
||||
### Bugfixes
|
||||
- Fixed a bug where tokens wouldn't be moved to the corect end position on gridless maps
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
"native": "Drag Ruler",
|
||||
"system": "System"
|
||||
}
|
||||
},
|
||||
"swapSpacebarRightClick": {
|
||||
"name": "Swap spacebar and right click",
|
||||
"hint": "Swaps the functions of spacebar and right click during dragging. If enabled right click will place waypoints and spacebar will delete them"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+32
-8
@@ -124,30 +124,54 @@ function onTokenDragLeftDrop(event) {
|
||||
}
|
||||
|
||||
function onTokenDragLeftCancel(event) {
|
||||
// This function is invoked by right clicking
|
||||
if (!canvas.controls.ruler.isDragRuler)
|
||||
return false
|
||||
if (canvas.controls.ruler._state === Ruler.STATES.MEASURING) {
|
||||
if (canvas.controls.ruler.waypoints.length > 1) {
|
||||
canvas.controls.ruler._removeWaypoint(canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens), {snap: !event.shiftKey})
|
||||
game.user.broadcastActivity({ruler: canvas.controls.ruler})
|
||||
event.preventDefault()
|
||||
if (!game.settings.get(settingsKey, "swapSpacebarRightClick")) {
|
||||
if (canvas.controls.ruler.waypoints.length > 1)
|
||||
event.preventDefault()
|
||||
deleteWaypoint()
|
||||
}
|
||||
else {
|
||||
canvas.controls.ruler._endMeasurement()
|
||||
canvas.controls.ruler.draggedToken = null
|
||||
return false
|
||||
event.preventDefault()
|
||||
canvas.controls.ruler._addWaypoint(canvas.controls.ruler.destination)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function onRulerMoveToken(event) {
|
||||
// This function is invoked by left clicking
|
||||
if (!this.isDragRuler)
|
||||
return false
|
||||
this._addWaypoint(this.destination)
|
||||
if (!game.settings.get(settingsKey, "swapSpacebarRightClick"))
|
||||
this._addWaypoint(this.destination)
|
||||
else
|
||||
deleteWaypoint()
|
||||
return true
|
||||
}
|
||||
|
||||
function deleteWaypoint() {
|
||||
if (canvas.controls.ruler.waypoints.length > 1) {
|
||||
canvas.controls.ruler._removeWaypoint(canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens), /* TODO What is this? */{snap: !event.shiftKey})
|
||||
game.user.broadcastActivity({ruler: canvas.controls.ruler})
|
||||
}
|
||||
else {
|
||||
const token = canvas.controls.ruler.draggedToken
|
||||
canvas.controls.ruler._endMeasurement()
|
||||
canvas.controls.ruler.draggedToken = null
|
||||
|
||||
// Deactivate the drag workflow in mouse
|
||||
token.mouseInteractionManager._deactivateDragEvents();
|
||||
token.mouseInteractionManager.state = token.mouseInteractionManager.states.HOVER;
|
||||
|
||||
// This will cancel the current drag operation
|
||||
// Pass in a fake event that hopefully is enough to allow other modules to function
|
||||
token._onDragLeftCancel({preventDefault: () => {return}})
|
||||
}
|
||||
}
|
||||
|
||||
function strInsertAfter(haystack, needle, strToInsert) {
|
||||
const pos = haystack.indexOf(needle) + needle.length
|
||||
return haystack.slice(0, pos) + strToInsert + haystack.slice(pos)
|
||||
|
||||
@@ -4,6 +4,15 @@ import {getDefaultDashMultiplier, getDefaultSpeedAttribute} from "./systems.js"
|
||||
export const settingsKey = "drag-ruler";
|
||||
|
||||
export function registerSettings() {
|
||||
game.settings.register(settingsKey, "swapSpacebarRightClick", {
|
||||
name: "drag-ruler.settings.swapSpacebarRightClick.name",
|
||||
hint: "drag-ruler.settings.swapSpacebarRightClick.hint",
|
||||
scope: "client",
|
||||
config: true,
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
|
||||
game.settings.register(settingsKey, "alwaysShowSpeedForPCs", {
|
||||
name: "drag-ruler.settings.alwaysShowSpeedForPCs.name",
|
||||
hint: "drag-ruler.settings.alwaysShowSpeedForPCs.hint",
|
||||
|
||||
Reference in New Issue
Block a user