Forked from janssen-io/foundry-set-folder-permissions.js
Created
May 20, 2020 07:11
-
-
Save p4535992/3a570ba5f27f0e5a3b572431c82d5fb0 to your computer and use it in GitHub Desktop.
Change the permissions of items in bulk in FoundryVTT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var folderName = "Test"; | |
var reqPermission = 0; // 0=None, 1=Limited, 2=Observer, 3=Owner | |
/***** | |
WARNING: This will overwrite the permissions of the items in the folder <folderName>! | |
That is, it will not keep the player permissions! | |
Tested on FoundryVTT 0.5.5 | |
******/ | |
function repermission(currentFolder) { | |
console.log("Repermissioning: ", currentFolder.name); | |
if (currentFolder.content){ | |
currentFolder.content.map(item => { | |
let newPermissions = duplicate(item.data.permission); | |
newPermissions.default = reqPermission; | |
console.log(" Item:", item.data.name); | |
item.update({permission: newPermissions}); | |
}); | |
} | |
if (currentFolder.children) { | |
currentFolder.children.map(({data}) => { | |
repermission(game.folders.entities.filter(f => f.data._id == data._id)[0]); | |
}); | |
} | |
} | |
// select folder to re-permission | |
var rootFolder = game.folders.entities.filter(({data}) => data.name == folderName)[0]; | |
repermission(rootFolder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment