Update for Foundry v10
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "smart-doors",
|
"id": "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.3.3",
|
"version": "1.3.3",
|
||||||
"minimumCoreVersion" : "9.238",
|
"compatibility": {
|
||||||
"compatibleCoreVersion" : "9",
|
"minimum": 10,
|
||||||
|
"verified": 10,
|
||||||
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Manuel Vögele",
|
"name": "Manuel Vögele",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export function hookDoorControlReposition() {
|
|||||||
"smart-doors",
|
"smart-doors",
|
||||||
"DoorControl.prototype.reposition",
|
"DoorControl.prototype.reposition",
|
||||||
function () {
|
function () {
|
||||||
let gridSize = this.wall.scene.data.grid;
|
let gridSize = this.wall.scene.grid.size;
|
||||||
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);
|
||||||
@@ -32,7 +32,7 @@ export function onDoorControlPostDraw() {
|
|||||||
|
|
||||||
// Resizes the door control according to the grid size
|
// Resizes the door control according to the grid size
|
||||||
function fixDoorControlSize(control) {
|
function fixDoorControlSize(control) {
|
||||||
let gridSize = control.wall.scene.data.grid;
|
let gridSize = control.wall.scene.grid.size;
|
||||||
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor");
|
gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor");
|
||||||
control.icon.width = control.icon.height = gridSize * 0.4;
|
control.icon.width = control.icon.height = gridSize * 0.4;
|
||||||
control.hitArea = new PIXI.Rectangle(
|
control.hitArea = new PIXI.Rectangle(
|
||||||
|
|||||||
@@ -7,27 +7,25 @@ export function onCanvasReady(currentCanvas) {
|
|||||||
if (game.settings.get(settingsKey, "highlightSecretDoors")) {
|
if (game.settings.get(settingsKey, "highlightSecretDoors")) {
|
||||||
const types = CONST.WALL_DOOR_TYPES;
|
const types = CONST.WALL_DOOR_TYPES;
|
||||||
const secretDoors = canvas.controls.doors.children.filter(
|
const secretDoors = canvas.controls.doors.children.filter(
|
||||||
control => control.wall.data.door == types.SECRET,
|
control => control.wall.door == types.SECRET,
|
||||||
);
|
);
|
||||||
secretDoors.forEach(control => (control.icon.tint = SECRET_DOOR_TINT));
|
secretDoors.forEach(control => (control.icon.tint = SECRET_DOOR_TINT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If door type has been changed, tint the door accordingly
|
// If door type has been changed, tint the door accordingly
|
||||||
export function onUpdateWall(scene, wall, update) {
|
export function onUpdateWall(wall, update, options) {
|
||||||
if (!game.settings.get(settingsKey, "highlightSecretDoors")) return;
|
if (!game.settings.get(settingsKey, "highlightSecretDoors")) return;
|
||||||
const types = CONST.WALL_DOOR_TYPES;
|
const types = CONST.WALL_DOOR_TYPES;
|
||||||
if (wall.door === types.NONE) return;
|
if (wall.door === types.NONE) return;
|
||||||
// Find the door control corresponding to the changed door
|
// Find the door control corresponding to the changed door
|
||||||
const changedDoor = canvas.controls.doors.children.find(
|
const changedDoor = canvas.controls.doors.children.find(control => control.wall.id === wall.id);
|
||||||
control => control.wall.data._id === wall._id,
|
|
||||||
);
|
|
||||||
// If the changed door doesn't have a control it's not on this scene - ignore it
|
// If the changed door doesn't have a control it's not on this scene - ignore it
|
||||||
if (!changedDoor) return;
|
if (!changedDoor) return;
|
||||||
// The wall object we got passed might be from another scene so we replace it with the door from the current scene
|
// The wall object we got passed might be from another scene so we replace it with the door from the current scene
|
||||||
wall = changedDoor.wall.data;
|
wall = changedDoor.wall;
|
||||||
if (wall.door === types.DOOR) changedDoor.icon.tint = 0xffffff;
|
if (wall.document.door === types.DOOR) changedDoor.icon.tint = 0xffffff;
|
||||||
else if (wall.door === types.SECRET) changedDoor.icon.tint = SECRET_DOOR_TINT;
|
else if (wall.document.door === types.SECRET) changedDoor.icon.tint = SECRET_DOOR_TINT;
|
||||||
else
|
else
|
||||||
console.warn(
|
console.warn(
|
||||||
"Smart Doors | Encountered unknown door type " +
|
"Smart Doors | Encountered unknown door type " +
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {settingsKey} from "../settings.js";
|
|||||||
// Tint the source door red when a locked alert is hovered
|
// Tint the source door red when a locked alert is hovered
|
||||||
export function onRenderChatMessage(message, html, data) {
|
export function onRenderChatMessage(message, html, data) {
|
||||||
// Tint the door that generated this message
|
// Tint the door that generated this message
|
||||||
const source = message.data.flags.smartdoors?.source;
|
const source = message.flags.smartdoors?.source;
|
||||||
if (!source) return;
|
if (!source) return;
|
||||||
|
|
||||||
// Tint on mouse enter
|
// Tint on mouse enter
|
||||||
@@ -33,7 +33,7 @@ export function onDoorLeftClick() {
|
|||||||
// Check if this feature is enabled
|
// Check if this feature is enabled
|
||||||
if (!game.settings.get(settingsKey, "lockedDoorAlert")) return false;
|
if (!game.settings.get(settingsKey, "lockedDoorAlert")) return false;
|
||||||
|
|
||||||
const state = this.wall.data.ds;
|
const state = this.wall.document.ds;
|
||||||
const states = CONST.WALL_DOOR_STATES;
|
const states = CONST.WALL_DOOR_STATES;
|
||||||
|
|
||||||
// Only create messages when the door is locked.
|
// Only create messages when the door is locked.
|
||||||
@@ -48,7 +48,7 @@ export function onDoorLeftClick() {
|
|||||||
if (game.user.character) message.speaker = {actor: game.user.character};
|
if (game.user.character) message.speaker = {actor: game.user.character};
|
||||||
message.content = game.i18n.localize("smart-doors.ui.lockedDoorAlert");
|
message.content = game.i18n.localize("smart-doors.ui.lockedDoorAlert");
|
||||||
message.sound = CONFIG.sounds.lock;
|
message.sound = CONFIG.sounds.lock;
|
||||||
message.flags = {smartdoors: {source: {wall: this.wall.data._id, scene: this.wall.scene.id}}};
|
message.flags = {smartdoors: {source: {wall: this.wall.id, scene: this.wall.scene.id}}};
|
||||||
ChatMessage.create(message);
|
ChatMessage.create(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as Util from "../util.js";
|
|||||||
|
|
||||||
// Inject settings for synchronized doors
|
// Inject settings for synchronized doors
|
||||||
export function onRederWallConfig(wallConfig, html, data) {
|
export function onRederWallConfig(wallConfig, html, data) {
|
||||||
if (game.settings.get(settingsKey, "synchronizedDoors") && data.isDoor) {
|
if (game.settings.get(settingsKey, "synchronizedDoors") && data.data.door) {
|
||||||
// Inject settings
|
// Inject settings
|
||||||
const synchronizedSettings = `
|
const synchronizedSettings = `
|
||||||
<p class="notes">${game.i18n.localize("smart-doors.ui.synchronizedDoors.description")}</p>
|
<p class="notes">${game.i18n.localize("smart-doors.ui.synchronizedDoors.description")}</p>
|
||||||
@@ -50,9 +50,9 @@ export async function onWallConfigUpdate(event, formData) {
|
|||||||
// Search for other doors in the synchronization group that aren't in the list of edited doors
|
// Search for other doors in the synchronization group that aren't in the list of edited doors
|
||||||
const doorInGroup = Util.findInAllWalls(wall => {
|
const doorInGroup = Util.findInAllWalls(wall => {
|
||||||
// We only search for doors
|
// We only search for doors
|
||||||
if (!wall.data.door) return false;
|
if (!wall.door) return false;
|
||||||
// We only want doors in the same synchronization group
|
// We only want doors in the same synchronization group
|
||||||
if (wall.data.flags.smartdoors?.synchronizationGroup !== formData.synchronizationGroup)
|
if (wall.flags.smartdoors?.synchronizationGroup !== formData.synchronizationGroup)
|
||||||
return false;
|
return false;
|
||||||
// Doors on this scene that have their id included in `ids` are currently being changed. Ignore them.
|
// Doors on this scene that have their id included in `ids` are currently being changed. Ignore them.
|
||||||
if (wall.parent.id === canvas.scene.id && ids.includes(wall.id)) return false;
|
if (wall.parent.id === canvas.scene.id && ids.includes(wall.id)) return false;
|
||||||
@@ -60,11 +60,11 @@ export async function onWallConfigUpdate(event, formData) {
|
|||||||
});
|
});
|
||||||
if (doorInGroup) {
|
if (doorInGroup) {
|
||||||
// ds is the door sate in foundry
|
// ds is the door sate in foundry
|
||||||
updateData.ds = doorInGroup.data.ds;
|
updateData.ds = doorInGroup.ds;
|
||||||
|
|
||||||
if (synchronizeSecretStatus) {
|
if (synchronizeSecretStatus) {
|
||||||
// door is the door type in foundry
|
// door is the door type in foundry
|
||||||
updateData.door = doorInGroup.data.door;
|
updateData.door = doorInGroup.door;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,13 +84,13 @@ export async function onWallConfigUpdate(event, formData) {
|
|||||||
|
|
||||||
// Update the state of all synchronized doors
|
// Update the state of all synchronized doors
|
||||||
export function onDoorLeftClick() {
|
export function onDoorLeftClick() {
|
||||||
const state = this.wall.data.ds;
|
const state = this.wall.document.ds;
|
||||||
const states = CONST.WALL_DOOR_STATES;
|
const states = CONST.WALL_DOOR_STATES;
|
||||||
|
|
||||||
// Check if this feature is enabled
|
// Check if this feature is enabled
|
||||||
if (!game.settings.get(settingsKey, "synchronizedDoors")) return false;
|
if (!game.settings.get(settingsKey, "synchronizedDoors")) return false;
|
||||||
|
|
||||||
const synchronizationGroup = this.wall.data.flags.smartdoors?.synchronizationGroup;
|
const synchronizationGroup = this.wall.document.flags.smartdoors?.synchronizationGroup;
|
||||||
|
|
||||||
// Does this door have a synchronization group? If not there is nothing to do
|
// Does this door have a synchronization group? If not there is nothing to do
|
||||||
if (!synchronizationGroup) return false;
|
if (!synchronizationGroup) return false;
|
||||||
@@ -109,13 +109,13 @@ export function onDoorLeftClick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function onDoorRightClick() {
|
export function onDoorRightClick() {
|
||||||
const state = this.wall.data.ds;
|
const state = this.wall.document.ds;
|
||||||
const states = CONST.WALL_DOOR_STATES;
|
const states = CONST.WALL_DOOR_STATES;
|
||||||
|
|
||||||
// Check if this feature is enabled
|
// Check if this feature is enabled
|
||||||
if (!game.settings.get(settingsKey, "synchronizedDoors")) return false;
|
if (!game.settings.get(settingsKey, "synchronizedDoors")) return false;
|
||||||
|
|
||||||
const synchronizationGroup = this.wall.data.flags.smartdoors?.synchronizationGroup;
|
const synchronizationGroup = this.wall.document.flags.smartdoors?.synchronizationGroup;
|
||||||
|
|
||||||
// Does this door have a synchronization group? If not there is nothing to do
|
// Does this door have a synchronization group? If not there is nothing to do
|
||||||
if (!synchronizationGroup) return false;
|
if (!synchronizationGroup) return false;
|
||||||
@@ -140,8 +140,7 @@ export function onDoorRightClick() {
|
|||||||
export function updateSynchronizedDoors(updateData, synchronizationGroup) {
|
export function updateSynchronizedDoors(updateData, synchronizationGroup) {
|
||||||
// Search for doors belonging to the synchronization group in all scenes
|
// Search for doors belonging to the synchronization group in all scenes
|
||||||
let scenes = Util.filterAllWalls(
|
let scenes = Util.filterAllWalls(
|
||||||
wall =>
|
wall => wall.door && wall.flags.smartdoors?.synchronizationGroup === synchronizationGroup,
|
||||||
wall.data.door && wall.data.flags.smartdoors?.synchronizationGroup === synchronizationGroup,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update all doors in the synchronization group
|
// Update all doors in the synchronization group
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ export function onDoorLeftClick() {
|
|||||||
// We don't trust the event to be filled with the expected data for compatibilty with arms reach (which passes a broken event)
|
// We don't trust the event to be filled with the expected data for compatibilty with arms reach (which passes a broken event)
|
||||||
if (toggleSecretDoor && game.user.isGM) {
|
if (toggleSecretDoor && game.user.isGM) {
|
||||||
const types = CONST.WALL_DOOR_TYPES;
|
const types = CONST.WALL_DOOR_TYPES;
|
||||||
const newtype = this.wall.data.door === types.DOOR ? types.SECRET : types.DOOR;
|
const newtype = this.wall.document.door === types.DOOR ? types.SECRET : types.DOOR;
|
||||||
const updateData = {door: newtype};
|
const updateData = {door: newtype};
|
||||||
const synchronizationGroup = this.wall.data.flags.smartdoors?.synchronizationGroup;
|
const synchronizationGroup = this.wall.document.flags.smartdoors?.synchronizationGroup;
|
||||||
if (
|
if (
|
||||||
game.settings.get(settingsKey, "synchronizedDoors") &&
|
game.settings.get(settingsKey, "synchronizedDoors") &&
|
||||||
synchronizationGroup &&
|
synchronizationGroup &&
|
||||||
this.wall.data.flags.smartdoors?.synchronizeSecretStatus
|
this.wall.document.flags.smartdoors?.synchronizeSecretStatus
|
||||||
)
|
)
|
||||||
updateSynchronizedDoors(updateData, synchronizationGroup);
|
updateSynchronizedDoors(updateData, synchronizationGroup);
|
||||||
else this.wall.document.update(updateData);
|
else this.wall.document.update(updateData);
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export function performMigrations() {
|
|||||||
|
|
||||||
// Make a dictionary that maps all door ids to their scenes
|
// Make a dictionary that maps all door ids to their scenes
|
||||||
const walls = game.scenes.reduce((dict, scene) => {
|
const walls = game.scenes.reduce((dict, scene) => {
|
||||||
scene.data.walls.forEach(wall => {
|
scene.walls.forEach(wall => {
|
||||||
if (!wall.data.door) return;
|
if (!wall.door) return;
|
||||||
dict[wall.id] = scene.id;
|
dict[wall.id] = scene.id;
|
||||||
});
|
});
|
||||||
return dict;
|
return dict;
|
||||||
@@ -28,14 +28,14 @@ export function performMigrations() {
|
|||||||
|
|
||||||
// Migrate all messages that have a (wall) source id
|
// Migrate all messages that have a (wall) source id
|
||||||
game.messages.forEach(async message => {
|
game.messages.forEach(async message => {
|
||||||
const wallId = message.data.flags.smartdoors?.sourceId;
|
const wallId = message.flags.smartdoors?.sourceId;
|
||||||
if (!wallId) return;
|
if (!wallId) return;
|
||||||
const flags = message.data.flags;
|
const flags = message.flags;
|
||||||
delete flags.smartdoors.sourceId;
|
delete flags.smartdoors.sourceId;
|
||||||
const scene = walls[wallId];
|
const scene = walls[wallId];
|
||||||
// If there is no wall with this id anymore we can drop the value. It has no purpose anymore
|
// If there is no wall with this id anymore we can drop the value. It has no purpose anymore
|
||||||
if (!scene) {
|
if (!scene) {
|
||||||
if (!message.data.flags.smartdoors) delete flags.smartdoors;
|
if (!message.flags.smartdoors) delete flags.smartdoors;
|
||||||
} else {
|
} else {
|
||||||
// Assign the id and the scene id to the new data structure
|
// Assign the id and the scene id to the new data structure
|
||||||
flags.smartdoors.source = {wall: wallId, scene: scene};
|
flags.smartdoors.source = {wall: wallId, scene: scene};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
export function filterAllWalls(filterFn) {
|
export function filterAllWalls(filterFn) {
|
||||||
// Find all walls that match the filter criteria
|
// Find all walls that match the filter criteria
|
||||||
const scenes = game.scenes.map(scene => {
|
const scenes = game.scenes.map(scene => {
|
||||||
return {scene: scene, walls: scene.data.walls.filter(filterFn)};
|
return {scene: scene, walls: scene.walls.filter(filterFn)};
|
||||||
});
|
});
|
||||||
// Drop all scenes that don't contain any results
|
// Drop all scenes that don't contain any results
|
||||||
return scenes.filter(scene => scene.walls.length > 0);
|
return scenes.filter(scene => scene.walls.length > 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user