Add an option to do pathfinding automatically

This commit is contained in:
Manuel Vögele
2021-07-19 22:39:11 +02:00
parent 54cebc3192
commit c9696f8725
3 changed files with 15 additions and 1 deletions
+4
View File
@@ -51,6 +51,10 @@
"name": "Automatically start measuring", "name": "Automatically start measuring",
"hint": "If enabled, Drag Ruler will start measuring as soon as the token is being dragged. If disabled, Drag Ruler will remain inactive and will only start measuring once the button to add a waypoint is being pressed." "hint": "If enabled, Drag Ruler will start measuring as soon as the token is being dragged. If disabled, Drag Ruler will remain inactive and will only start measuring once the button to add a waypoint is being pressed."
}, },
"autoPathfinding": {
"name": "Pathfinding by default",
"hint": "If enabled, dragging a token will automatically use a pathfinding ruler"
},
"enableMovementHistory": { "enableMovementHistory": {
"name": "Enable movement history during combat", "name": "Enable movement history during combat",
"hint": "If enabled, Drag Ruler will remember the path a token took during it's turn in combat and will display it when you pick the token back up." "hint": "If enabled, Drag Ruler will remember the path a token took during it's turn in combat and will display it when you pick the token back up."
+2 -1
View File
@@ -4,6 +4,7 @@ import {Line} from "./geometry.js";
import {disableSnap, moveWithoutAnimation} from "./keybindings.js"; import {disableSnap, moveWithoutAnimation} from "./keybindings.js";
import {trackRays} from "./movement_tracking.js" import {trackRays} from "./movement_tracking.js"
import {find_path} from "./pathfinding.js"; import {find_path} from "./pathfinding.js";
import {settingsKey} from "./settings.js";
import {recalculate} from "./socket.js"; import {recalculate} from "./socket.js";
import {applyTokenSizeOffset, enumeratedZip, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, sum} from "./util.js"; import {applyTokenSizeOffset, enumeratedZip, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, sum} from "./util.js";
@@ -132,7 +133,7 @@ function scheduleMeasurement(destination, event) {
const mt = event._measureTime || 0; const mt = event._measureTime || 0;
const originalEvent = event.data.originalEvent; const originalEvent = event.data.originalEvent;
if (Date.now() - mt > measurementInterval) { if (Date.now() - mt > measurementInterval) {
this.measure(destination, {snap: !disableSnap, pathfinding: game.keyboard.isDown("y")}); this.measure(destination, {snap: !disableSnap, pathfinding: game.settings.get(settingsKey, "autoPathfinding") != game.keyboard.isDown("y")});
event._measureTime = Date.now(); event._measureTime = Date.now();
this._state = Ruler.STATES.MEASURING; this._state = Ruler.STATES.MEASURING;
cancelScheduledMeasurement.call(this); cancelScheduledMeasurement.call(this);
+9
View File
@@ -82,6 +82,15 @@ export function registerSettings() {
default: true, default: true,
}); });
game.settings.register(settingsKey, "autoPathfinding", {
name: "drag-ruler.settings.autoPathfinding.name",
hint: "drag-ruler.settings.autoPathfinding.hint",
scpoe: "client",
config: true,
type: Boolean,
defualt: true,
});
game.settings.register(settingsKey, "lastTerrainRulerHintTime", { game.settings.register(settingsKey, "lastTerrainRulerHintTime", {
config: false, config: false,
type: Number, type: Number,