From 2ce7e57f43816bba1589248004fcbd52b5ef4e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 20 Jul 2021 11:03:03 +0200 Subject: [PATCH] Bring back the "tint secret doors" feature (resolves #7) This partially reverts commit 42529d3df66029667011b5200289a22acdcb24df. --- README.md | 10 +++----- lang/en.json | 4 +++ src/features/highlight_secret_doors.js | 34 ++++++++++++++++++++++++++ src/main.js | 4 +++ src/settings.js | 14 +++++++++++ 5 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/features/highlight_secret_doors.js diff --git a/README.md b/README.md index 1803887..99a3e53 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,6 @@ Makes doors smarter. Allows doors to synchronize across multiple scenes and send Door Control icons will be rendered the same size in every scene, regardless of the configured grid size. The size of the icons is configurable. -### Tint Secret Doors -![Tint Secret Doors demonstration](https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/dc5d328cd9bc4a0e2aacc5c86ab59e15739cc6d1/media/tint_secret_doors.webp) - -Which where the secret doors again? This tints all secret doors grey in the GM view, allowing to easily differentiate between normal and secret doors. - - ### Toggle Secret Doors ![Toggle Secret Doors demonstration](https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/da5872042ea81e2f41875a193d161331a81a2b6d/media/secret_door_toggle.webp) @@ -29,6 +23,10 @@ Keep everyone informed who tried to open which door. Whenever a player tries to If the GM tries to open a locked door the sound will only played for him and no chat message will be sent. +### Tint Secret Doors +This tints secret doors in a gay shade to make them easier to discern from regular doors when being zoomed further out. + + ### Synchronized Doors ![Synchronized Doors demonstration](https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/360d724240634dbc6cc493a3b62243a8b28b7056/media/synchronized_doors.webp) diff --git a/lang/en.json b/lang/en.json index d81d4f8..caf2437 100644 --- a/lang/en.json +++ b/lang/en.json @@ -5,6 +5,10 @@ "name": "Door Control Size Factor", "hint": "Defines by which factor the size of the door control icons should be scaled up" }, + "highlightSecretDoors": { + "name": "Tint Secret Doors", + "hint": "Shade secret doors in a different color on the gm screen to differentiate them from normal doors" + }, "lockedDoorAlert": { "name": "Locked Door Alert", "hint": "Send a message in chat when a player tried to open a locked door" diff --git a/src/features/highlight_secret_doors.js b/src/features/highlight_secret_doors.js new file mode 100644 index 0000000..f293106 --- /dev/null +++ b/src/features/highlight_secret_doors.js @@ -0,0 +1,34 @@ +import {settingsKey} from "../settings.js" + +const SECRET_DOOR_TINT = 0x888888 + +// Tint all secret doors dark grey +export function onCanvasReady(currentCanvas) { + if (game.settings.get(settingsKey, "highlightSecretDoors")) { + const types = CONST.WALL_DOOR_TYPES + const secretDoors = canvas.controls.doors.children.filter(control => control.wall.data.door == types.SECRET) + secretDoors.forEach(control => control.icon.tint = SECRET_DOOR_TINT) + } +} + +// If door type has been changed, tint the door accordingly +export function onUpdateWall(scene, wall, update) { + if (!game.settings.get(settingsKey, "highlightSecretDoors")) + return + const types = CONST.WALL_DOOR_TYPES + if (wall.door === types.NONE) + return + // Find the door control corresponding to the changed door + const changedDoor = canvas.controls.doors.children.find(control => control.wall.data._id === wall._id); + // If the changed door doesn't have a control it's not on this scene - ignore it + if (!changedDoor) + return + // The wall object we got passed might be from another scene so we replace it with the door from the current scene + wall = changedDoor.wall.data + if (wall.door === types.DOOR) + changedDoor.icon.tint = 0xFFFFFF + else if (wall.door === types.SECRET) + changedDoor.icon.tint = SECRET_DOOR_TINT + else + console.warn("Smart Doors | Encountered unknown door type " + wall.door + " while highlighting secret doors.") +} diff --git a/src/main.js b/src/main.js index d4b7f2b..17b40b4 100644 --- a/src/main.js +++ b/src/main.js @@ -2,6 +2,7 @@ import {libWrapper} from "../lib/libwrapper_shim.js"; import * as DoorControlIconScale from "./features/door_control_icon_scale.js" +import * as HighlightSecretDoors from "./features/highlight_secret_doors.js" import * as LockedDoorAlert from "./features/locked_door_alert.js" import * as SynchronizedDoors from "./features/synchronized_doors.js" import * as ToggleSecretDoor from "./features/toggle_secret_door.js" @@ -24,6 +25,9 @@ Hooks.once("ready", () => { Hooks.on("renderChatMessage", LockedDoorAlert.onRenderChatMessage) Hooks.on("canvasReady", DoorControlIconScale.onCanvasReady) +Hooks.on("canvasReady", HighlightSecretDoors.onCanvasReady) + +Hooks.on("updateWall", HighlightSecretDoors.onUpdateWall) // Inject our custom settings into the WallConfig dialog Hooks.on("renderWallConfig", SynchronizedDoors.onRederWallConfig) diff --git a/src/settings.js b/src/settings.js index f38d6db..c657e62 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1,5 +1,10 @@ export const settingsKey = "smart-doors"; +function reloadGM() { + if (game.user.isGM) + location.reload() +} + export function registerSettings() { game.settings.register(settingsKey, "dataVersion", { scope: "world", @@ -16,6 +21,15 @@ export function registerSettings() { default: 1.5, onChange: () => location.reload() }) + game.settings.register(settingsKey, "highlightSecretDoors", { + name: "smart-doors.settings.highlightSecretDoors.name", + hint: "smart-doors.settings.highlightSecretDoors.hint", + scope: "world", + config: true, + type: Boolean, + default: false, + onChange: reloadGM, + }) game.settings.register(settingsKey, "toggleSecretDoors", { name: "smart-doors.settings.toggleSecretDoors.name", hint: "smart-doors.settings.toggleSecretDoors.hint",