Draw an outline around door control icons

This commit is contained in:
2020-12-14 10:05:15 +01:00
parent f67899500e
commit 82b495f4c3
8 changed files with 210 additions and 12 deletions

View File

@@ -10,15 +10,6 @@ export function hookDoorControlReposition() {
}
}
export function hookDoorControlDraw() {
const originalHandler = DoorControl.prototype.draw
DoorControl.prototype.draw = async function () {
const result = await originalHandler.call(this)
onDoorControlPostDraw.call(this)
return result
}
}
// Set the size of all door controls in relation to the grid size so it'll have a constant percieved size
export function onCanvasReady(currentCanvas) {
const doors = currentCanvas.controls.doors.children
@@ -26,7 +17,7 @@ export function onCanvasReady(currentCanvas) {
}
// Set the size of the door control in relation to the grid size so it'll have a constant percieved size
function onDoorControlPostDraw() {
export function onDoorControlPostDraw() {
// If the canvas isn't ready we'll do this after the "canvasReady" event is fired instead
if (!canvas.ready)
return

View File

@@ -0,0 +1,24 @@
import {settingsKey} from "../settings.js"
import {OutlineFilter} from "../../lib/outline_filter/outline_filter.js"
export function onDoorControlPostDraw() {
if (!game.settings.get(settingsKey, "doorControlOutline"))
return
const types = CONST.WALL_DOOR_TYPES
if (this.wall.data.door === types.NONE)
return
// Remove all OutlineFilters from current filters
let pixiFilters = this.icon.filters || []
pixiFilters = pixiFilters.filter(pixiFilter => !(pixiFilter instanceof OutlineFilter))
let outlineFilter;
if (this.wall.data.door === types.SECRET && game.settings.get(settingsKey, "highlightSecretDoors"))
outlineFilter = new OutlineFilter(1, 0xFFFFFF)
else
outlineFilter = new OutlineFilter(1, 0x000000)
pixiFilters.push(outlineFilter)
this.icon.filters = pixiFilters
}

View File

@@ -1,6 +1,7 @@
"use strict";
import * as DoorControlIconScale from "./features/door_control_icon_scale.js"
import * as DoorControlOutline from "./features/door_control_outline.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"
@@ -13,7 +14,7 @@ Hooks.once("init", () => {
registerSettings()
hookDoorEvents()
hookWallConfigUpdate()
DoorControlIconScale.hookDoorControlDraw()
hookDoorControlDraw()
DoorControlIconScale.hookDoorControlReposition()
})
@@ -24,7 +25,6 @@ Hooks.once("ready", () => {
Hooks.on("renderChatMessage", LockedDoorAlert.onRenderChatMessage)
Hooks.on("canvasReady", DoorControlIconScale.onCanvasReady)
Hooks.on("canvasReady", HighlightSecretDoors.onCanvasReady)
Hooks.on("updateWall", HighlightSecretDoors.onUpdateWall)
@@ -42,6 +42,16 @@ function hookWallConfigUpdate() {
}
}
function hookDoorControlDraw() {
const originalHandler = DoorControl.prototype.draw
DoorControl.prototype.draw = async function () {
const result = await originalHandler.call(this)
DoorControlIconScale.onDoorControlPostDraw.call(this)
DoorControlOutline.onDoorControlPostDraw.call(this)
return result
}
}
// Hook mouse events on DoorControls to perform our logic.
// If we successfully handled the event block the original handler. Forward the event otherwise.
function hookDoorEvents() {

View File

@@ -21,6 +21,15 @@ export function registerSettings() {
default: 1.5,
onChange: () => location.reload()
})
game.settings.register(settingsKey, "doorControlOutline", {
name: "smart-doors.settings.doorControlOutline.name",
hint: "smart-doors.settings.doorControlOutline.hint",
scope: "client",
config: true,
type: Boolean,
default: true,
onChange: () => location.reload(),
})
game.settings.register(settingsKey, "highlightSecretDoors", {
name: "smart-doors.settings.highlightSecretDoors.name",
hint: "smart-doors.settings.highlightSecretDoors.hint",