commit fd8248696b452babf996589fb1e3c8bb0edc0a6c Author: Manuel Vögele Date: Fri Dec 4 18:09:14 2020 +0100 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e376ef8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +end_of_line = lf +indent_style = tab +insert_final_newline = true \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c368173 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Smart Doors +Sends a message to chat when a player tries to open a locked door + +## Planned features +- Attach macros to doors that are being executed when the door is being opened/closed +- Synchronize the opening/closing of doors +- Give out keys to players, that allow them to lock/unlock associated doors diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..31b3c29 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,10 @@ +{ + "smart-doors": { + "settings": { + "lockedDoorAlert": { + "name": "Locked Door Alert", + "hint": "Send a message in chat when a player tried to open a locked door" + } + } + } +} diff --git a/main.js b/main.js new file mode 100644 index 0000000..8b20993 --- /dev/null +++ b/main.js @@ -0,0 +1,75 @@ +"use strict"; + +const settingsKey = "smart-doors"; + +Hooks.once("init", () => { + registerSettings() + hookDoorEvents() +}) + +Hooks.on("renderChatMessage", (message, html, data) => { + // Tint the door that generated this message + const sourceId = message.data.flags.smartdoors?.sourceId + if (!sourceId) + return + + // Tint on mouse enter + const mouseEnter = function () { + canvas.controls.doors.children.find(door => door.wall.data._id == sourceId).icon.tint = 0xff0000; + } + html.on("mouseenter", mouseEnter); + + // Remove tint on mouse leave + const mouseLeave = function () { + canvas.controls.doors.children.find(door => door.wall.data._id == sourceId).icon.tint = 0xffffff; + } + html.on("mouseleave", mouseLeave); +}) + +function hookDoorEvents() { + // Replace the original mousedown handler by our custom one + const originalMouseDownHandler = DoorControl.prototype._onMouseDown + DoorControl.prototype._onMouseDown = function (event) { + // Call our handler first. Only allow the original handler to run if our handler returns true + const continuePropagation = onDoorMousedown.call(this, event) + if (!continuePropagation) + return false + return originalMouseDownHandler.call(this, event) + } +} + + +function onDoorMousedown(event) { + // If the user doesn't have the "door" permission we don't do anything. + if (!game.user.can("WALL_DOORS")) + return true + // If the game is paused don't do anything if the current player isn't the gm + if ( game.paused && !game.user.isGM ) + return true + + // Create a chat message stating that a player tried to open a locked door + if (game.settings.get(settingsKey, "lockedDoorAlert")) { + if (this.wall.data.ds == CONST.WALL_DOOR_STATES.LOCKED && !game.user.isGM) { + const message = {} + message.user = game.user; + message.content = "Just tried to open a locked door" + message.sound = CONFIG.sounds.lock + message.flags = {smartdoors: {sourceId: this.wall.data._id}} + ChatMessage.create(message) + return false + } + } + + return true +} + +function registerSettings() { + game.settings.register(settingsKey, "lockedDoorAlert", { + name: "smart-doors.settings.lockedDoorAlert.name", + hint: "smart-doors.settings.lockedDoorAlert.hint", + scope: "world", + config: true, + type: Boolean, + default: true, + }) +} diff --git a/module.json b/module.json new file mode 100644 index 0000000..aeb2e27 --- /dev/null +++ b/module.json @@ -0,0 +1,19 @@ +{ + "name": "smart-doors", + "title": "Smart Doors", + "description": "Sends a message to chat when a player tries to open a locked door", + "version": "0.1.alpha0", + "minimumCoreVersion" : "0.7.7", + "compatibleCoreVersion" : "0.7.7", + "author": "Manuel Vögele", + "esmodules": [ + "./main.js" + ], + "languages": [ + { + "lang": "en", + "name": "English", + "path": "lang/en.json" + } + ] +}