Improve class filtering

Related to #9
master
Matheus Clemente 2024-03-04 17:46:24 -03:00
parent 4837213b89
commit dfa10b9f92
2 changed files with 8 additions and 8 deletions

View File

@ -902,14 +902,14 @@ class CompendiumBrowser extends Application {
const matchedClass = []; const matchedClass = [];
const reqString = item.requirements?.replace(/\d/g, "").trim(); const reqString = item.requirements?.replace(/\d/g, "").trim();
if (reqString) { if (reqString) {
for (const [classId, classData] of Object.entries(this.provider.classes)) { for (const classData of Object.values(this.provider.classes)) {
const isClassMatch = classData.label.includes(reqString); const isClassMatch = classData.label.includes(reqString);
const isSubclassMatch = !isClassMatch && Object.values(classData.subclasses).some( const isSubclassMatch = !isClassMatch && Object.values(classData.subclasses).some(
(label) => reqString.includes(label) (label) => reqString.includes(label)
); );
if (isClassMatch || isSubclassMatch) { if (isClassMatch || isSubclassMatch) {
matchedClass.push(classId); matchedClass.push(classData.label);
} }
} }
} }
@ -1335,12 +1335,9 @@ class CompendiumBrowser extends Application {
_sortPackValues(packValue) { _sortPackValues(packValue) {
const sortable = Object.entries(packValue) const sortable = Object.entries(packValue)
.filter(([key, data]) => key !== undefined && data !== undefined)
.map(([key, data]) => { .map(([key, data]) => {
if (typeof data === "string") return [key, game.i18n.localize(data)]; if (typeof data === "string") return [key, game.i18n.localize(data)];
if (!data) {
console.error(`Compendium Browser | Pack Value "${key}" has no data.`);
return [key, ""];
}
return [key, data.label]; return [key, data.label];
}) })
.sort((a, b) => a[1].localeCompare(b[1])); .sort((a, b) => a[1].localeCompare(b[1]));

View File

@ -10,7 +10,7 @@ export class dnd5eProvider {
for (let pack of game.packs) { for (let pack of game.packs) {
if (pack.documentName === "Item") { if (pack.documentName === "Item") {
const indexes = await pack.getIndex({ fields: ["system.identifier", "system.classIdentifier"] }); const indexes = await pack.getIndex({ fields: ["system.identifier", "system.classIdentifier"] });
const classes = indexes.filter((entry) => entry.type === "class"); const classes = indexes.filter((entry) => entry.type === "class" && entry.system.identifier);
if (classes.length) { if (classes.length) {
classes.map((entry) => { classes.map((entry) => {
return { return {
@ -25,7 +25,7 @@ export class dnd5eProvider {
}; };
}); });
} }
const _subclasses = indexes.filter((entry) => entry.type === "subclass"); const _subclasses = indexes.filter((entry) => entry.type === "subclass" && entry.system.classIdentifier);
if (_subclasses.length) { if (_subclasses.length) {
_subclasses.map((entry) => { _subclasses.map((entry) => {
return { return {
@ -49,6 +49,9 @@ export class dnd5eProvider {
} }
} }
this.classes = foundry.utils.mergeObject(this.classes, subclasses); this.classes = foundry.utils.mergeObject(this.classes, subclasses);
this.classes = Object.fromEntries(
Object.entries(this.classes).filter(([classId, classData]) => classData.label)
);
} }
static classList = { static classList = {