/** * Describes metadata about the item data model type * @typedef {Object} ItemDataModelMetadata * @property {string} label - A localizable label used on application. * @property {string} type - The system type that this data model represents. * @property {boolean} hasDescription - Indicates whether items of this type have description field * @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field * @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item */ import { addLinkedItemsDiff, getScrollTextData, updateLinkedItemApps } from '../../helpers/utils.mjs'; import { ActionsField } from '../fields/actionField.mjs'; import FormulaField from '../fields/formulaField.mjs'; const fields = foundry.data.fields; export default class BaseDataItem extends foundry.abstract.TypeDataModel { static LOCALIZATION_PREFIXES = ['DAGGERHEART.ITEMS']; /** @returns {ItemDataModelMetadata}*/ static get metadata() { return { label: 'Base Item', type: 'base', hasDescription: false, hasResource: false, isQuantifiable: false, isInventoryItem: false, hasActions: false, hasAttribution: true }; } /**@returns {ItemDataModelMetadata}*/ get metadata() { return this.constructor.metadata; } /** @inheritDoc */ static defineSchema() { const schema = { attribution: new fields.SchemaField({ source: new fields.StringField(), page: new fields.NumberField(), artist: new fields.StringField() }) }; if (this.metadata.hasDescription) schema.description = new fields.HTMLField({ required: true, nullable: true }); if (this.metadata.hasResource) { schema.resource = new fields.SchemaField( { type: new fields.StringField({ choices: CONFIG.DH.ITEM.itemResourceTypes, initial: CONFIG.DH.ITEM.itemResourceTypes.simple }), value: new fields.NumberField({ integer: true, min: 0, initial: 0 }), max: new FormulaField({ nullable: true, initial: null, deterministic: true }), icon: new fields.StringField(), recovery: new fields.StringField({ choices: CONFIG.DH.GENERAL.refreshTypes, initial: null, nullable: true }), progression: new fields.StringField({ required: true, choices: CONFIG.DH.ITEM.itemResourceProgression, initial: CONFIG.DH.ITEM.itemResourceProgression.increasing.id }), diceStates: new fields.TypedObjectField( new fields.SchemaField({ value: new fields.NumberField({ integer: true, initial: 1, min: 1 }), used: new fields.BooleanField({ initial: false }) }) ), dieFaces: new fields.StringField({ choices: CONFIG.DH.GENERAL.diceTypes, initial: CONFIG.DH.GENERAL.diceTypes.d4 }) }, { nullable: true, initial: null } ); } if (this.metadata.isQuantifiable) schema.quantity = new fields.NumberField({ integer: true, initial: 1, min: 0, required: true }); if (this.metadata.hasActions) schema.actions = new ActionsField(); return schema; } /* -------------------------------------------- */ /** * The default icon used for newly created Item documents * @type {string} */ static DEFAULT_ICON = null; /* -------------------------------------------- */ /** * Convenient access to the item's actor, if it exists. * @returns {foundry.documents.Actor | null} */ get actor() { return this.parent.actor; } get actionsList() { return this.actions; } get itemFeatures() { return []; } get attributionLabel() { if (!this.attribution) return; const { source, page } = this.attribution; return [source, page ? `pg ${page}.` : null].filter(x => x).join('. '); } /** * Augments the description for the item with type specific info to display. Implemented in applicable item subtypes. * @param {object} [options] - Options that modify the styling of the rendered template. { headerStyle: undefined|'none'|'large' } * @returns {string} */ async getDescriptionData(_options) { return { prefix: null, value: this.description, suffix: null }; } /** * Gets the enriched and augmented description for the item. * @param {object} [options] - Options that modify the styling of the rendered template. { headerStyle: undefined|'none'|'large' } * @returns {string} */ async getEnrichedDescription() { if (!this.metadata.hasDescription) return ''; const appendWithSeparator = (text, add) => { if (!add) return text; if (text) return `${text}\n