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')
|
if (type === 'subclasses')
|
||||||
presets.filter = {
|
presets.items = await (await foundry.utils.fromUuid(this.setup.class.uuid)).system.fetchSubclasses();
|
||||||
'system.linkedClass': { key: 'system.linkedClass', value: this.setup.class?.uuid }
|
|
||||||
};
|
|
||||||
|
|
||||||
if (equipment.includes(type))
|
if (equipment.includes(type))
|
||||||
presets.filter = {
|
presets.filter = {
|
||||||
|
|
|
||||||
|
|
@ -240,27 +240,27 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
super._replaceHTML(result, content, options);
|
super._replaceHTML(result, content, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadItems() {
|
async loadItems() {
|
||||||
let loadTimeout = this.toggleLoader(true);
|
let loadTimeout = this.toggleLoader(true);
|
||||||
|
|
||||||
const browserSettings = game.settings.get(
|
const browserSettings = game.settings.get(
|
||||||
CONFIG.DH.id,
|
CONFIG.DH.id,
|
||||||
CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings
|
CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings
|
||||||
);
|
);
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
game.packs.forEach(pack => {
|
let allItems = [];
|
||||||
promises.push(
|
for (const pack of game.packs) {
|
||||||
new Promise(async resolve => {
|
allItems.push(...(await pack.getDocuments({ type__in: this.selectedMenu?.data?.type })));
|
||||||
const items = await pack.getDocuments({ type__in: this.selectedMenu?.data?.type });
|
}
|
||||||
resolve(items);
|
|
||||||
})
|
const items = this.presets.items ?? allItems;
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.all(promises).then(async result => {
|
|
||||||
this.items = ItemBrowser.sortBy(
|
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'
|
'name'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -277,7 +277,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
(await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description));
|
(await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fieldFilter = await this._createFieldFilter();
|
this.fieldFilter = await this._createFieldFilter(allItems);
|
||||||
|
|
||||||
if (this.presets?.filter) {
|
if (this.presets?.filter) {
|
||||||
Object.entries(this.presets.filter).forEach(([k, v]) => {
|
Object.entries(this.presets.filter).forEach(([k, v]) => {
|
||||||
|
|
@ -318,7 +318,6 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
clearTimeout(loadTimeout);
|
clearTimeout(loadTimeout);
|
||||||
this.toggleLoader(false);
|
this.toggleLoader(false);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleLoader(state) {
|
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');
|
const filters = ItemBrowser.getFolderConfig(this.selectedMenu.data, 'filters');
|
||||||
for (const f of filters) {
|
for (const f of filters) {
|
||||||
if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field);
|
if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field);
|
||||||
else if (typeof f.choices === 'function') {
|
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
|
// Clear field label so template uses our custom label parameter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue