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
|
## v1.1.1
|
||||||
### 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
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
"native": "Drag Ruler",
|
"native": "Drag Ruler",
|
||||||
"system": "System"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-6
@@ -124,30 +124,54 @@ function onTokenDragLeftDrop(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onTokenDragLeftCancel(event) {
|
function onTokenDragLeftCancel(event) {
|
||||||
|
// This function is invoked by right clicking
|
||||||
if (!canvas.controls.ruler.isDragRuler)
|
if (!canvas.controls.ruler.isDragRuler)
|
||||||
return false
|
return false
|
||||||
if (canvas.controls.ruler._state === Ruler.STATES.MEASURING) {
|
if (canvas.controls.ruler._state === Ruler.STATES.MEASURING) {
|
||||||
if (canvas.controls.ruler.waypoints.length > 1) {
|
if (!game.settings.get(settingsKey, "swapSpacebarRightClick")) {
|
||||||
canvas.controls.ruler._removeWaypoint(canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens), {snap: !event.shiftKey})
|
if (canvas.controls.ruler.waypoints.length > 1)
|
||||||
game.user.broadcastActivity({ruler: canvas.controls.ruler})
|
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
deleteWaypoint()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
canvas.controls.ruler._endMeasurement()
|
event.preventDefault()
|
||||||
canvas.controls.ruler.draggedToken = null
|
canvas.controls.ruler._addWaypoint(canvas.controls.ruler.destination)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRulerMoveToken(event) {
|
function onRulerMoveToken(event) {
|
||||||
|
// This function is invoked by left clicking
|
||||||
if (!this.isDragRuler)
|
if (!this.isDragRuler)
|
||||||
return false
|
return false
|
||||||
|
if (!game.settings.get(settingsKey, "swapSpacebarRightClick"))
|
||||||
this._addWaypoint(this.destination)
|
this._addWaypoint(this.destination)
|
||||||
|
else
|
||||||
|
deleteWaypoint()
|
||||||
return true
|
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) {
|
function strInsertAfter(haystack, needle, strToInsert) {
|
||||||
const pos = haystack.indexOf(needle) + needle.length
|
const pos = haystack.indexOf(needle) + needle.length
|
||||||
return haystack.slice(0, pos) + strToInsert + haystack.slice(pos)
|
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 const settingsKey = "drag-ruler";
|
||||||
|
|
||||||
export function registerSettings() {
|
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", {
|
game.settings.register(settingsKey, "alwaysShowSpeedForPCs", {
|
||||||
name: "drag-ruler.settings.alwaysShowSpeedForPCs.name",
|
name: "drag-ruler.settings.alwaysShowSpeedForPCs.name",
|
||||||
hint: "drag-ruler.settings.alwaysShowSpeedForPCs.hint",
|
hint: "drag-ruler.settings.alwaysShowSpeedForPCs.hint",
|
||||||
|
|||||||
Reference in New Issue
Block a user