From 81f455c63adaf57b9b497032b75cdb71237451a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 4 May 2021 22:48:11 +0200 Subject: [PATCH] Port the code to Foundry 0.8.5 --- CHANGELOG.md | 3 +++ module.json | 4 ++-- src/features/locked_door_alert.js | 8 ++++---- src/features/synchronized_doors.js | 28 +++++++++++----------------- src/features/toggle_secret_door.js | 2 +- src/migration.js | 4 ++-- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 724287f..c16133e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## In development +### Compatibility +- Smart Doors is now compatible with Foundry 0.8.5 + ### Feature removals - The door icons now have outlines by defualt in Foundry. As a result the "Door Icon Outline" feature was removed. - Secret doors now have a different icon from regular doors in Foundry, making the "Tint Secret Doors" feature redundant. As a result it was removed. diff --git a/module.json b/module.json index 9532ef2..7c16aa0 100644 --- a/module.json +++ b/module.json @@ -3,8 +3,8 @@ "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.2.6", - "minimumCoreVersion" : "0.7.7", - "compatibleCoreVersion" : "0.7.9", + "minimumCoreVersion" : "0.8.5", + "compatibleCoreVersion" : "0.8.5", "authors": [ { "name": "Manuel Vögele", diff --git a/src/features/locked_door_alert.js b/src/features/locked_door_alert.js index c060fa5..eebc674 100644 --- a/src/features/locked_door_alert.js +++ b/src/features/locked_door_alert.js @@ -9,7 +9,7 @@ export function onRenderChatMessage(message, html, data) { // Tint on mouse enter const mouseEnter = function () { - const sourceDoor = canvas.controls.doors.children.find(door => door.wall.data._id === source.wall && door.wall.scene.id === source.scene); + const sourceDoor = canvas.controls.doors.children.find(door => door.wall.id === source.wall && door.wall.scene.id === source.scene); if (sourceDoor) sourceDoor.icon.tint = 0xff0000; } @@ -17,7 +17,7 @@ export function onRenderChatMessage(message, html, data) { // Remove tint on mouse leave const mouseLeave = function () { - const sourceDoor = canvas.controls.doors.children.find(door => door.wall.data._id === source.wall && door.wall.scene.id === source.scene); + const sourceDoor = canvas.controls.doors.children.find(door => door.wall.id === source.wall && door.wall.scene.id === source.scene); if (sourceDoor) sourceDoor.icon.tint = 0xffffff; } @@ -34,7 +34,7 @@ export function onDoorLeftClick() { const states = CONST.WALL_DOOR_STATES // Only create messages when the door is locked. - if (state != states.LOCKED) + if (state !== states.LOCKED) return false // Generate no message if the gm attempts to open the door @@ -43,7 +43,7 @@ export function onDoorLeftClick() { // Create and send the chat message const message = {} - message.user = game.user + message.user = game.user.id; if (game.user.character) message.speaker = {actor: game.user.character} message.content = "Just tried to open a locked door" diff --git a/src/features/synchronized_doors.js b/src/features/synchronized_doors.js index fed64af..018e1fa 100644 --- a/src/features/synchronized_doors.js +++ b/src/features/synchronized_doors.js @@ -35,7 +35,7 @@ export async function onWallConfigUpdate(event, formData) { const updateData = {flags: {smartdoors: {synchronizationGroup: formData.synchronizationGroup}}}; let ids = this.options.editTargets; if (ids.length == 0) { - ids = [this.object.data._id]; + ids = [this.object.id]; } // If a synchronization group is set, get the state of existing doors and assume their state @@ -46,33 +46,30 @@ 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.door) + if (!wall.data.door) return false // We only want doors in the same synchronization group - if (wall.flags.smartdoors?.synchronizationGroup !== formData.synchronizationGroup) + if (wall.data.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.scene === canvas.scene && ids.includes(wall._id)) + if (wall.parent.id === canvas.scene.id && ids.includes(wall.id)) return false return true }) if (doorInGroup) { // ds is the door sate in foundry - updateData.ds = doorInGroup.ds; + updateData.ds = doorInGroup.data.ds; if (synchronizeSecretStatus) { // door is the door type in foundry - updateData.door = doorInGroup.door + updateData.door = doorInGroup.data.door; } } } // Update all the edited walls - const updateDataset = ids.reduce((dataset, id) => { - dataset.push({_id: id, ...updateData}) - return dataset - }, []) - const updateResult = await canvas.scene.updateEmbeddedEntity("Wall", updateDataset); + const updateDataset = ids.map(id => {return {_id: id, ...updateData}}); + const updateResult = await canvas.scene.updateEmbeddedDocuments("Wall", updateDataset); // If door is synchronized, synchronize secret status among synchronized doors if (formData.synchronizationGroup) @@ -143,13 +140,10 @@ export function onDoorRightClick() { } // Updates all doors in the specified synchronization group with the provided data -export async function updateSynchronizedDoors(updateData, synchronizationGroup) { +export function updateSynchronizedDoors(updateData, synchronizationGroup) { // Search for doors belonging to the synchronization group in all scenes - let scenes = Util.filterAllWalls(wall => wall.door && wall.flags.smartdoors?.synchronizationGroup === synchronizationGroup); + let scenes = Util.filterAllWalls(wall => wall.data.door && wall.data.flags.smartdoors?.synchronizationGroup === synchronizationGroup); // Update all doors in the synchronization group - for (const scene of scenes) { - // When VFTT 0.8 is out look for a way to do this in a single call. - await scene.scene.updateEmbeddedEntity("Wall", scene.walls.map((wall) => {return {_id: wall._id, ...updateData}})) - } + return Promise.all(scenes.map(scene => scene.scene.updateEmbeddedDocuments("Wall", scene.walls.map((wall) => {return {_id: wall.id, ...updateData}})))); } diff --git a/src/features/toggle_secret_door.js b/src/features/toggle_secret_door.js index 47c8643..21fe694 100644 --- a/src/features/toggle_secret_door.js +++ b/src/features/toggle_secret_door.js @@ -12,7 +12,7 @@ export function onDoorLeftClick(event) { if (game.settings.get(settingsKey, "synchronizedDoors") && synchronizationGroup && this.wall.data.flags.smartdoors?.synchronizeSecretStatus) updateSynchronizedDoors(updateData, synchronizationGroup) else - this.wall.update(updateData) + this.wall.document.update(updateData) return true } diff --git a/src/migration.js b/src/migration.js index fd36391..c34dd8e 100644 --- a/src/migration.js +++ b/src/migration.js @@ -20,9 +20,9 @@ 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.door) + if (!wall.data.door) return - dict[wall._id] = scene.id + dict[wall.id] = scene.id; }) return dict }, {})