From a46bc36dbf89aced5516d01a8467113b8825be8d Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Mon, 5 Aug 2024 08:53:58 -0700 Subject: [PATCH] [#3911] Move effect getter into AppliedEffectData initialization --- module/data/activity/base-activity.mjs | 5 ----- .../data/activity/fields/applied-effect-field.mjs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/module/data/activity/base-activity.mjs b/module/data/activity/base-activity.mjs index 8fd9679123..9e2bd2e36b 100644 --- a/module/data/activity/base-activity.mjs +++ b/module/data/activity/base-activity.mjs @@ -156,11 +156,6 @@ export default class BaseActivityData extends foundry.abstract.DataModel { prepareData() { this.name = this.name || game.i18n.localize(this.metadata?.title); this.img = this.img || this.metadata?.img; - const item = this.item; - this.effects?.forEach(e => Object.defineProperty(e, "effect", { - get() { return item.effects.get(e._id); }, - configurable: true - })); UsesField.prepareData.call(this, this.getRollData({ deterministic: true })); } diff --git a/module/data/activity/fields/applied-effect-field.mjs b/module/data/activity/fields/applied-effect-field.mjs index f20e9023c6..269157bb38 100644 --- a/module/data/activity/fields/applied-effect-field.mjs +++ b/module/data/activity/fields/applied-effect-field.mjs @@ -12,4 +12,19 @@ export default class AppliedEffectField extends SchemaField { ...fields }, options); } + + /* -------------------------------------------- */ + + /** @inheritDoc */ + initialize(value, model, options={}) { + const obj = super.initialize(value, model, options); + const item = model.item; + + Object.defineProperty(obj, "effect", { + get() { return item?.effects.get(this._id); }, + configurable: true + }); + + return obj; + } }