You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wanderhome-foundry-system/module/documents/actor.mjs

70 lines
2.2 KiB
JavaScript

/**
* Extend the base Actor document by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class WanderhomeActor extends Actor {
/** @override */
prepareData() {
// Prepare data for the actor. Calling the super version of this executes
// the following, in order: data reset (to clear active effects),
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
// prepareDerivedData().
super.prepareData();
}
/** @override */
prepareBaseData() {
// Data modifications in this step occur before processing embedded
// documents or derived data.
}
/**
* @override
* Augment the actor source data with additional dynamic data that isn't
* handled by the actor's DataModel. Data calculated in this step should be
* available both inside and outside of character sheets (such as if an actor
* is queried and has a roll executed directly from it).
*/
prepareDerivedData() {
const actorData = this;
const flags = actorData.flags.wanderhome || {};
}
/**
*
* @override
* Augment the actor's default getRollData() method by appending the data object
* generated by the its DataModel's getRollData(), or null. This polymorphic
* approach is useful when you have actors & items that share a parent Document,
* but have slightly different data preparation needs.
*/
getRollData() {
return { ...super.getRollData(), ...this.system.getRollData?.() ?? null };
}
/**
* Convert the actor document to a plain object.
*
* The built in `toObject()` method will ignore derived data when using Data Models.
* This additional method will instead use the spread operator to return a simplified
* version of the data.
*
* @returns {object} Plain object either via deepClone or the spread operator.
*/
toPlainObject() {
const result = {...this};
// Simplify system data.
result.system = this.system.toPlainObject();
// Add items.
result.items = this.items?.size > 0 ? this.items.contents : [];
// Add effects.
result.effects = this.effects?.size > 0 ? this.effects.contents : [];
return result;
}
}