vtt-compendium-folders
vtt-compendium-folders copied to clipboard
Deleting more than one custom pack causes console error
If I delete more than one custom pack in a loop I get this error.
foundry.js:16058 TypeError: Cannot read property 'title' of null
at CompendiumEntry.get name [as name] (compendium-folders.js:293)
at s (foundry.js:16107)
at Array.sort (<anonymous>)
at Function._populate (foundry.js:16116)
at Function.setupFolders (foundry.js:16056)
at CompendiumFolderDirectory.initialize (compendium-folders.js:625)
at CompendiumFolderDirectory.render (foundry.js:16138)
at foundry.js:28345
async function deleteCompendiums() {
const packages = ['world'];
const compendiums = game.packs.entries.filter(r => packages.includes(r.metadata.package));
for (let i = 0; i < compendiums.length; i++) {
await compendiums[i].delete();
}
}
I forgot to note I was creating my compendiums in code, not though the UI, so there is probably something with this api I should have done.
async function createCompendium(name) {
const nameLowerHypen = name.replace(/\s/g, '-').toLowerCase();
return await Compendium.create({
"label": name,
"entity": "Item",
"name": nameLowerHypen,
"path": "packs/" + nameLowerHypen + ".db",
"system": "swade"
})
}
Hi, yeah this will happen because the module stores some metadata about the compendiums in order to sort them into folders. I'll see about including this in a future release but for now you should be able to remove the entry that I create programatically using this (it may need to be before your Compendium.delete()
not after):
await game.customFolders.compendium.entries.get(packCode).delete();
It tells me that the delete method is undefined.
game.customFolders.compendium.entries.get(packCode).delete()
The CompendiumFolder object does have a delete method, but I'm not trying to delete the whole folder.
game.customFolders.compendium.folders.entries[0].delete()
Ah looks like i forgot to include the delete method for entries. I'm not sure if there is currently a way to programmatically delete compendiums in that case. I'm currently working on getting compendium folders working for 0.8.x, but if i have some time ill modify the testing version and you can test it.