mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
display only class subclasses on character creation
Fixes #715 This PR fixes the issue where all subclasses are displayed in the compendium browser by allowing a fixed set of items as part of the presets passed to the ItemBrowser. Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
This commit is contained in:
parent
85982bac8c
commit
a853f150be
2 changed files with 19 additions and 10 deletions
|
|
@ -511,6 +511,10 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
'system.domain': { key: 'system.domain', value: this.setup.class?.system.domains ?? null }
|
'system.domain': { key: 'system.domain', value: this.setup.class?.system.domains ?? null }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (type === 'subclasses') {
|
||||||
|
presets.items = this.setup.class?.system.subclasses ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
return (this.itemBrowser = await new ItemBrowser({ presets }).render({ force: true }));
|
return (this.itemBrowser = await new ItemBrowser({ presets }).render({ force: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
async _preFirstRender(context, options) {
|
async _preFirstRender(context, options) {
|
||||||
if(context.presets?.render?.noFolder || context.presets?.render?.lite)
|
if(context.presets?.render?.noFolder || context.presets?.render?.lite)
|
||||||
options.position.width = 600;
|
options.position.width = 600;
|
||||||
|
|
||||||
await super._preFirstRender(context, options);
|
await super._preFirstRender(context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,13 +110,13 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
this._createSearchFilter();
|
this._createSearchFilter();
|
||||||
this._createFilterInputs();
|
this._createFilterInputs();
|
||||||
this._createDragProcess();
|
this._createDragProcess();
|
||||||
|
|
||||||
if(context.presets?.render?.lite)
|
if(context.presets?.render?.lite)
|
||||||
this.element.classList.add('lite');
|
this.element.classList.add('lite');
|
||||||
|
|
||||||
if(context.presets?.render?.noFolder)
|
if(context.presets?.render?.noFolder)
|
||||||
this.element.classList.add('no-folder');
|
this.element.classList.add('no-folder');
|
||||||
|
|
||||||
if(context.presets?.render?.noFilter)
|
if(context.presets?.render?.noFilter)
|
||||||
this.element.classList.add('no-filter');
|
this.element.classList.add('no-filter');
|
||||||
|
|
||||||
|
|
@ -183,6 +183,11 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
items = items.concat(await comp.getDocuments({ type__in: folderData.type }));
|
items = items.concat(await comp.getDocuments({ type__in: folderData.type }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.presets.items?.length > 0) {
|
||||||
|
const ids = this.presets.items.map(i => i._id);
|
||||||
|
items = items.filter(i => ids.includes(i._id));
|
||||||
|
}
|
||||||
|
|
||||||
this.items = ItemBrowser.sortBy(items, 'name');
|
this.items = ItemBrowser.sortBy(items, 'name');
|
||||||
this.render({ force: true });
|
this.render({ force: true });
|
||||||
}
|
}
|
||||||
|
|
@ -320,7 +325,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
for (const li of this.element.querySelectorAll('.item-container')) {
|
for (const li of this.element.querySelectorAll('.item-container')) {
|
||||||
const itemUUID = li.dataset.itemUuid,
|
const itemUUID = li.dataset.itemUuid,
|
||||||
item = this.items.find(i => i.uuid === itemUUID);
|
item = this.items.find(i => i.uuid === itemUUID);
|
||||||
|
|
||||||
if(!item) continue;
|
if(!item) continue;
|
||||||
|
|
||||||
const matchesMenu =
|
const matchesMenu =
|
||||||
|
|
@ -335,11 +340,11 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
li.hidden = !(search.has(item.id) && matchesMenu);
|
li.hidden = !(search.has(item.id) && matchesMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Foundry evaluateFilter doesn't allow you to match if filter values are included into item data
|
* Foundry evaluateFilter doesn't allow you to match if filter values are included into item data
|
||||||
* @param {*} obj
|
* @param {*} obj
|
||||||
* @param {*} filter
|
* @param {*} filter
|
||||||
*/
|
*/
|
||||||
static evaluateFilter(obj, filter) {
|
static evaluateFilter(obj, filter) {
|
||||||
let docValue = foundry.utils.getProperty(obj, filter.field);
|
let docValue = foundry.utils.getProperty(obj, filter.field);
|
||||||
|
|
@ -386,7 +391,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
target.closest(".item-list-header").querySelectorAll('[data-sort-key]').forEach(b => b.dataset.sortType = "");
|
target.closest(".item-list-header").querySelectorAll('[data-sort-key]').forEach(b => b.dataset.sortType = "");
|
||||||
target.dataset.sortType = type;
|
target.dataset.sortType = type;
|
||||||
|
|
||||||
const newOrder = [...itemList].reverse().sort((a, b) => {
|
const newOrder = [...itemList].reverse().sort((a, b) => {
|
||||||
const aProp = a.querySelector(`[data-item-key="${key}"]`),
|
const aProp = a.querySelector(`[data-item-key="${key}"]`),
|
||||||
bProp = b.querySelector(`[data-item-key="${key}"]`)
|
bProp = b.querySelector(`[data-item-key="${key}"]`)
|
||||||
|
|
@ -396,7 +401,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
return aProp.innerText > bProp.innerText ? 1 : -1;
|
return aProp.innerText > bProp.innerText ? 1 : -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
itemListContainer.replaceChildren(...newOrder);
|
itemListContainer.replaceChildren(...newOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue