compendium shennanegins

TIL about CompendiumContent.getDocuments taking nedb queries.
game.packs.get('dnd5e.heroes').getDocuments({ 'data.abilities.con.value': {$gt: 14} });
game.packs.get('dnd5e.heroes').getDocuments({ 'data.abilities.con.value': {$gt: 14} });
More info about nedb queries: https://github.com/louischatriot/nedb#finding-documents
C
Calego935d ago
No description
C
Calego935d ago
The above returns all actors in the compendium with a constitution value greater than 14.
E
Ethaks935d ago
I vaguely remember Atro mentioning this on the mothership at some point, too. IIRC documents fetched by this are not cached though, which can make repeated calls a bit costly. (Not sure if the caching situation changed in the meantime, so I cannot say whether the warning still applies)
C
Calego935d ago
Yeah good call, the docs only mention caching for the singular getDocument
C
ccjmk935d ago
hmm even with no caching this might be useful for my module 🤔 i mean, its mostly working already, but half of the code is held together with ducttape and best intentions; it would probably be helpful if I use queries to say, get only Spells when I want spells, and only Classes when I want classes, and don't rely on the user doing things the proper way spoiler alert: they never do
C
Calego935d ago
@ccjmk do you use the compendium indexes for your thing?
E
Ethaks935d ago
The query option is why inquired about 5e's data usage a while back, but all the custom stuff you had to do made it a bit difficult for me to recommend this
C
ccjmk935d ago
ehhh to be honest, I .. think ? but I never understood that part deeply. Ghost helped me set up a function I could call with a compendium name, and it would get all the items on the compendium, ready to be added into an actor and I just parsed it after the fact as I needed this' Le Function
export async function getItemListFromPackListByNames(packNames: string[]) {
const allItems = [];
for (const compendiumName of packNames) {
const pack = game.packs.get(compendiumName);
const worldItems = game.items;
if (!worldItems) throw new Error('game.items not initialized yet');
if (!pack) ui.notifications?.warn(`No pack for name [${compendiumName}]!`);
if (pack?.documentName !== 'Item') throw new Error(`${compendiumName} is not an Item pack`);
const itemPack = pack as CompendiumCollection<CompendiumCollection.Metadata & { entity: 'Item' }>;
const itemsPromises: Promise<Item | null | undefined>[] = [];
for (const itemIndex of pack.index.keys()) {
const item = itemPack.getDocument(itemIndex);
itemsPromises.push(item);
}
const items = await Promise.all(itemsPromises);
allItems.push(
...items
.filter((item): item is Item => !!item)
.map((item) => {
const itemFromCompendium = worldItems.fromCompendium(item);
// intentionally adding the flag without using the API as I don't want to persist this flag
// this should be enough and more lightweight
itemFromCompendium.flags.hct = {
link: {
id: item.id,
pack: item.pack,
},
};
return itemFromCompendium;
}),
);
}
return allItems;
}
export async function getItemListFromPackListByNames(packNames: string[]) {
const allItems = [];
for (const compendiumName of packNames) {
const pack = game.packs.get(compendiumName);
const worldItems = game.items;
if (!worldItems) throw new Error('game.items not initialized yet');
if (!pack) ui.notifications?.warn(`No pack for name [${compendiumName}]!`);
if (pack?.documentName !== 'Item') throw new Error(`${compendiumName} is not an Item pack`);
const itemPack = pack as CompendiumCollection<CompendiumCollection.Metadata & { entity: 'Item' }>;
const itemsPromises: Promise<Item | null | undefined>[] = [];
for (const itemIndex of pack.index.keys()) {
const item = itemPack.getDocument(itemIndex);
itemsPromises.push(item);
}
const items = await Promise.all(itemsPromises);
allItems.push(
...items
.filter((item): item is Item => !!item)
.map((item) => {
const itemFromCompendium = worldItems.fromCompendium(item);
// intentionally adding the flag without using the API as I don't want to persist this flag
// this should be enough and more lightweight
itemFromCompendium.flags.hct = {
link: {
id: item.id,
pack: item.pack,
},
};
return itemFromCompendium;
}),
);
}
return allItems;
}
given that its iterating over const itemIndex of pack.index.keys() I think the answer is "technically yes"
C
Calego935d ago
Looks like yes but also no Lol
C
ccjmk935d ago
Schrodinger's Indexes
C
Calego935d ago
Have a look at the getIndex method on compendium collection It lets you build and cache a slimmed down version of a compendium's documents locally So for instance if you need to display all the spells and their levels, you can add spell level to the index Instead of parsing all spells from the compendium itself
C
ccjmk935d ago
hmm but I will need the full item anyway later, though if getting trimmed versions of documents is performant enough, I guess I could get the minimum I need for displaying/sorting data, and search it on-demand when the user actually submits the actor to be created (which is usually just name, img, requirement, and for spells, level + I imagine index to re-find the appropriate documents)
C
Calego935d ago
right, later you get the full items, but only the ones you actually need
Want results from more Discord servers?
Add your server
More Posts
with just a parent class and the class name, is there a way to instantiate a new class?JamesB and @veterini have a question for y'all in #coc7-dev https://discord.com/channels/7323252527More Hooks 5ehttps://github.com/ElfFriend-DnD/foundryvtt-more-hooks-5e I'm going to try to use this library to hacreateEmbeddedDocuments issueI'm going to throw my code in a thread so I don't clutter this channel up with a wall of textBase Item@otigon it occurs to me that the new `baseItem` property on weapons and such is probably of interestCompendium loadinghmm ghost, I added some console.time tags here and there to measure the difference between loading oSkill and Ability bonusesA massive enhancement of Skills and Ability Checks/Saves allows them to be individually affected by 150 Sheet Changes@sdenec @lordzeel Sheet Changes required: - New Cog-menu for Ability Scores and Skills to support neDocumentData shennaneginsTIL: It is possible to `update` an Actor or Item's `data.data` with arbitrary information that isn'tflag shenanneginsTIL you can set the `flags` key on a document to whatever you want to (e.g. a string). This is a surraaeAfter some discussion yesterday in #active-effects , I decided to try to create a system-agnostic modevMode json changed warningI checked the module repo and I honestly can't figure out where I would plug in my code. I'd be guesS3 File Picker SettingsCan someone with an S3 configuration give me a test of the FilePicker settings api and tell me if a item preCreate@sol.folango @mrprimate (pinging you two in particular because you do import stuff involving existinItem Macro Compendium WorkflowOkay, here's a long one that's a bit of a doozy. I'm looking at setting up some sort of tooling/workItem Specific Crit DetailsOh that critical hit thing is gonna hit MRE too isn't it... hrm...1.5.x 72%@dnd5e No action required (but suggested 🙂 ) The 1.5.0 milestone is ~72% complete. It has a due daV9 Tabs IssueIf you never figured this out, here's why this happened: A small change in `Tabs` during v9 causes sDeck Creation MacroI created a macro to fill out a 52-card deck, you set the ID of the deck and the base URL of the foldevmode-issues@arcanist figured out, the flex layout elements have `pointer-events: none`, so anything injected wifunction vs methodAnyone know of a good guide that explains the difference between a function and a method? I don't re