Skip to content

Commit

Permalink
feat: allow api deletions of items to skip items with spells dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
akrigline committed Oct 30, 2022
1 parent 07db439 commit d4f52e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,18 @@ The spells listed can be used like normal. The Core System's consumption behavio
https://user-images.githubusercontent.com/7644614/190871810-824db216-56fa-4411-9e03-ada2a9c0f251.mp4


## API

When programatically deleting items that have spells attached, it is possible to skip the prompt for the user by providing the following object in the [DocumentModificationContext](https://foundryvtt.com/api/classes/foundry.abstract.Document.html#delete) option of the `delete` method.

```
someItem.delete({
itemsWithSpells5e: { alsoDeleteChildSpells: true } // or false
})
```

The logic within this module will respect the boolean provided, deleting the child item spells itself if `true`, or leaving them alone if `false`.

## Compatibility

Compatible with:
Expand Down
14 changes: 8 additions & 6 deletions scripts/classes/actor.js
Expand Up @@ -65,12 +65,14 @@ export class ItemsWithSpells5eActor {
return;
}

ItemsWithSpells5e.log(false, 'handleDeleteItem', itemDeleted);

const alsoDeleteChildSpells = await Dialog.confirm({
title: 'Items with Spells',
content: 'Would you also like to delete the spells from that item?',
});
ItemsWithSpells5e.log(false, 'handleDeleteItem', itemDeleted, options);

const alsoDeleteChildSpells =
options?.itemsWithSpells5e?.alsoDeleteChildSpells ??
(await Dialog.confirm({
title: 'Items with Spells',
content: 'Would you also like to delete the spells from that item?',
}));

if (alsoDeleteChildSpells) {
await this.removeChildSpellsFromActor(itemDeleted);
Expand Down

0 comments on commit d4f52e6

Please sign in to comment.