move calculation of total attributes and traits to prepareBaseData
This commit is contained in:
parent
b157cff67a
commit
61c6f6edd9
1 changed files with 13 additions and 10 deletions
|
@ -19,6 +19,18 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
|
|||
this.applyActiveEffectsToDerivedData();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareBaseData(): void {
|
||||
const data = this.data;
|
||||
const attributes = data.data.attributes;
|
||||
Object.values(attributes).forEach(
|
||||
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
|
||||
);
|
||||
|
||||
const traits = data.data.traits;
|
||||
Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
|
||||
}
|
||||
|
||||
applyActiveEffectsToNonDerivedData(): void {
|
||||
this.applyActiveEffectsFiltered((change) => !this.derivedDataProperties.includes(change.key));
|
||||
}
|
||||
|
@ -61,22 +73,13 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
|
|||
|
||||
/** @override */
|
||||
prepareDerivedData(): void {
|
||||
const data = this.data;
|
||||
const attributes = data.data.attributes;
|
||||
Object.values(attributes).forEach(
|
||||
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
|
||||
);
|
||||
|
||||
const traits = data.data.traits;
|
||||
Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
|
||||
|
||||
this._prepareCombatValues();
|
||||
}
|
||||
|
||||
/** The list of properties that are derived from others, given in dot notation */
|
||||
get derivedDataProperties(): Array<string> {
|
||||
return Object.keys(DS4.combatValues)
|
||||
.map((combatValue) => `data.combatValues.${combatValue}.base`)
|
||||
.map((combatValue) => `data.combatValues.${combatValue}.total`)
|
||||
.concat("data.combatValues.hitPoints.max");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue