move calculation of total attributes and traits to prepareBaseData

This commit is contained in:
Johannes Loher 2021-01-25 10:32:13 +01:00
parent b157cff67a
commit 61c6f6edd9

View file

@ -19,6 +19,18 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
this.applyActiveEffectsToDerivedData(); 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 { applyActiveEffectsToNonDerivedData(): void {
this.applyActiveEffectsFiltered((change) => !this.derivedDataProperties.includes(change.key)); this.applyActiveEffectsFiltered((change) => !this.derivedDataProperties.includes(change.key));
} }
@ -61,22 +73,13 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
/** @override */ /** @override */
prepareDerivedData(): void { 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(); this._prepareCombatValues();
} }
/** The list of properties that are derived from others, given in dot notation */ /** The list of properties that are derived from others, given in dot notation */
get derivedDataProperties(): Array<string> { get derivedDataProperties(): Array<string> {
return Object.keys(DS4.combatValues) return Object.keys(DS4.combatValues)
.map((combatValue) => `data.combatValues.${combatValue}.base`) .map((combatValue) => `data.combatValues.${combatValue}.total`)
.concat("data.combatValues.hitPoints.max"); .concat("data.combatValues.hitPoints.max");
} }