Skip to content

Commit

Permalink
Port the code to Foundry 0.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelVo committed May 22, 2021
1 parent 42529d3 commit 81f455c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/features/locked_door_alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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;
}
html.on("mouseenter", mouseEnter);

// 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;
}
Expand All @@ -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
Expand All @@ -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"
Expand Down
28 changes: 11 additions & 17 deletions src/features/synchronized_doors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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}}))));
}
2 changes: 1 addition & 1 deletion src/features/toggle_secret_door.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, {})
Expand Down

0 comments on commit 81f455c

Please sign in to comment.