From e92e35a0a83e46f937af2a0a7d42ada19e75fc4f Mon Sep 17 00:00:00 2001 From: Shawn Dibble Date: Tue, 26 May 2020 18:36:33 -0500 Subject: [PATCH 1/4] Create folder_to_rollable_table.js --- misc/folder_to_rollable_table.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 misc/folder_to_rollable_table.js diff --git a/misc/folder_to_rollable_table.js b/misc/folder_to_rollable_table.js new file mode 100644 index 0000000..e78e2dc --- /dev/null +++ b/misc/folder_to_rollable_table.js @@ -0,0 +1,19 @@ +// Take the entries of a folder and turn it into a rollable table +// Author: @Atropos#3814 + +const folder = game.folders.getName("Herbalism & Alchemy"); +const table = game.tables.getName("Common Ingredients"); +const items = folder.entities; +const results = folder.entities.map(i => { + return { + text: i.data.name, + type: 1, + collection: "Item", + resultId: i.data._id, + img: i.data.img, + weight: 1, + range: [1, 1], + drawn: false + } +}); +await table.createEmbeddedEntity("TableResult", results); From 060080b9959340a404b7d64bc557a1cd232bcabc Mon Sep 17 00:00:00 2001 From: Shawn Dibble Date: Wed, 27 May 2020 09:00:51 -0500 Subject: [PATCH 2/4] Create close_all_doors.js --- misc/close_all_doors.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 misc/close_all_doors.js diff --git a/misc/close_all_doors.js b/misc/close_all_doors.js new file mode 100644 index 0000000..5acf603 --- /dev/null +++ b/misc/close_all_doors.js @@ -0,0 +1,8 @@ +/** + * Closes all doors on the canvas + * Author: @Atropos#3814 + */ + +canvas.walls.updateMany(canvas.scene.data.walls.map(w => { + return {_id: w._id, ds: w.ds === 1 ? 0 : w.ds}; +})); From 252fdd746008158e344d26af499157be14a8d3bb Mon Sep 17 00:00:00 2001 From: Stan Janssen Date: Wed, 27 May 2020 23:33:48 +0200 Subject: [PATCH 3/4] Show dialog for bulk permission changes Instead of changing the variables on top, users can now enter the data in a nice dialog. --- item/foundry_item_permission.js | 112 +++++++++++++++++--------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/item/foundry_item_permission.js b/item/foundry_item_permission.js index 84dee21..2e6516c 100644 --- a/item/foundry_item_permission.js +++ b/item/foundry_item_permission.js @@ -1,64 +1,70 @@ -var folderName = "Test Deeper"; -var desiredPermission = 0; // 0=None, 1=Limited, 2=Observer, 3=Owner -var applyInSubfolders = true; +const dialog = new Dialog({ + title: "Set desired permission", + content: form, + buttons: { + use: { + label: "Apply permissions", + callback: applyPermissions + } + } +}).render(true); -/***** -WARNING: This will overwrite the permissions of the items in the folder ! - That is, it will not keep the player permissions! - - Tested on FoundryVTT 0.5.5 & 0.5.7 - -* * * * * * * * * * * * * * * * * * * * * * - -WARNING: Make sure the folder name is unique across actors, scenes, items, journals and roll tables! - This script will apply the desired permission on the first folder it finds with that name. -******/ +const form = ` +
Folder:
+ +
-function repermission(currentFolder) { - console.log("Repermissioning: ", currentFolder.name); +
Permission:
+ +
- if (currentFolder.content){ - currentFolder.content.map(item => { - let newPermissions = duplicate(item.data.permission); - newPermissions.default = desiredPermission; - console.log(" Item:", item.data.name); - item.update({permission: newPermissions}); - }); - } + +`; + +function applyPermissions(html) { + const folderName = html.find(`input#folderName`)[0].value; + const permission = html.find(`select#desiredPermission`)[0].value; + const recurse = html.find(`input#recurse`)[0].checked; - if (currentFolder.children && applyInSubfolders) { - currentFolder.children.map(({data}) => { - repermission(game.folders.entities.filter(f => f.data._id == data._id)[0]); - }); + const folders = game.folders.filter(f => f.name === folderName); + if (folders.length === 0) { + ui.notifications.error(`Your world does not have any folders named '${folderName}'.`); } -} - -function findFolder(parent) { - if (parent.data.name === folderName) { - return parent; + else if(folders.length > 1) { + ui.notifications.error(`Your world has more than one folder named ${folderName}`) } - - for (let child of parent.children) { - let foundFolder = findFolder(child); - if (foundFolder) { - return foundFolder; - } + else { + repermission(folders[0], permission, recurse); + ui.notifications.notify(`Desired permissions were set successfully for '${folderName}'.`); } - - return null; -} - -if (game.folders.entities.length == 0) { - console.error("Your world does not have any folders."); } -var root = { data: {}, children: game.folders.entities }; +function repermission(currentFolder, desiredPermission, recurse) { + console.debug("Repermissioning: ", currentFolder.name); + + if (currentFolder.content) { + currentFolder.content.map(item => { + let newPermissions = duplicate(item.data.permission); + newPermissions.default = desiredPermission; + console.debug(" Item:", item.data.name); + item.update({ permission: newPermissions }); + }); + } -var folder = findFolder(root); -if (!folder) { - console.error(`Your world does not have any folders named '${folderName}'.`); + if (currentFolder.children && recurse) { + currentFolder.children.map(({ data }) => { + repermission( + game.folders.entities.filter(f => f.data._id == data._id)[0], + desiredPermission, + recurse); + }); + } } -else { - repermission(folder); - console.log("Repermissioning finished successfully!"); -} \ No newline at end of file From 7ee23c377549385a52e74de4067d2c86a6f17b4a Mon Sep 17 00:00:00 2001 From: Anthony Vadala Date: Wed, 27 May 2020 23:16:15 -0400 Subject: [PATCH 4/4] Updated script thanks to... ... @janssen-io and @Grim-M for pointing out the fixes --- item/foundry_item_permission.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/item/foundry_item_permission.js b/item/foundry_item_permission.js index 2e6516c..53ca612 100644 --- a/item/foundry_item_permission.js +++ b/item/foundry_item_permission.js @@ -1,14 +1,3 @@ -const dialog = new Dialog({ - title: "Set desired permission", - content: form, - buttons: { - use: { - label: "Apply permissions", - callback: applyPermissions - } - } -}).render(true); - const form = `
Folder:
@@ -29,6 +18,17 @@ const form = ` `; +const dialog = new Dialog({ + title: "Set desired permission", + content: form, + buttons: { + use: { + label: "Apply permissions", + callback: applyPermissions + } + } +}).render(true); + function applyPermissions(html) { const folderName = html.find(`input#folderName`)[0].value; const permission = html.find(`select#desiredPermission`)[0].value;