import DHBaseActorSettings from './actor-setting.mjs'; import DHApplicationMixin from './application-mixin.mjs'; const { ActorSheetV2 } = foundry.applications.sheets; /**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */ /** * A base actor sheet extending {@link ActorSheetV2} via {@link DHApplicationMixin} * @extends ActorSheetV2 * @mixes DHSheetV2 */ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { /** @inheritDoc */ static DEFAULT_OPTIONS = { classes: ['actor'], position: { width: 480 }, form: { submitOnChange: true }, actions: { openSettings: DHBaseActorSheet.#openSettings, sendExpToChat: DHBaseActorSheet.#sendExpToChat, }, dragDrop: [] }; /* -------------------------------------------- */ /**@type {typeof DHBaseActorSettings}*/ #settingSheet; /**@returns {DHBaseActorSettings|null} */ get settingSheet() { const SheetClass = this.document.system.metadata.settingSheet; return (this.#settingSheet ??= SheetClass ? new SheetClass({ document: this.document }) : null); } /* -------------------------------------------- */ /* Prepare Context */ /* -------------------------------------------- */ /**@inheritdoc */ async _prepareContext(_options) { const context = await super._prepareContext(_options); context.isNPC = this.document.isNPC; return context; } /**@inheritdoc */ async _preparePartContext(partId, context, options) { context = await super._preparePartContext(partId, context, options); switch (partId) { case 'effects': await this._prepareEffectsContext(context, options); break; } return context; } /** * Prepare render context for the Effect part. * @param {ApplicationRenderContext} context * @param {ApplicationRenderOptions} options * @returns {Promise} * @protected */ async _prepareEffectsContext(context, _options) { context.effects = { actives: [], inactives: [], }; for (const effect of this.actor.allApplicableEffects()) { const list = effect.active ? context.effects.actives : context.effects.inactives; list.push(effect); } } /* -------------------------------------------- */ /* Application Clicks Actions */ /* -------------------------------------------- */ /** * Open the Actor Setting Sheet * @type {ApplicationClickAction} */ static async #openSettings() { await this.settingSheet.render({ force: true }); } /** * Send Experience to Chat * @type {ApplicationClickAction} */ static async #sendExpToChat(_, button) { const experience = this.document.system.experiences[button.dataset.id]; const systemData = { name: game.i18n.localize('DAGGERHEART.GENERAL.Experience.single'), description: `${experience.name} ${experience.total < 0 ? experience.total : `+${experience.total}`}` }; foundry.documents.ChatMessage.implementation.create({ type: 'abilityUse', user: game.user.id, system: systemData, content: await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/ui/chat/ability-use.hbs', systemData ) }); } }