mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-05 20:34:15 +02:00
Changed so that the ItemBrowser can take in preset.items
This commit is contained in:
parent
533421abba
commit
46af7ad228
2 changed files with 63 additions and 66 deletions
|
|
@ -440,9 +440,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
};
|
||||
|
||||
if (type === 'subclasses')
|
||||
presets.filter = {
|
||||
'system.linkedClass': { key: 'system.linkedClass', value: this.setup.class?.uuid }
|
||||
};
|
||||
presets.items = await (await foundry.utils.fromUuid(this.setup.class.uuid)).system.fetchSubclasses();
|
||||
|
||||
if (equipment.includes(type))
|
||||
presets.filter = {
|
||||
|
|
|
|||
|
|
@ -240,27 +240,27 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
super._replaceHTML(result, content, options);
|
||||
}
|
||||
|
||||
loadItems() {
|
||||
async loadItems() {
|
||||
let loadTimeout = this.toggleLoader(true);
|
||||
|
||||
const browserSettings = game.settings.get(
|
||||
CONFIG.DH.id,
|
||||
CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings
|
||||
);
|
||||
const promises = [];
|
||||
|
||||
game.packs.forEach(pack => {
|
||||
promises.push(
|
||||
new Promise(async resolve => {
|
||||
const items = await pack.getDocuments({ type__in: this.selectedMenu?.data?.type });
|
||||
resolve(items);
|
||||
})
|
||||
);
|
||||
});
|
||||
let allItems = [];
|
||||
for (const pack of game.packs) {
|
||||
allItems.push(...(await pack.getDocuments({ type__in: this.selectedMenu?.data?.type })));
|
||||
}
|
||||
|
||||
const items = this.presets.items ?? allItems;
|
||||
|
||||
Promise.all(promises).then(async result => {
|
||||
this.items = ItemBrowser.sortBy(
|
||||
result.flatMap(r => r).filter(r => !browserSettings.isEntryExcluded.bind(browserSettings)(r)),
|
||||
items.filter(r => !browserSettings.isEntryExcluded.bind(browserSettings)(r)),
|
||||
'name'
|
||||
);
|
||||
allItems = ItemBrowser.sortBy(
|
||||
allItems.filter(r => !browserSettings.isEntryExcluded.bind(browserSettings)(r)),
|
||||
'name'
|
||||
);
|
||||
|
||||
|
|
@ -277,7 +277,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
(await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description));
|
||||
}
|
||||
|
||||
this.fieldFilter = await this._createFieldFilter();
|
||||
this.fieldFilter = await this._createFieldFilter(allItems);
|
||||
|
||||
if (this.presets?.filter) {
|
||||
Object.entries(this.presets.filter).forEach(([k, v]) => {
|
||||
|
|
@ -318,7 +318,6 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
|
||||
clearTimeout(loadTimeout);
|
||||
this.toggleLoader(false);
|
||||
});
|
||||
}
|
||||
|
||||
toggleLoader(state) {
|
||||
|
|
@ -355,12 +354,12 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
);
|
||||
}
|
||||
|
||||
async _createFieldFilter() {
|
||||
async _createFieldFilter(items) {
|
||||
const filters = ItemBrowser.getFolderConfig(this.selectedMenu.data, 'filters');
|
||||
for (const f of filters) {
|
||||
if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field);
|
||||
else if (typeof f.choices === 'function') {
|
||||
f.choices = await f.choices(this.items);
|
||||
f.choices = await f.choices(items);
|
||||
}
|
||||
|
||||
// Clear field label so template uses our custom label parameter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue