Add keybinding for the pathfinding feature

This commit is contained in:
Manuel Vögele
2022-01-27 23:58:51 +01:00
parent 9140ef3acf
commit 4c006d34c9
5 changed files with 26 additions and 1 deletions
+4
View File
@@ -40,6 +40,10 @@
"moveWithoutAnimation": { "moveWithoutAnimation": {
"name": "Token animation deaktivieren", "name": "Token animation deaktivieren",
"hint": "Wenn diese Taste gedrückt wird, während ein Token fallen gelassen wird, bewegt es sich ohne Animation zum Zielort." "hint": "Wenn diese Taste gedrückt wird, während ein Token fallen gelassen wird, bewegt es sich ohne Animation zum Zielort."
},
"togglePathfinding": {
"name": "Wegfindung umschalten",
"hint": "Wenn diese Taste gedrückt gehalten wird, während ein Token gezogen wird, wird die Wegfindung vorübergehend aktiviert/deaktiviert"
} }
}, },
"settings": { "settings": {
+4
View File
@@ -40,6 +40,10 @@
"moveWithoutAnimation": { "moveWithoutAnimation": {
"name": "Disable token animation", "name": "Disable token animation",
"hint": "When being held while dropping a token, the token will move to the target location without animating" "hint": "When being held while dropping a token, the token will move to the target location without animating"
},
"togglePathfinding": {
"name": "Toggle pathfinding",
"hint": "When being held while dragging a token, the pathfinding functionality will be temporarily enabled/disabled"
} }
}, },
"settings": { "settings": {
+15
View File
@@ -3,6 +3,7 @@ import {getMeasurePosition, setSnapParameterOnOptions} from "./util.js";
export let disableSnap = false; export let disableSnap = false;
export let moveWithoutAnimation = false; export let moveWithoutAnimation = false;
export let togglePathfinding = false;
export function registerKeybindings() { export function registerKeybindings() {
game.keybindings.register(settingsKey, "cancelDrag", { game.keybindings.register(settingsKey, "cancelDrag", {
@@ -50,6 +51,16 @@ export function registerKeybindings() {
}], }],
precedence: -1, precedence: -1,
}); });
if (game.settings.get(settingsKey, "allowPathfinding")) {
game.keybindings.register(settingsKey, "togglePathfinding", {
name: "drag-ruler.keybindings.togglePathfinding.name",
hint: "drag-ruler.keybindings.togglePathfinding.hint",
onDown: handleTogglePathfinding,
onUp: handleTogglePathfinding,
precedence: -1,
});
}
} }
function handleDeleteWaypoint() { function handleDeleteWaypoint() {
@@ -103,3 +114,7 @@ function handleDisableSnap(event) {
function handleMoveWithoutAnimation(event) { function handleMoveWithoutAnimation(event) {
moveWithoutAnimation = !event.up; moveWithoutAnimation = !event.up;
} }
function handleTogglePathfinding(event) {
togglePathfinding = !event.up;
}
+2 -1
View File
@@ -1,4 +1,5 @@
import {getCenterFromGridPositionObj} from "./foundry_fixes.js"; import {getCenterFromGridPositionObj} from "./foundry_fixes.js";
import { togglePathfinding } from "./keybindings.js";
import {settingsKey} from "./settings.js"; import {settingsKey} from "./settings.js";
// TODO Wipe cache if walls layer is being modified // TODO Wipe cache if walls layer is being modified
@@ -7,7 +8,7 @@ let cached_nodes = undefined;
export function is_pathfinding_enabled() { export function is_pathfinding_enabled() {
if (!game.settings.get(settingsKey, "allowPathfinding")) if (!game.settings.get(settingsKey, "allowPathfinding"))
return false; return false;
return game.settings.get(settingsKey, "autoPathfinding") != game.keyboard.isDown("y") return game.settings.get(settingsKey, "autoPathfinding") != togglePathfinding;
} }
function get_node(pos, initialize=true) { function get_node(pos, initialize=true) {
+1
View File
@@ -89,6 +89,7 @@ export function registerSettings() {
config: true, config: true,
type: Boolean, type: Boolean,
default: false, default: false,
onChange: () => location.reload(),
}); });
game.settings.register(settingsKey, "autoPathfinding", { game.settings.register(settingsKey, "autoPathfinding", {