Skip to content

Commit

Permalink
update docs, error handling for sorting without folders
Browse files Browse the repository at this point in the history
  • Loading branch information
esheyw committed Feb 4, 2024
1 parent 98a5621 commit ea0e3f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
- Add per-setting reset-to-default buttons

## Version 1.1.1
- Mark root folder setting as requiresReload
- 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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
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.
10 changes: 5 additions & 5 deletions scripts/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ea0e3f3

Please sign in to comment.