From a252da620a550e4e0d4c06c8256ea6c643c962d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 1 Feb 2022 11:33:33 +0100 Subject: [PATCH] Always allow the GM to use pathfinding --- lang/de.json | 4 ++-- lang/en.json | 4 ++-- src/keybindings.js | 17 ++++++++--------- src/pathfinding.js | 2 +- src/settings.js | 3 ++- src/util.js | 7 +++++++ 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lang/de.json b/lang/de.json index 424a33b..35f9557 100644 --- a/lang/de.json +++ b/lang/de.json @@ -48,8 +48,8 @@ }, "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." + "name": "Wegfindung für Spieler erlauben", + "hint": "Erlaubt es Spielern die Wegfindungs zu benutzen. 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", diff --git a/lang/en.json b/lang/en.json index fae78e3..afdab5d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -48,8 +48,8 @@ }, "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." + "name": "Allow pathfinding for players", + "hint": "Allows players to use 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", diff --git a/src/keybindings.js b/src/keybindings.js index cfa5b49..c2747e2 100644 --- a/src/keybindings.js +++ b/src/keybindings.js @@ -52,15 +52,14 @@ export function registerKeybindings() { 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, - }); - } + game.keybindings.register(settingsKey, "togglePathfinding", { + name: "drag-ruler.keybindings.togglePathfinding.name", + hint: "drag-ruler.keybindings.togglePathfinding.hint", + onDown: handleTogglePathfinding, + onUp: handleTogglePathfinding, + precedence: -1, + restricted: !game.settings.get(settingsKey, "allowPathfinding"), + }); } function handleDeleteWaypoint() { diff --git a/src/pathfinding.js b/src/pathfinding.js index 35e533f..507ae3f 100644 --- a/src/pathfinding.js +++ b/src/pathfinding.js @@ -10,7 +10,7 @@ let use5105 = false; export function isPathfindingEnabled() { if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) return false; - if (!game.settings.get(settingsKey, "allowPathfinding")) + if (!game.user.isGM && !game.settings.get(settingsKey, "allowPathfinding")) return false; return game.settings.get(settingsKey, "autoPathfinding") != togglePathfinding; } diff --git a/src/settings.js b/src/settings.js index 7ba23b2..51caa58 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1,5 +1,6 @@ import {availableSpeedProviders, currentSpeedProvider, getDefaultSpeedProvider, updateSpeedProvider} from "./api.js"; import {SpeedProvider} from "./speed_provider.js" +import { early_isGM } from "./util.js"; export const settingsKey = "drag-ruler"; @@ -96,7 +97,7 @@ export function registerSettings() { name: "drag-ruler.settings.autoPathfinding.name", hint: "drag-ruler.settings.autoPathfinding.hint", scpoe: "client", - config: true, + config: early_isGM(), type: Boolean, defualt: false, }); diff --git a/src/util.js b/src/util.js index f9bf828..ebcb2a0 100644 --- a/src/util.js +++ b/src/util.js @@ -272,3 +272,10 @@ export function getMeasurePosition() { const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y}; return measurePosition; } + +// isGM function for use during loading when game.user isn't available yet +export function early_isGM() { + const level = game.data.users.find(u => u._id == game.data.userId).role; + const gmLevel = CONST.USER_ROLES.ASSISTANT; + return level >= gmLevel; +}