Handles deletion and folder creation for Foundry v13 #56
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes:
Links to #55
Current Behavior
In Foundry v12, users with the "Create Actors" permission (
ACTOR_CREATE) are also able to delete actors. The module is able to create and delete multiple temp actors while loading the character details, before finally assigning the data to the original actor.In case of a non-GM user importing a character with a familiar, that step fails with an error because they cannot create the "Familiars" folder.
In Foundry v13, only GM level users can delete actors. This leads to the import failing with an error when the module attempts to delete the first temp actor. The folder creation limitation remains the same.
New Behavior
In Foundry v12, there are no changes to the temp actor naming or location. They continue to get created at the root level and are deleted automatically. A new custom error message is shown when a non-GM user fails to create the "Familiars" folder. This message informs the user to either manually create the folder or enable the setting.
A new setting is added that toggles automatic creation of the required folders. This is only the "Familiars" folder in v12. A hook is used to create this folder whenever a GM level user logs in and the setting is enabled. As long as the folder exists, a non-GM user will not receive any error during import.
In Foundry v13, the setting also creates a second folder named "PathmuncherTemp". This location is used for all temp actors, and the actors are only deleted if the user has permission to do so. A number gets appended to the temp actor name (ex: "Mr Temp (LeafDruid) 0014") to help distinguish the stages. This might not be strictly necessary as the import process relies on ID and Foundry will allow duplicate actor names.
The setting is disabled by default to avoid introducing new folders to existing worlds where sheets are already set up.
I'm not familiar with the conventions around Foundry modules, so please let me know if creating folders in this way is alright. The main change will still work well without the setting and hook as long as GMs create those folders first.