Initial commit
This commit is contained in:
6
.editorconfig
Normal file
6
.editorconfig
Normal file
@@ -0,0 +1,6 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
insert_final_newline = true
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -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
|
||||
10
lang/en.json
Normal file
10
lang/en.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
main.js
Normal file
75
main.js
Normal file
@@ -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,
|
||||
})
|
||||
}
|
||||
19
module.json
Normal file
19
module.json
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user