From ea0e3f3f72284b2c1d36c29b3748fddec35e88c3 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 3 Feb 2024 21:18:25 -0800 Subject: [PATCH] update docs, error handling for sorting without folders --- CHANGELOG.md | 5 ++++- README.md | 11 +++++++++-- scripts/init.mjs | 10 +++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bcbd70..13b67d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,4 +19,7 @@ - Add per-setting reset-to-default buttons ## Version 1.1.1 -- Mark root folder setting as requiresReload \ No newline at end of file +- Mark root folder setting as requiresReload + +## Version 1.1.2 +- Add minimal error handling and reporting for authorless macros when attempting to sort existing macros \ No newline at end of file diff --git a/README.md b/README.md index 33b9b22..e20c5d2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Macro Creation Tweaks -This is a pretty simple module that only does three things: +A module providing various conveniences around the creation and organization of macros. ## Append Numbers to Newly Created Macros Normally any Document created via a 'Create X' dialog gets a sequential number appended to it if no name is supplied, eg, `New Scene (2)`, `New Actor (50)`, etc. Creating a macro via clicking an empty hotbar slot currently does not have this handling, leading to a bunch of macros named identically (just `New Macro`) if, like me, you're lazy when writing little things to test. @@ -9,4 +9,11 @@ Normally any Document created via a 'Create X' dialog gets a sequential number a I accidentally click empty hotbar slots all the time, creating useless, empty macros I then have to right click -> delete. Tedious! This setting will delete any macro document if its config sheet is closed with nothing in it's command textarea. ## Set default type for newly created macros to `script` -Personally I make script macros *far* more often than chat macros, so this is the obvious choice, but if you'd like the other parts of this module without this change, it is configurable. \ No newline at end of file +Personally I make script macros *far* more often than chat macros, so this is the obvious choice, but if you'd like the other parts of this module without this change, it is configurable. + +## Sort macros into per-User folders +*Defaults Off* | *Requires Reload* +On creation, sorts macros made by non-GM users into a folder. User folders can be inside a containing root folder or at the top level of the macro directory. +User folders will always be named their user's name, and coloured their user's colour, and will default to manual sorting but not overwrite if changed to alphabetical. +The root folder, if enabled, will use the name and colour in settings for creation, but won't overwrite any changes made after. +Provides button in settings to sort pre-existing macros into user folders. \ No newline at end of file diff --git a/scripts/init.mjs b/scripts/init.mjs index dcdd9e6..cd4cc34 100644 --- a/scripts/init.mjs +++ b/scripts/init.mjs @@ -44,13 +44,13 @@ async function updateUserFolders() { export async function sortUserMacrosIntoFolders() { if (!setting("players-folders").includes("root")) return; const nonGMs = game.users.filter((user) => user.role !== CONST.USER_ROLES.GAMEMASTER); - const updates = nonGMs.reduce((acc, user) => { + const updates = []; + for (const user of nonGMs) { const userFolderID = user.getFlag(MODULE_ID, "macro-folder"); - //folder is a document reference if set + if (!game.folders.get(userFolderID)) return ui.notifications.warn(`Please do not attempt to sort until after reloading once player folders are enabled.`); const authored = game.macros.filter((m) => m.author?.id === user.id && m.folder?.id !== userFolderID); - if (authored.length > 0) acc.push(...authored.map((m) => ({ _id: m._id, folder: userFolderID }))); - return acc; - }, []); + if (authored.length > 0) updates.push(...authored.map((m) => ({ _id: m._id, folder: userFolderID }))); + } if (updates.length) { ui.notifications.info(`Sorting ${updates.length} macros into user folders.`); Macro.implementation.updateDocuments(updates);