mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
FIX: add again the Filter Menu implementation
This commit is contained in:
parent
09eaa0d771
commit
22dad98466
1 changed files with 96 additions and 0 deletions
|
|
@ -495,6 +495,102 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
this.document.diceRoll(config);
|
this.document.diceRoll(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
/* Filter Menus */
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
|
_createFilterMenus() {
|
||||||
|
//Menus could be a application option if needed
|
||||||
|
const menus = [
|
||||||
|
{
|
||||||
|
key: 'inventory',
|
||||||
|
container: '[data-application-part="inventory"]',
|
||||||
|
content: '.items-section',
|
||||||
|
callback: this._onMenuFilterInventory.bind(this),
|
||||||
|
target: '.filter-button',
|
||||||
|
filters: FilterMenu.invetoryFilters
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'loadout',
|
||||||
|
container: '[data-application-part="loadout"]',
|
||||||
|
content: '.items-section',
|
||||||
|
callback: this._onMenuFilterLoadout.bind(this),
|
||||||
|
target: '.filter-button',
|
||||||
|
filters: FilterMenu.cardsFilters
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
menus.forEach(m => {
|
||||||
|
const container = this.element.querySelector(m.container);
|
||||||
|
this.#menu[m.key] = new FilterMenu(container, m.target, m.filters, m.callback, {
|
||||||
|
contentSelector: m.content
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback when filters change
|
||||||
|
* @param {PointerEvent} event
|
||||||
|
* @param {HTMLElement} html
|
||||||
|
* @param {import('../ux/filter-menu.mjs').FilterItem[]} filters
|
||||||
|
*/
|
||||||
|
_onMenuFilterInventory(event, html, filters) {
|
||||||
|
this.#filteredItems.inventory.menu.clear();
|
||||||
|
|
||||||
|
for (const li of html.querySelectorAll('.inventory-item')) {
|
||||||
|
const item = this.document.items.get(li.dataset.itemId);
|
||||||
|
|
||||||
|
const matchesMenu =
|
||||||
|
filters.length === 0 || filters.some(f => foundry.applications.ux.SearchFilter.evaluateFilter(item, f));
|
||||||
|
if (matchesMenu) this.#filteredItems.inventory.menu.add(item.id);
|
||||||
|
|
||||||
|
const { search } = this.#filteredItems.inventory;
|
||||||
|
li.hidden = !(search.has(item.id) && matchesMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback when filters change
|
||||||
|
* @param {PointerEvent} event
|
||||||
|
* @param {HTMLElement} html
|
||||||
|
* @param {import('../ux/filter-menu.mjs').FilterItem[]} filters
|
||||||
|
*/
|
||||||
|
_onMenuFilterLoadout(event, html, filters) {
|
||||||
|
this.#filteredItems.loadout.menu.clear();
|
||||||
|
|
||||||
|
for (const li of html.querySelectorAll('.items-list .inventory-item, .card-list .card-item')) {
|
||||||
|
const item = this.document.items.get(li.dataset.itemId);
|
||||||
|
|
||||||
|
const matchesMenu =
|
||||||
|
filters.length === 0 || filters.some(f => foundry.applications.ux.SearchFilter.evaluateFilter(item, f));
|
||||||
|
if (matchesMenu) this.#filteredItems.loadout.menu.add(item.id);
|
||||||
|
|
||||||
|
const { search } = this.#filteredItems.loadout;
|
||||||
|
li.hidden = !(search.has(item.id) && matchesMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
|
async mapFeatureType(data, configType) {
|
||||||
|
return await Promise.all(
|
||||||
|
data.map(async x => {
|
||||||
|
const abilities = x.system.abilities
|
||||||
|
? await Promise.all(x.system.abilities.map(async x => await fromUuid(x.uuid)))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
...x,
|
||||||
|
uuid: x.uuid,
|
||||||
|
system: {
|
||||||
|
...x.system,
|
||||||
|
abilities: abilities,
|
||||||
|
type: game.i18n.localize(configType[x.system.type ?? x.type].label)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static async toggleMarks(_, button) {
|
static async toggleMarks(_, button) {
|
||||||
const markValue = Number.parseInt(button.dataset.value);
|
const markValue = Number.parseInt(button.dataset.value);
|
||||||
const newValue = this.document.system.armor.system.marks.value >= markValue ? markValue - 1 : markValue;
|
const newValue = this.document.system.armor.system.marks.value >= markValue ? markValue - 1 : markValue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue