Port the code to Foundry 0.8.5
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
## In development
|
## In development
|
||||||
|
### Compatibility
|
||||||
|
- Smart Doors is now compatible with Foundry 0.8.5
|
||||||
|
|
||||||
### Feature removals
|
### Feature removals
|
||||||
- The door icons now have outlines by defualt in Foundry. As a result the "Door Icon Outline" feature was removed.
|
- 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.
|
- 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.
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
"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.6",
|
"version": "1.2.6",
|
||||||
"minimumCoreVersion" : "0.7.7",
|
"minimumCoreVersion" : "0.8.5",
|
||||||
"compatibleCoreVersion" : "0.7.9",
|
"compatibleCoreVersion" : "0.8.5",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Manuel Vögele",
|
"name": "Manuel Vögele",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export function onRenderChatMessage(message, html, data) {
|
|||||||
|
|
||||||
// Tint on mouse enter
|
// Tint on mouse enter
|
||||||
const mouseEnter = function () {
|
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)
|
if (sourceDoor)
|
||||||
sourceDoor.icon.tint = 0xff0000;
|
sourceDoor.icon.tint = 0xff0000;
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ export function onRenderChatMessage(message, html, data) {
|
|||||||
|
|
||||||
// Remove tint on mouse leave
|
// Remove tint on mouse leave
|
||||||
const mouseLeave = function () {
|
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)
|
if (sourceDoor)
|
||||||
sourceDoor.icon.tint = 0xffffff;
|
sourceDoor.icon.tint = 0xffffff;
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ export function onDoorLeftClick() {
|
|||||||
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.
|
||||||
if (state != states.LOCKED)
|
if (state !== states.LOCKED)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
// Generate no message if the gm attempts to open the door
|
// Generate no message if the gm attempts to open the door
|
||||||
@@ -43,7 +43,7 @@ export function onDoorLeftClick() {
|
|||||||
|
|
||||||
// Create and send the chat message
|
// Create and send the chat message
|
||||||
const message = {}
|
const message = {}
|
||||||
message.user = game.user
|
message.user = game.user.id;
|
||||||
if (game.user.character)
|
if (game.user.character)
|
||||||
message.speaker = {actor: game.user.character}
|
message.speaker = {actor: game.user.character}
|
||||||
message.content = "Just tried to open a locked door"
|
message.content = "Just tried to open a locked door"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export async function onWallConfigUpdate(event, formData) {
|
|||||||
const updateData = {flags: {smartdoors: {synchronizationGroup: formData.synchronizationGroup}}};
|
const updateData = {flags: {smartdoors: {synchronizationGroup: formData.synchronizationGroup}}};
|
||||||
let ids = this.options.editTargets;
|
let ids = this.options.editTargets;
|
||||||
if (ids.length == 0) {
|
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
|
// 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
|
// 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.door)
|
if (!wall.data.door)
|
||||||
return false
|
return false
|
||||||
// We only want doors in the same synchronization group
|
// 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
|
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.scene === canvas.scene && ids.includes(wall._id))
|
if (wall.parent.id === canvas.scene.id && ids.includes(wall.id))
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if (doorInGroup) {
|
if (doorInGroup) {
|
||||||
// ds is the door sate in foundry
|
// ds is the door sate in foundry
|
||||||
updateData.ds = doorInGroup.ds;
|
updateData.ds = doorInGroup.data.ds;
|
||||||
|
|
||||||
if (synchronizeSecretStatus) {
|
if (synchronizeSecretStatus) {
|
||||||
// door is the door type in foundry
|
// door is the door type in foundry
|
||||||
updateData.door = doorInGroup.door
|
updateData.door = doorInGroup.data.door;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all the edited walls
|
// Update all the edited walls
|
||||||
const updateDataset = ids.reduce((dataset, id) => {
|
const updateDataset = ids.map(id => {return {_id: id, ...updateData}});
|
||||||
dataset.push({_id: id, ...updateData})
|
const updateResult = await canvas.scene.updateEmbeddedDocuments("Wall", updateDataset);
|
||||||
return dataset
|
|
||||||
}, [])
|
|
||||||
const updateResult = await canvas.scene.updateEmbeddedEntity("Wall", updateDataset);
|
|
||||||
|
|
||||||
// If door is synchronized, synchronize secret status among synchronized doors
|
// If door is synchronized, synchronize secret status among synchronized doors
|
||||||
if (formData.synchronizationGroup)
|
if (formData.synchronizationGroup)
|
||||||
@@ -143,13 +140,10 @@ export function onDoorRightClick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Updates all doors in the specified synchronization group with the provided data
|
// 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
|
// 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
|
// Update all doors in the synchronization group
|
||||||
for (const scene of scenes) {
|
return Promise.all(scenes.map(scene => scene.scene.updateEmbeddedDocuments("Wall", scene.walls.map((wall) => {return {_id: wall.id, ...updateData}}))));
|
||||||
// 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}}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function onDoorLeftClick(event) {
|
|||||||
if (game.settings.get(settingsKey, "synchronizedDoors") && synchronizationGroup && this.wall.data.flags.smartdoors?.synchronizeSecretStatus)
|
if (game.settings.get(settingsKey, "synchronizedDoors") && synchronizationGroup && this.wall.data.flags.smartdoors?.synchronizeSecretStatus)
|
||||||
updateSynchronizedDoors(updateData, synchronizationGroup)
|
updateSynchronizedDoors(updateData, synchronizationGroup)
|
||||||
else
|
else
|
||||||
this.wall.update(updateData)
|
this.wall.document.update(updateData)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ 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.data.walls.forEach(wall => {
|
||||||
if (!wall.door)
|
if (!wall.data.door)
|
||||||
return
|
return
|
||||||
dict[wall._id] = scene.id
|
dict[wall.id] = scene.id;
|
||||||
})
|
})
|
||||||
return dict
|
return dict
|
||||||
}, {})
|
}, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user