6 Commits

9 changed files with 31 additions and 14 deletions

2
CHANGELOG.md Normal file
View File

@@ -0,0 +1,2 @@
## v1.0.1 (in development)
- When adding a door to a synchronization group adjust it's state to bring it in sync with the other doors

34
main.js
View File

@@ -73,22 +73,25 @@ function hookWallConfigUpdate() {
// Store our custom data from the WallConfig dialog
async function onWallConfigUpdate(event, formData) {
// TODO Bring newly merged doors in sync
const updateData = {flags: {smartdoors: {synchronizationGroup: formData.synchronizationGroup}}}
let ids = this.options.editTargets;
if (ids.length == 0) {
ids = [this.object.data._id];
}
const ids = this.options.editTargets;
if (ids.length > 0) {
// Multiple walls are edited at once. Update all of them
// If a synchronization group is set, get the state of existing doors and assume their state
if (formData.synchronizationGroup) {
const doorInGroup = findInAllWalls(wall => wall.door && wall.flags.smartdoors?.synchronizationGroup == formData.synchronizationGroup && !ids.includes(wall._id));
if (doorInGroup)
updateData.ds = doorInGroup.ds;
}
// Update all the edited walls
const updateDataset = ids.reduce((dataset, id) => {
dataset.push({_id: id, ...updateData})
return dataset
}, [])
return canvas.scene.updateEmbeddedEntity("Wall", updateDataset)
}
else {
// Only one wall is being edited
return this.object.update(updateData);
}
}
// Hook mouse events on DoorControls to perform our logic.
@@ -117,7 +120,18 @@ function hookDoorEvents() {
// Searches through all scenes for walls and returns those that match the given filter criteria.
function filterAllWalls(filterFn) {
return game.scenes.map((scene) => {return {scene: scene, walls: scene.data.walls.filter(filterFn)}});
// Find all walls that match the filter criteria
const scenes = game.scenes.map((scene) => {return {scene: scene, walls: scene.data.walls.filter(filterFn)}})
// Drop all scenes that don't contain any results
return scenes.filter(scene => scene.walls.length > 0)
}
// Searches through all scenes for a wall that matches the given filter criteria
function findInAllWalls(filterFn) {
// TODO The performance of this could be increased by stopping the search on the first hit
const scenes = filterAllWalls(filterFn)
// If results were found take the first wall from the first scene.
return scenes[0]?.walls[0]
}
// Our custom handler for mousedown events on doors

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@@ -20,5 +20,6 @@
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-smart-doors/master/module.json",
"download": "https://github.com/manuelVo/foundryvtt-smart-doors/archive/v1.0.0.zip",
"readme": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/README.md",
"changelog": "https://github.com/manuelVo/foundryvtt-smart-doors/blob/master/CHANGELOG.md",
"bugs": "https://github.com/manuelVo/foundryvtt-smart-doors/issues"
}