Make the size of Door Control icons consistent

This commit is contained in:
2020-12-08 12:20:28 +01:00
parent 2f12e06e3b
commit c20b9cdbeb
4 changed files with 63 additions and 1 deletions

52
main.js
View File

@@ -7,6 +7,7 @@ Hooks.once("init", () => {
registerSettings()
hookDoorEvents()
hookWallConfigUpdate()
hookDoorControlDraw()
})
Hooks.once("ready", () => {
@@ -37,6 +38,48 @@ Hooks.on("renderChatMessage", (message, html, data) => {
html.on("mouseleave", mouseLeave);
})
// Adjust the repositioning formula for the door controls
DoorControl.prototype.reposition = function () {
let gridSize = this.wall.scene.data.grid
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor")
const pos = this.wall.midpoint.map(p => p - gridSize * 0.2)
this.position.set(...pos)
}
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 the door control in relation to the grid size so it'll have a constant percieved size
function onDoorControlPostDraw() {
// If the canvas isn't ready we'll do this after the "canvasReady" event is fired instead
if (!canvas.ready)
return
fixDoorControlSize(this)
}
// Set the size of all door controls in relation to the grid size so it'll have a constant percieved size
Hooks.on("canvasReady", (currentCanvas, wall, update) => {
const doors = currentCanvas.controls.doors.children
doors.forEach(control => fixDoorControlSize(control))
})
// Resizes the door control according to the grid size
function fixDoorControlSize(control) {
let gridSize = control.wall.scene.data.grid
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor")
control.icon.width = control.icon.height = gridSize * 0.4
control.hitArea = new PIXI.Rectangle(gridSize * -0.02, gridSize * -0.02, gridSize * 0.44, gridSize * 0.44);
control.border.clear().lineStyle(1, 0xFF5500, 0.8).drawRoundedRect(gridSize * -0.02, gridSize * -0.02, gridSize * 0.44, gridSize * 0.44, gridSize * 0.05).endFill();
control.bg.clear().beginFill(0x000000, 1.0).drawRoundedRect(gridSize * -0.02, gridSize * -0.02, gridSize * 0.44, gridSize * 0.44, gridSize * 0.05).endFill();
}
const SECRET_DOOR_TINT = 0x222222
// Tint all secret doors dark grey
@@ -326,6 +369,15 @@ function registerSettings() {
type: String,
default: "fresh install"
})
game.settings.register(settingsKey, "doorControlSizeFactor", {
name: "smart-doors.settings.doorControlSizeFactor.name",
hint: "smart-doors.settings.doorControlSizeFactor.hint",
scope: "client",
config: true,
type: Number,
default: 1.5,
onChange: () => location.reload()
})
game.settings.register(settingsKey, "highlightSecretDoors", {
name: "smart-doors.settings.highlightSecretDoors.name",
hint: "smart-doors.settings.highlightSecretDoors.hint",