Avoid fate scars update in place, with scars migrating to an integer value.

This commit is contained in:
Chris Ryan 2025-12-23 21:46:28 +10:00
parent 25646e30d6
commit d2caa5f6d9
2 changed files with 13 additions and 26 deletions

View file

@ -57,28 +57,15 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
if (config.roll.fate.value <= this.actor.system.levelData.level.current) {
// apply scarring - for now directly apply - later add a button.
console.log("Adding a scar...", this.actor.system.scars);
const scar = {
[foundry.utils.randomID()]: {
name: "A scar " + this.actor.system.scars.length,
description: "A description"
}
}
console.log("scar", scar);
const newScarAmount = this.actor.system.scars + 1;
console.log('something goes here to update the scars data...');
await this.actor.update(
{
system: {
scars: {
scar
await this.actor.update(
{
system: {
scars: newScarAmount
}
}
},
{ overwrite: true }
);
);
console.log("Adding a scar result", this.actor.system.scars);
}

View file

@ -78,12 +78,7 @@ export default class DhCharacter extends BaseDataActor {
bags: new fields.NumberField({ initial: 0, integer: true }),
chests: new fields.NumberField({ initial: 0, integer: true })
}),
scars: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField({}),
description: new fields.StringField()
})
),
scars: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.scars' }),
biography: new fields.SchemaField({
background: new fields.HTMLField(),
connections: new fields.HTMLField(),
@ -633,7 +628,7 @@ export default class DhCharacter extends BaseDataActor {
? armor.system.baseThresholds.severe + this.levelData.level.current
: this.levelData.level.current * 2
};
this.resources.hope.max -= Object.keys(this.scars).length;
this.resources.hope.max -= this.scars;
this.resources.hitPoints.max += this.class.value?.system?.hitPoints ?? 0;
}
@ -705,4 +700,9 @@ export default class DhCharacter extends BaseDataActor {
t => !!t
);
}
static migrateData(source) {
if (typeof (source.scars) === 'object') source.scars = 0;
return super.migrateData(source);
}
}