-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFavoritesDialog.js
37 lines (32 loc) · 1.5 KB
/
FavoritesDialog.js
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
const tokenActor = token?.actor ?? game.user.character;
const faves = tokenActor.system.favorites;
const sortedFaves = faves.sort((a, b) => a.sort - b.sort);
async function getFaveLabel(fave) {
const fullItem = await fromUuid(`${_token.actor.uuid}${fave.id}`);
return `<span class="item-tooltip item " data-favorite-id="${fave.id}" data-item-id="${fave.id}" draggable="true" data-tooltip="
<section class="loading" data-uuid=${_token.actor.uuid}${fave.id}><i class="fas fa-spinner fa-spin-pulse"></i></section>
" data-tooltip-class="dnd5e2 dnd5e-tooltip item-tooltip" data-tooltip-direction="LEFT">
<img src="${fullItem.img}" height="30" style="vertical-align: middle; margin-right: 5px;">
${fullItem.name} ${fullItem.system.uses?.value ? `(${fullItem.system.uses?.value}/${fullItem.system.uses?.max})` : ""}
</span>
`;
}
const buttons = await Promise.all(sortedFaves.map(async (f) => {
const label = await getFaveLabel(f);
return {
label,
action: f.id,
callback: () => { return f.id; }
};
}));
const faveId = await foundry.applications.api.DialogV2.wait({
buttons,
window: {
title: "Favorite Items",
icon: "fa-solid fa-star"
},
render: (event, html) => html.querySelector(".form-footer").style.flexDirection = "column",
close: () => { return false; }
}, { id: "faves-dialog", width: 'auto' });
const item = await fromUuid(`${_token.actor.uuid}${faveId}`);
item.use({ legacy: false });