Compendium Browser (#821)

This commit is contained in:
Dapoulp 2025-08-11 00:18:31 +02:00 committed by GitHub
parent b68d2e9ec2
commit f9774f130e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 74 additions and 20 deletions

View file

@ -383,7 +383,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
uuid: suggestions.armor?.uuid,
taken: suggestions.armor?.uuid === this.equipment.armor?.uuid
},
compendium: 'armors'
compendium: 'armor'
};
context.primaryWeapon = {
...this.equipment.primaryWeapon,
@ -392,7 +392,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
uuid: suggestions.primaryWeapon?.uuid,
taken: suggestions.primaryWeapon?.uuid === this.equipment.primaryWeapon?.uuid
},
compendium: 'weapons'
compendium: 'weapon'
};
context.secondaryWeapon = {
...this.equipment.secondaryWeapon,
@ -402,7 +402,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
taken: suggestions.secondaryWeapon?.uuid === this.equipment.secondaryWeapon?.uuid
},
disabled: this.equipment.primaryWeapon?.system?.burden === burden.twoHanded.value,
compendium: 'weapons'
compendium: 'weapon'
};
context.inventory = {
take: suggestions.inventory.take,
@ -500,11 +500,12 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
}
static async viewCompendium(event, target) {
const type = target.dataset.compendium ?? target.dataset.type;
const type = target.dataset.compendium ?? target.dataset.type,
equipment = ['armor', 'weapon'];
const presets = {
compendium: 'daggerheart',
folder: type,
folder: equipment.includes(type) ? "equipments" : type,
render: {
noFolder: true
}
@ -516,6 +517,12 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
'system.domain': { key: 'system.domain', value: this.setup.class?.system.domains ?? null }
};
if (equipment.includes(type))
presets.filter = {
'system.tier': { key: 'system.tier', value: 1 },
'type': { key: 'type', value: type }
};
return (this.itemBrowser = await new ItemBrowser({ presets }).render({ force: true }));
}

View file

@ -121,6 +121,16 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
}
}
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
htmlElement
.querySelectorAll('[data-action="selectFolder"]')
.forEach(element => element.addEventListener("contextmenu", (event) => {
event.target.classList.toggle('expanded');
}))
}
/* -------------------------------------------- */
/* Rendering */
/* -------------------------------------------- */
@ -179,9 +189,20 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
}
this.items = ItemBrowser.sortBy(items, 'name');
if(target) {
target.closest('.compendium-sidebar').querySelectorAll('[data-action="selectFolder"]').forEach(element => element.classList.remove("is-selected"))
target.classList.add('is-selected');
}
this.render({ force: true });
}
_replaceHTML(result, content, options) {
if(!options.isFirstRender) delete result.sidebar;
super._replaceHTML(result, content, options);
}
static expandContent(_, target) {
const parent = target.parentElement;
parent.classList.toggle('expanded');

View file

@ -325,7 +325,7 @@ export const compendiumConfig = {
"equipments": {
id: "equipments",
keys: ["armors", "weapons", "consumables", "loot"],
label: "Equipments",
label: "Equipment",
type: ["armor", "weapon", "consumable", "loot"],
listType: "items"
},