mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 13:11:08 +01:00
FEAT: improvement of DHApplicationMixin
FEAT: create a new DHBaseItemSheet
This commit is contained in:
parent
3464717958
commit
8574a1d93f
15 changed files with 381 additions and 162 deletions
|
|
@ -1,13 +1,14 @@
|
|||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import { weaponFeatures } from '../../../config/itemConfig.mjs';
|
||||
import { tagifyElement } from '../../../helpers/utils.mjs';
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class WeaponSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
export default class WeaponSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['weapon']
|
||||
};
|
||||
|
||||
/**@override */
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/items/weapon/header.hbs' },
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
|
|
@ -22,6 +23,7 @@ export default class WeaponSheet extends DHItemSheetV2(ItemSheetV2) {
|
|||
}
|
||||
};
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preparePartContext(partId, context) {
|
||||
super._preparePartContext(partId, context);
|
||||
|
||||
|
|
@ -34,15 +36,20 @@ export default class WeaponSheet extends DHItemSheetV2(ItemSheetV2) {
|
|||
return context;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
const featureInput = htmlElement.querySelector('.features-input');
|
||||
tagifyElement(featureInput, weaponFeatures, this.onFeatureSelect.bind(this));
|
||||
tagifyElement(featureInput, weaponFeatures, WeaponSheet.onFeatureSelect.bind(this));
|
||||
}
|
||||
|
||||
async onFeatureSelect(features) {
|
||||
await this.document.update({ 'system.features': features.map(x => ({ value: x.value })) });
|
||||
this.render(true);
|
||||
/**
|
||||
* Callback function used by `tagifyElement`.
|
||||
* @param {Array<Object>} selectedOptions - The currently selected tag objects.
|
||||
*/
|
||||
static async onFeatureSelect(selectedOptions) {
|
||||
await this.document.update({ 'system.features': selectedOptions.map(x => ({ value: x.value })) });
|
||||
this.render({ force: false, parts: ["settings"] });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue