From 9140ef3acf440eb7c7733df2a077869709e04c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 27 Jan 2022 23:29:08 +0100 Subject: [PATCH] Add setting to forbid the usage of pathfinding --- lang/de.json | 4 ++++ lang/en.json | 4 ++++ src/foundry_imports.js | 4 ++-- src/pathfinding.js | 7 +++++++ src/settings.js | 9 +++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lang/de.json b/lang/de.json index f394d00..c7080f7 100644 --- a/lang/de.json +++ b/lang/de.json @@ -43,6 +43,10 @@ } }, "settings": { + "allowPathfinding": { + "name": "Wegfindung aktivieren", + "hint": "Aktiviert Drag Ruler's Wegfindungsfunktion. Bitte beachte, dass die Wegfindung Wege durch unerkundeten Nebel des Kriegs und Ätherische Wände berechnen kann. Dies kann deinen Spielern Geheimnisse lüften, von denen sie noch nicht erfahren sollten." + }, "alwaysShowSpeedForPCs": { "name": "Geschwindigkeit von Spielercharakteren für jeden anzeigen", "hint": "Wenn diese Einstellung aktiviert ist wird die Färbung der hervorgehobenen Felder bei Spielercharakteren allen Spielern angezeigt, selbst wenn diese keinen Zugriff auf den Charakterbogen haben." diff --git a/lang/en.json b/lang/en.json index b75960f..ef7e66a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -43,6 +43,10 @@ } }, "settings": { + "allowPathfinding": { + "name": "Enable pathfinding feature", + "hint": "Enables Drag Ruler's pathfinding functionality in this world. Be aware that pathfinding can route through unexplored fog of war and Ethereal Walls, which might reveal secrets to your players ahead of time." + }, "alwaysShowSpeedForPCs": { "name": "Show PC speed to everyone", "hint": "If enabled the coloring based on actor speed for player characters will shown to everyone, even if they don't have observer permission for the character sheet." diff --git a/src/foundry_imports.js b/src/foundry_imports.js index 4fef1ec..a638214 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -3,7 +3,7 @@ import {getCenterFromGridPositionObj, getGridPositionFromPixels, getGridPosition import {Line} from "./geometry.js"; import {disableSnap, moveWithoutAnimation} from "./keybindings.js"; import {trackRays} from "./movement_tracking.js" -import {find_path} from "./pathfinding.js"; +import {find_path, is_pathfinding_enabled} from "./pathfinding.js"; import {settingsKey} from "./settings.js"; import {recalculate} from "./socket.js"; import {applyTokenSizeOffset, enumeratedZip, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, sum} from "./util.js"; @@ -133,7 +133,7 @@ function scheduleMeasurement(destination, event) { const mt = event._measureTime || 0; const originalEvent = event.data.originalEvent; if (Date.now() - mt > measurementInterval) { - this.measure(destination, {snap: !disableSnap, pathfinding: game.settings.get(settingsKey, "autoPathfinding") != game.keyboard.isDown("y")}); + this.measure(destination, {snap: !disableSnap, pathfinding: is_pathfinding_enabled()}); event._measureTime = Date.now(); this._state = Ruler.STATES.MEASURING; cancelScheduledMeasurement.call(this); diff --git a/src/pathfinding.js b/src/pathfinding.js index f7dd58b..f885c56 100644 --- a/src/pathfinding.js +++ b/src/pathfinding.js @@ -1,8 +1,15 @@ import {getCenterFromGridPositionObj} from "./foundry_fixes.js"; +import {settingsKey} from "./settings.js"; // TODO Wipe cache if walls layer is being modified let cached_nodes = undefined; +export function is_pathfinding_enabled() { + if (!game.settings.get(settingsKey, "allowPathfinding")) + return false; + return game.settings.get(settingsKey, "autoPathfinding") != game.keyboard.isDown("y") +} + function get_node(pos, initialize=true) { if (!cached_nodes) // TODO Check if ceil is the right thing to do here diff --git a/src/settings.js b/src/settings.js index 90d9941..11edfb9 100644 --- a/src/settings.js +++ b/src/settings.js @@ -82,6 +82,15 @@ export function registerSettings() { default: true, }); + game.settings.register(settingsKey, "allowPathfinding", { + name: "drag-ruler.settings.allowPathfinding.name", + hint: "drag-ruler.settings.allowPathfinding.hint", + scope: "world", + config: true, + type: Boolean, + default: false, + }); + game.settings.register(settingsKey, "autoPathfinding", { name: "drag-ruler.settings.autoPathfinding.name", hint: "drag-ruler.settings.autoPathfinding.hint",