mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-05 20:34:15 +02:00
Preload class and subclass features for description (#1940)
Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
251d7e4e13
commit
493998cc95
3 changed files with 54 additions and 6 deletions
|
|
@ -865,6 +865,45 @@ export function camelize(str) {
|
|||
.replace(/\s+/g, '');
|
||||
}
|
||||
|
||||
/** Bulk load a list of documents using uuids. Returns the documents in the same order */
|
||||
export async function fromUuids(uuids) {
|
||||
// Set up base entries. Each step works on a sublist of these objects
|
||||
const entries = uuids.map(uuid => ({
|
||||
uuid,
|
||||
parsed: foundry.utils.parseUuid(uuid),
|
||||
value: foundry.utils.fromUuidSync(uuid)
|
||||
}));
|
||||
|
||||
// Handle missing uuids for embedded documents first
|
||||
// A value may be index data, so we check if its a document
|
||||
const packEmbeddedEntries = entries.filter(
|
||||
e =>
|
||||
!(e.value instanceof Document) &&
|
||||
e.parsed.collection instanceof foundry.documents.collections.CompendiumCollection &&
|
||||
e.parsed.embedded.length > 0
|
||||
);
|
||||
await Promise.all(
|
||||
packEmbeddedEntries.map(async e => {
|
||||
e.value = await fromUuid(e.uuid);
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
// Handle missing top level pack stuff, by batching per pack
|
||||
const missingTopLevel = entries.filter(e => !(e.value instanceof Document) && e.value?.pack);
|
||||
for (const packGroup of Object.values(Object.groupBy(missingTopLevel, e => e.value.pack))) {
|
||||
const pack = game.packs.get(packGroup[0].value.pack);
|
||||
if (!pack) continue;
|
||||
|
||||
const ids = packGroup.map(p => p.parsed.id);
|
||||
const documents = await pack.getDocuments({ _id__in: ids });
|
||||
for (const p of packGroup) {
|
||||
p.value = documents.find(d => d.id === p.parsed.id) ?? p.value;
|
||||
}
|
||||
}
|
||||
|
||||
return entries.map(e => e.value);
|
||||
}
|
||||
/**
|
||||
* Triggers DiceSoNice rolls or dice roll audio for rolls. Not used for duality rolls.
|
||||
* @param { Roll[] } rolls
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue