FEAT: new FormulaField class

FEAT: add getRollData on BaseDataItem Class
FEAT: weapon
FIX: remove inventoryWeapon field on Weapon Data Model
This commit is contained in:
Joaquin Pereyra 2025-05-31 12:46:26 -03:00
parent ec7f32cdc7
commit 527a0cd419
6 changed files with 96 additions and 18 deletions

View file

@ -24,9 +24,20 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
if (this.metadata.hasDescription)
schema.description = new fields.HTMLField({ required: true, nullable: true });
if (this.metadata.isQuantifiable)
if (this.metadata.isQuantifiable)
schema.quantity = new fields.NumberField({ integer: true, initial: 1, min: 0, required: true });
return schema;
}
/**
* Obtain a data object used to evaluate any dice rolls associated with this Item
* @param {object} [options]
* @returns {object}
*/
getRollData(options = {}) {
const actorRollData = this.parent.actor?.getRollData() ?? {};
const data = { ...actorRollData, item: { ...this } };
return data;
}
}

View file

@ -1,4 +1,5 @@
import BaseDataItem from "./base.mjs";
import FormulaField from "../fields/formulaField.mjs";
export default class DHWeapon extends BaseDataItem {
/** @inheritDoc */
@ -18,10 +19,6 @@ export default class DHWeapon extends BaseDataItem {
...super.defineSchema(),
equipped: new fields.BooleanField({ initial: false }),
//TODO: NEED REVISION
//It makes more sense to control the inventory from the actor
inventoryWeapon: new fields.NumberField({ initial: null, nullable: true, integer: true }),
//SETTINGS
secondary: new fields.BooleanField({ initial: false }),
trait: new fields.StringField({ required: true, choices: SYSTEM.ACTOR.abilities, initial: 'agility' }),
@ -30,8 +27,7 @@ export default class DHWeapon extends BaseDataItem {
//DAMAGE
damage: new fields.SchemaField({
//TODO: CREATE FORMULA FIELD
value: new fields.StringField({ initial: 'd6' }),
value: new FormulaField({ initial: 'd6' }),
type: new fields.StringField({
required: true,
choices: SYSTEM.GENERAL.damageTypes,