From e53a1b6a216511257cb0decdc80d713eb1389394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Sat, 15 Oct 2022 22:29:25 +0200 Subject: [PATCH] Update for Foundry v10 --- module.json | 8 +++++--- src/features/door_control_icon_scale.js | 4 ++-- src/features/highlight_secret_doors.js | 14 ++++++-------- src/features/locked_door_alert.js | 6 +++--- src/features/synchronized_doors.js | 21 ++++++++++----------- src/features/toggle_secret_door.js | 6 +++--- src/migration.js | 10 +++++----- src/util.js | 2 +- 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/module.json b/module.json index 54802ea..0afa889 100644 --- a/module.json +++ b/module.json @@ -1,10 +1,12 @@ { - "name": "smart-doors", + "id": "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.", "version": "1.3.3", - "minimumCoreVersion" : "9.238", - "compatibleCoreVersion" : "9", + "compatibility": { + "minimum": 10, + "verified": 10, + }, "authors": [ { "name": "Manuel Vögele", diff --git a/src/features/door_control_icon_scale.js b/src/features/door_control_icon_scale.js index 42aa3d9..5dc4f37 100644 --- a/src/features/door_control_icon_scale.js +++ b/src/features/door_control_icon_scale.js @@ -7,7 +7,7 @@ export function hookDoorControlReposition() { "smart-doors", "DoorControl.prototype.reposition", function () { - let gridSize = this.wall.scene.data.grid; + let gridSize = this.wall.scene.grid.size; gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor"); const pos = this.wall.midpoint.map(p => p - gridSize * 0.2); this.position.set(...pos); @@ -32,7 +32,7 @@ export function onDoorControlPostDraw() { // Resizes the door control according to the grid size function fixDoorControlSize(control) { - let gridSize = control.wall.scene.data.grid; + let gridSize = control.wall.scene.grid.size; gridSize *= game.settings.get(settingsKey, "doorControlSizeFactor"); control.icon.width = control.icon.height = gridSize * 0.4; control.hitArea = new PIXI.Rectangle( diff --git a/src/features/highlight_secret_doors.js b/src/features/highlight_secret_doors.js index 41393bb..3953a60 100644 --- a/src/features/highlight_secret_doors.js +++ b/src/features/highlight_secret_doors.js @@ -7,27 +7,25 @@ export function onCanvasReady(currentCanvas) { if (game.settings.get(settingsKey, "highlightSecretDoors")) { const types = CONST.WALL_DOOR_TYPES; 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)); } } // 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; const types = CONST.WALL_DOOR_TYPES; if (wall.door === types.NONE) return; // Find the door control corresponding to the changed door - const changedDoor = canvas.controls.doors.children.find( - control => control.wall.data._id === wall._id, - ); + const changedDoor = canvas.controls.doors.children.find(control => control.wall.id === wall.id); // If the changed door doesn't have a control it's not on this scene - ignore it 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 - wall = changedDoor.wall.data; - if (wall.door === types.DOOR) changedDoor.icon.tint = 0xffffff; - else if (wall.door === types.SECRET) changedDoor.icon.tint = SECRET_DOOR_TINT; + wall = changedDoor.wall; + if (wall.document.door === types.DOOR) changedDoor.icon.tint = 0xffffff; + else if (wall.document.door === types.SECRET) changedDoor.icon.tint = SECRET_DOOR_TINT; else console.warn( "Smart Doors | Encountered unknown door type " + diff --git a/src/features/locked_door_alert.js b/src/features/locked_door_alert.js index 25e8d6c..710715c 100644 --- a/src/features/locked_door_alert.js +++ b/src/features/locked_door_alert.js @@ -3,7 +3,7 @@ import {settingsKey} from "../settings.js"; // Tint the source door red when a locked alert is hovered export function onRenderChatMessage(message, html, data) { // Tint the door that generated this message - const source = message.data.flags.smartdoors?.source; + const source = message.flags.smartdoors?.source; if (!source) return; // Tint on mouse enter @@ -33,7 +33,7 @@ export function onDoorLeftClick() { // Check if this feature is enabled 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; // 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}; message.content = game.i18n.localize("smart-doors.ui.lockedDoorAlert"); 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); return true; } diff --git a/src/features/synchronized_doors.js b/src/features/synchronized_doors.js index b11c73a..49f0003 100644 --- a/src/features/synchronized_doors.js +++ b/src/features/synchronized_doors.js @@ -3,7 +3,7 @@ import * as Util from "../util.js"; // Inject settings for synchronized doors 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 const synchronizedSettings = `

${game.i18n.localize("smart-doors.ui.synchronizedDoors.description")}

@@ -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 const doorInGroup = Util.findInAllWalls(wall => { // 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 - if (wall.data.flags.smartdoors?.synchronizationGroup !== formData.synchronizationGroup) + if (wall.flags.smartdoors?.synchronizationGroup !== formData.synchronizationGroup) return false; // 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; @@ -60,11 +60,11 @@ export async function onWallConfigUpdate(event, formData) { }); if (doorInGroup) { // ds is the door sate in foundry - updateData.ds = doorInGroup.data.ds; + updateData.ds = doorInGroup.ds; if (synchronizeSecretStatus) { // 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 export function onDoorLeftClick() { - const state = this.wall.data.ds; + const state = this.wall.document.ds; const states = CONST.WALL_DOOR_STATES; // Check if this feature is enabled 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 if (!synchronizationGroup) return false; @@ -109,13 +109,13 @@ export function onDoorLeftClick() { } export function onDoorRightClick() { - const state = this.wall.data.ds; + const state = this.wall.document.ds; const states = CONST.WALL_DOOR_STATES; // Check if this feature is enabled 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 if (!synchronizationGroup) return false; @@ -140,8 +140,7 @@ export function onDoorRightClick() { export function updateSynchronizedDoors(updateData, synchronizationGroup) { // Search for doors belonging to the synchronization group in all scenes let scenes = Util.filterAllWalls( - wall => - wall.data.door && wall.data.flags.smartdoors?.synchronizationGroup === synchronizationGroup, + wall => wall.door && wall.flags.smartdoors?.synchronizationGroup === synchronizationGroup, ); // Update all doors in the synchronization group diff --git a/src/features/toggle_secret_door.js b/src/features/toggle_secret_door.js index f11e938..9002edc 100644 --- a/src/features/toggle_secret_door.js +++ b/src/features/toggle_secret_door.js @@ -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) if (toggleSecretDoor && game.user.isGM) { 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 synchronizationGroup = this.wall.data.flags.smartdoors?.synchronizationGroup; + const synchronizationGroup = this.wall.document.flags.smartdoors?.synchronizationGroup; if ( game.settings.get(settingsKey, "synchronizedDoors") && synchronizationGroup && - this.wall.data.flags.smartdoors?.synchronizeSecretStatus + this.wall.document.flags.smartdoors?.synchronizeSecretStatus ) updateSynchronizedDoors(updateData, synchronizationGroup); else this.wall.document.update(updateData); diff --git a/src/migration.js b/src/migration.js index f93e27b..bad45b3 100644 --- a/src/migration.js +++ b/src/migration.js @@ -19,8 +19,8 @@ export function performMigrations() { // Make a dictionary that maps all door ids to their scenes const walls = game.scenes.reduce((dict, scene) => { - scene.data.walls.forEach(wall => { - if (!wall.data.door) return; + scene.walls.forEach(wall => { + if (!wall.door) return; dict[wall.id] = scene.id; }); return dict; @@ -28,14 +28,14 @@ export function performMigrations() { // Migrate all messages that have a (wall) source id game.messages.forEach(async message => { - const wallId = message.data.flags.smartdoors?.sourceId; + const wallId = message.flags.smartdoors?.sourceId; if (!wallId) return; - const flags = message.data.flags; + const flags = message.flags; delete flags.smartdoors.sourceId; const scene = walls[wallId]; // If there is no wall with this id anymore we can drop the value. It has no purpose anymore if (!scene) { - if (!message.data.flags.smartdoors) delete flags.smartdoors; + if (!message.flags.smartdoors) delete flags.smartdoors; } else { // Assign the id and the scene id to the new data structure flags.smartdoors.source = {wall: wallId, scene: scene}; diff --git a/src/util.js b/src/util.js index 7ddf301..fe74e82 100644 --- a/src/util.js +++ b/src/util.js @@ -2,7 +2,7 @@ export function filterAllWalls(filterFn) { // Find all walls that match the filter criteria 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 return scenes.filter(scene => scene.walls.length > 0);