-
Notifications
You must be signed in to change notification settings - Fork 8
/
ActorItemApi.ts
45 lines (44 loc) · 1.51 KB
/
ActorItemApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ActorItemRuntime } from 'src/runtime/ActorItemRuntime';
import type { ActorItemSectionFooterCommand } from '../../api.types';
/**
* API functionality related to Actor-owned items.
*
* @category Configuration
*/
export class ActorItemApi {
/**
* Registers actor item section commands which Tidy 5e can render at select locations on the sheet.
* @param commands actor item section commands for Tidy 5e to render
*
* @example Registering a command that sorts items
* ```js
* Hooks.once('tidy5e-sheet.ready', (api) => {
* api.config.actorItem.registerSectionFooterCommands([
* {
* enabled: (params) =>
* params.section.items?.length > 1 || params.section.spells?.length > 1,
* iconClass: 'fa-solid fa-arrow-up-a-z',
* tooltip: 'Sort by Name Ascending',
* execute: async (params) => {
* const actor = params.actor;
* const itemsToSort = params.section.items ?? params.section.spells;
* await actor.updateEmbeddedDocuments(
* 'Item',
* [...itemsToSort]
* .sort((a, b) => {
* return a.name.localeCompare(b.name);
* })
* .map((item, idx) => {
* return { _id: item.id, sort: idx };
* })
* );
* },
* },
* ]);
* });
* ```
*/
registerSectionFooterCommands(commands: ActorItemSectionFooterCommand[]) {
ActorItemRuntime.registerActorItemSectionCommands(commands);
}
}