Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 01857f6ef4 | |||
| 1215ddf55a |
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.2.6
|
||||||
|
### Compatibility
|
||||||
|
- Smart Doors now uses the libwrapper module and as a result is now compatible with the module "FoundryVTT Arms Reach"
|
||||||
|
|
||||||
## 1.2.5
|
## 1.2.5
|
||||||
### New features
|
### New features
|
||||||
- Synchronized doors can now be configured to synchronize their secret door status as well
|
- Synchronized doors can now be configured to synchronize their secret door status as well
|
||||||
|
|||||||
61
lib/libwrapper_shim.js
Normal file
61
lib/libwrapper_shim.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright © 2021 fvtt-lib-wrapper Rui Pinheiro
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// A shim for the libWrapper library
|
||||||
|
export let libWrapper = undefined;
|
||||||
|
|
||||||
|
Hooks.once('init', () => {
|
||||||
|
// Check if the real module is already loaded - if so, use it
|
||||||
|
if(globalThis.libWrapper && !(globalThis.libWrapper.is_fallback ?? true)) {
|
||||||
|
libWrapper = globalThis.libWrapper;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback implementation
|
||||||
|
libWrapper = class {
|
||||||
|
static get is_fallback() { return true };
|
||||||
|
|
||||||
|
static register(module, target, fn, type="MIXED", {chain=undefined}={}) {
|
||||||
|
const is_setter = target.endsWith('#set');
|
||||||
|
target = !is_setter ? target : target.slice(0, -4);
|
||||||
|
const split = target.split('.');
|
||||||
|
const fn_name = split.pop();
|
||||||
|
const root_nm = split.splice(0,1)[0];
|
||||||
|
const _eval = eval; // The browser doesn't expose all global variables (e.g. 'Game') inside globalThis, but it does to an eval. We copy it to a variable to have it run in global scope.
|
||||||
|
const obj = split.reduce((x,y)=>x[y], globalThis[root_nm] ?? _eval(root_nm));
|
||||||
|
|
||||||
|
let iObj = obj;
|
||||||
|
let descriptor = null;
|
||||||
|
while(iObj) {
|
||||||
|
descriptor = Object.getOwnPropertyDescriptor(iObj, fn_name);
|
||||||
|
if(descriptor) break;
|
||||||
|
iObj = Object.getPrototypeOf(iObj);
|
||||||
|
}
|
||||||
|
if(!descriptor || descriptor?.configurable === false) throw `libWrapper Shim: '${target}' does not exist, could not be found, or has a non-configurable descriptor.`;
|
||||||
|
|
||||||
|
let original = null;
|
||||||
|
const wrapper = (chain ?? type != 'OVERRIDE') ? function() { return fn.call(this, original.bind(this), ...arguments); } : function() { return fn.apply(this, arguments); };
|
||||||
|
|
||||||
|
if(!is_setter) {
|
||||||
|
if(descriptor.value) {
|
||||||
|
original = descriptor.value;
|
||||||
|
descriptor.value = wrapper;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
original = descriptor.get;
|
||||||
|
descriptor.get = wrapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(!descriptor.set) throw `libWrapper Shim: '${target}' does not have a setter`;
|
||||||
|
original = descriptor.set;
|
||||||
|
descriptor.set = wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptor.configurable = true;
|
||||||
|
Object.defineProperty(obj, fn_name, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "smart-doors",
|
"name": "smart-doors",
|
||||||
"title": "Smart Doors",
|
"title": "Smart Doors",
|
||||||
"description": "Makes doors smarter. Allows doors to synchronize across multiple scenes and sends chat messages when players try to open locked doors.",
|
"description": "Makes doors smarter. Allows doors to synchronize across multiple scenes and sends chat messages when players try to open locked doors.",
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"minimumCoreVersion" : "0.7.7",
|
"minimumCoreVersion" : "0.7.7",
|
||||||
"compatibleCoreVersion" : "0.7.9",
|
"compatibleCoreVersion" : "0.7.9",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"esmodules": [
|
"esmodules": [
|
||||||
|
"lib/libwrapper_shim.js",
|
||||||
"src/main.js"
|
"src/main.js"
|
||||||
],
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
@@ -24,7 +25,7 @@
|
|||||||
],
|
],
|
||||||
"url": "https://github.com/manuelVo/foundryvtt-smart-doors",
|
"url": "https://github.com/manuelVo/foundryvtt-smart-doors",
|
||||||
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/master/module.json",
|
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/master/module.json",
|
||||||
"download": "https://github.com/manuelVo/foundryvtt-smart-doors/archive/v1.2.5.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-smart-doors/archive/v1.2.6.zip",
|
||||||
"readme": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/README.md",
|
"readme": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/README.md",
|
||||||
"changelog": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/CHANGELOG.md",
|
"changelog": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/CHANGELOG.md",
|
||||||
"bugs": "https://github.com/manuelVo/foundryvtt-smart-doors/issues"
|
"bugs": "https://github.com/manuelVo/foundryvtt-smart-doors/issues"
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
import { libWrapper } from "../../lib/libwrapper_shim.js"
|
||||||
import {settingsKey} from "../settings.js"
|
import {settingsKey} from "../settings.js"
|
||||||
|
|
||||||
// Adjust the repositioning formula for the door controls
|
// Adjust the repositioning formula for the door controls
|
||||||
export function hookDoorControlReposition() {
|
export function hookDoorControlReposition() {
|
||||||
DoorControl.prototype.reposition = function () {
|
libWrapper.register("smart-doors", "DoorControl.prototype.reposition", function () {
|
||||||
let gridSize = this.wall.scene.data.grid
|
let gridSize = this.wall.scene.data.grid
|
||||||
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor")
|
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor")
|
||||||
const pos = this.wall.midpoint.map(p => p - gridSize * 0.2)
|
const pos = this.wall.midpoint.map(p => p - gridSize * 0.2)
|
||||||
this.position.set(...pos)
|
this.position.set(...pos)
|
||||||
}
|
}, "OVERRIDE");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the size of all door controls in relation to the grid size so it'll have a constant percieved size
|
// Set the size of all door controls in relation to the grid size so it'll have a constant percieved size
|
||||||
|
|||||||
31
src/main.js
31
src/main.js
@@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import {libWrapper} from "../lib/libwrapper_shim.js";
|
||||||
import * as DoorControlIconScale from "./features/door_control_icon_scale.js"
|
import * as DoorControlIconScale from "./features/door_control_icon_scale.js"
|
||||||
import * as DoorControlOutline from "./features/door_control_outline.js"
|
import * as DoorControlOutline from "./features/door_control_outline.js"
|
||||||
import * as HighlightSecretDoors from "./features/highlight_secret_doors.js"
|
import * as HighlightSecretDoors from "./features/highlight_secret_doors.js"
|
||||||
@@ -35,45 +36,41 @@ Hooks.on("renderWallConfig", SynchronizedDoors.onRederWallConfig)
|
|||||||
// Hook the update function of the WallConfig dialog so we can store our custom data
|
// Hook the update function of the WallConfig dialog so we can store our custom data
|
||||||
function hookWallConfigUpdate() {
|
function hookWallConfigUpdate() {
|
||||||
// Replace the original function with our custom one
|
// Replace the original function with our custom one
|
||||||
const originalHandler = WallConfig.prototype._updateObject;
|
libWrapper.register("smart-doors", "WallConfig.prototype._updateObject", async function (wrapped, event, formData) {
|
||||||
WallConfig.prototype._updateObject = async function (event, formData) {
|
await wrapped(event, formData);
|
||||||
await originalHandler.call(this, event, formData)
|
|
||||||
return SynchronizedDoors.onWallConfigUpdate.call(this, event, formData)
|
return SynchronizedDoors.onWallConfigUpdate.call(this, event, formData)
|
||||||
}
|
}, "WRAPPER");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hookDoorControlDraw() {
|
function hookDoorControlDraw() {
|
||||||
const originalHandler = DoorControl.prototype.draw
|
libWrapper.register("smart-doors", "DoorControl.prototype.draw", async function (wrapped) {
|
||||||
DoorControl.prototype.draw = async function () {
|
const result = await wrapped();
|
||||||
const result = await originalHandler.call(this)
|
|
||||||
DoorControlIconScale.onDoorControlPostDraw.call(this)
|
DoorControlIconScale.onDoorControlPostDraw.call(this)
|
||||||
DoorControlOutline.onDoorControlPostDraw.call(this)
|
DoorControlOutline.onDoorControlPostDraw.call(this)
|
||||||
return result
|
return result;
|
||||||
}
|
}, "WRAPPER");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook mouse events on DoorControls to perform our logic.
|
// Hook mouse events on DoorControls to perform our logic.
|
||||||
// If we successfully handled the event block the original handler. Forward the event otherwise.
|
// If we successfully handled the event block the original handler. Forward the event otherwise.
|
||||||
function hookDoorEvents() {
|
function hookDoorEvents() {
|
||||||
// Replace the original mousedown handler with our custom one
|
// Replace the original mousedown handler with our custom one
|
||||||
const originalMouseDownHandler = DoorControl.prototype._onMouseDown
|
libWrapper.register("smart-doors", "DoorControl.prototype._onMouseDown", function (wrapped, event) {
|
||||||
DoorControl.prototype._onMouseDown = function (event) {
|
|
||||||
// Call our handler first. Only allow the original handler to run if our handler returns true
|
// Call our handler first. Only allow the original handler to run if our handler returns true
|
||||||
const eventHandled = onDoorMouseDown.call(this, event)
|
const eventHandled = onDoorMouseDown.call(this, event)
|
||||||
if (eventHandled)
|
if (eventHandled)
|
||||||
return
|
return
|
||||||
return originalMouseDownHandler.call(this, event)
|
return wrapped(event);
|
||||||
}
|
}, "MIXED");
|
||||||
|
|
||||||
// Replace the original rightdown handler with our custom one
|
// Replace the original rightdown handler with our custom one
|
||||||
const originalRightDownHandler = DoorControl.prototype._onRightDown
|
libWrapper.register("smart-doors", "DoorControl.prototype._onRightDown", function (wrapped, event) {
|
||||||
DoorControl.prototype._onRightDown = function (event) {
|
|
||||||
// Call our handler first. Only allow the original handler to run if our handler returns true
|
// Call our handler first. Only allow the original handler to run if our handler returns true
|
||||||
const eventHandled = onDoorRightDown.call(this, event)
|
const eventHandled = onDoorRightDown.call(this, event)
|
||||||
if (eventHandled)
|
if (eventHandled)
|
||||||
return
|
return
|
||||||
return originalRightDownHandler.call(this, event)
|
return wrapped(event);
|
||||||
}
|
}, "MIXED");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our custom handler for mousedown events on doors
|
// Our custom handler for mousedown events on doors
|
||||||
|
|||||||
Reference in New Issue
Block a user