Initial data model update

This commit is contained in:
WBHarry 2026-07-18 00:11:48 +02:00
parent 3828337472
commit 578e6e6c76
4 changed files with 43 additions and 25 deletions

View file

@ -469,6 +469,22 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
return acc; return acc;
}, {}); }, {});
} }
if (source.damage && source.damage.resources === undefined) {
source.damage.resources = {};
for (const [partKey, part] of Object.entries(source.damage.parts)) {
if (partKey === 'hitPoints') {
source.damage.main = {
...part,
includeBase: source.damage.includeBase,
direct: source.damage.direct,
groupAttack: source.damage.groupAttack
};
} else {
source.damage.resources[partKey] = part;
}
}
}
} }
} }

View file

@ -838,7 +838,7 @@ export default class DhCharacter extends DhCreature {
isReversed: true isReversed: true
}; };
this.attack.damage.parts.hitPoints.value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`; this.attack.damage.main.value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`;
// Clamp resources (must be done last to ensure all updates occur) // Clamp resources (must be done last to ensure all updates occur)
this.resources.clamp(); this.resources.clamp();

View file

@ -11,7 +11,8 @@ export class ChatDamageData extends foundry.abstract.DataModel {
const fields = foundry.data.fields; const fields = foundry.data.fields;
return { return {
types: new fields.TypedObjectField(new fields.JSONField({validate: ChatDamageData.#validateRoll})) damage: new fields.JSONField({validate: ChatDamageData.#validateRoll}),
resources: new fields.TypedObjectField(new fields.JSONField({validate: ChatDamageData.#validateRoll}))
}; };
} }

View file

@ -13,17 +13,8 @@ export default class DamageField extends fields.SchemaField {
/** @inheritDoc */ /** @inheritDoc */
constructor(options, context = {}) { constructor(options, context = {}) {
const damageFields = { const damageFields = {
parts: new IterableTypedObjectField(DHDamageData), main: new fields.EmbeddedDataField(DHDamageData),
includeBase: new fields.BooleanField({ resources: new IterableTypedObjectField(DHResourceData)
initial: false,
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
}),
direct: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.CONFIG.DamageType.direct.name' }),
groupAttack: new fields.StringField({
choices: CONFIG.DH.GENERAL.groupAttackRange,
blank: true,
label: 'DAGGERHEART.ACTIONS.Settings.groupAttack.label'
})
}; };
super(damageFields, options, context); super(damageFields, options, context);
} }
@ -287,6 +278,18 @@ export class DHResourceData extends foundry.abstract.DataModel {
/** @override */ /** @override */
static defineSchema() { static defineSchema() {
return { return {
base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }),
type: new fields.SetField(
new fields.StringField({
choices: CONFIG.DH.GENERAL.damageTypes,
initial: 'physical',
nullable: false,
required: true
}),
{
label: game.i18n.localize('DAGGERHEART.GENERAL.type')
}
),
applyTo: new fields.StringField({ applyTo: new fields.StringField({
choices: CONFIG.DH.GENERAL.healingTypes, choices: CONFIG.DH.GENERAL.healingTypes,
required: true, required: true,
@ -309,18 +312,16 @@ export class DHDamageData extends DHResourceData {
static defineSchema() { static defineSchema() {
return { return {
...super.defineSchema(), ...super.defineSchema(),
base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }), includeBase: new fields.BooleanField({
type: new fields.SetField( initial: false,
new fields.StringField({ label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
choices: CONFIG.DH.GENERAL.damageTypes, }),
initial: 'physical', direct: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.CONFIG.DamageType.direct.name' }),
nullable: false, groupAttack: new fields.StringField({
required: true choices: CONFIG.DH.GENERAL.groupAttackRange,
}), blank: true,
{ label: 'DAGGERHEART.ACTIONS.Settings.groupAttack.label'
label: game.i18n.localize('DAGGERHEART.GENERAL.type') })
}
)
}; };
} }
} }