[Fix] CompendiumBrowser Pack Toggling (#1909)

* Fixed so that CompendiumBrowserSettings saves source/pack names as slugified version to avoid foundrdy not saving names with dots in the middle

* Updated excludedPacks with another layer of TypedObjectField

* Renmamed variable

* Update module/applications/dialogs/CompendiumBrowserSettings.mjs

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>

---------

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
This commit is contained in:
WBHarry 2026-05-21 01:33:07 +02:00 committed by GitHub
parent da06381748
commit f4c21a6a1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 20 deletions

View file

@ -50,7 +50,7 @@ export default class CompendiumBrowserSettings extends HandlebarsApplicationMixi
const excludedSourceData = this.browserSettings.excludedSources; const excludedSourceData = this.browserSettings.excludedSources;
const excludedPackData = this.browserSettings.excludedPacks; const excludedPackData = this.browserSettings.excludedPacks;
context.typePackCollections = game.packs.reduce((acc, pack) => { context.typePackCollections = game.packs.reduce((acc, pack) => {
const { type, label, packageType, packageName: basePackageName, id } = pack.metadata; const { type, label, packageType, packageName: basePackageName, name, id } = pack.metadata;
if (!CompendiumBrowserSettings.#browserPackTypes.includes(type)) return acc; if (!CompendiumBrowserSettings.#browserPackTypes.includes(type)) return acc;
const isWorldPack = packageType === 'world'; const isWorldPack = packageType === 'world';
@ -68,13 +68,15 @@ export default class CompendiumBrowserSettings extends HandlebarsApplicationMixi
if (!acc[type].sources[packageName]) if (!acc[type].sources[packageName])
acc[type].sources[packageName] = { label: sourceLabel, checked: sourceChecked, packs: [] }; acc[type].sources[packageName] = { label: sourceLabel, checked: sourceChecked, packs: [] };
const checked = !excludedPackData[id] || !excludedPackData[id].excludedDocumentTypes.includes(type); const included =
!excludedPackData[packageName] ||
!excludedPackData[packageName][name]?.excludedDocumentTypes.includes(type);
acc[type].sources[packageName].packs.push({ acc[type].sources[packageName].packs.push({
pack: id, name,
type, type,
label: id === game.system.id ? game.system.title : game.i18n.localize(label), label: id === game.system.id ? game.system.title : game.i18n.localize(label),
checked: checked checked: included
}); });
return acc; return acc;
@ -106,16 +108,16 @@ export default class CompendiumBrowserSettings extends HandlebarsApplicationMixi
toggleTypedPack(event) { toggleTypedPack(event) {
event.stopPropagation(); event.stopPropagation();
const { type, pack } = event.target.dataset; const { type, source, packName } = event.target.dataset;
const currentlyExcluded = this.browserSettings.excludedPacks[pack] const currentlyExcluded = this.browserSettings.excludedPacks[source]?.[packName]
? this.browserSettings.excludedPacks[pack].excludedDocumentTypes.includes(type) ? this.browserSettings.excludedPacks[source][packName].excludedDocumentTypes.includes(type)
: false; : false;
if (!this.browserSettings.excludedPacks[pack]) this.browserSettings.excludedPacks[source] ??= {};
this.browserSettings.excludedPacks[pack] = { excludedDocumentTypes: [] }; this.browserSettings.excludedPacks[source][packName] ??= { excludedDocumentTypes: [] };
this.browserSettings.excludedPacks[pack].excludedDocumentTypes = currentlyExcluded this.browserSettings.excludedPacks[source][packName].excludedDocumentTypes = currentlyExcluded
? this.browserSettings.excludedPacks[pack].excludedDocumentTypes.filter(x => x !== type) ? this.browserSettings.excludedPacks[source][packName].excludedDocumentTypes.filter(x => x !== type)
: [...(this.browserSettings.excludedPacks[pack]?.excludedDocumentTypes ?? []), type]; : [...(this.browserSettings.excludedPacks[source][packName]?.excludedDocumentTypes ?? []), type];
this.render(); this.render();
} }

View file

@ -11,12 +11,14 @@ export default class CompendiumBrowserSettings extends foundry.abstract.DataMode
}) })
), ),
excludedPacks: new fields.TypedObjectField( excludedPacks: new fields.TypedObjectField(
new fields.TypedObjectField(
new fields.SchemaField({ new fields.SchemaField({
excludedDocumentTypes: new fields.ArrayField( excludedDocumentTypes: new fields.ArrayField(
new fields.StringField({ required: true, choices: CONST.SYSTEM_SPECIFIC_COMPENDIUM_TYPES }) new fields.StringField({ required: true, choices: CONST.SYSTEM_SPECIFIC_COMPENDIUM_TYPES })
) )
}) })
) )
)
}; };
} }
@ -28,7 +30,7 @@ export default class CompendiumBrowserSettings extends foundry.abstract.DataMode
const excludedSourceData = this.excludedSources[packageName]; const excludedSourceData = this.excludedSources[packageName];
if (excludedSourceData && excludedSourceData.excludedDocumentTypes.includes(pack.metadata.type)) return true; if (excludedSourceData && excludedSourceData.excludedDocumentTypes.includes(pack.metadata.type)) return true;
const excludedPackData = this.excludedPacks[item.pack]; const excludedPackData = this.excludedPacks[packageName]?.[pack.metadata.name];
if (excludedPackData && excludedPackData.excludedDocumentTypes.includes(pack.metadata.type)) return true; if (excludedPackData && excludedPackData.excludedDocumentTypes.includes(pack.metadata.type)) return true;
return false; return false;

View file

@ -449,7 +449,6 @@ export async function createEmbeddedItemsWithEffects(actor, baseData) {
effects: data.effects?.map(effect => effect.toObject()) effects: data.effects?.map(effect => effect.toObject())
}); });
} }
await actor.createEmbeddedDocuments('Item', effectData); await actor.createEmbeddedDocuments('Item', effectData);
} }

View file

@ -22,7 +22,7 @@
<div class="checks-container {{#unless source.checked}}collapsed{{/unless}}"> <div class="checks-container {{#unless source.checked}}collapsed{{/unless}}">
{{#each source.packs as |pack|}} {{#each source.packs as |pack|}}
<div class="check-container"> <div class="check-container">
<input type="checkbox" class="pack-checkbox" data-type="{{pack.type}}" data-pack="{{pack.pack}}" {{checked pack.checked}} /> <input type="checkbox" class="pack-checkbox" data-type="{{pack.type}}" data-source="{{@../key}}" data-pack-name="{{pack.name}}" {{checked pack.checked}} />
<label>{{pack.label}}</label> <label>{{pack.label}}</label>
</div> </div>
{{/each}} {{/each}}