diff --git a/module/data/action/move-context.mjs b/module/data/action/move-context.mjs index 5d5e73956..c98cf3739 100644 --- a/module/data/action/move-context.mjs +++ b/module/data/action/move-context.mjs @@ -1,5 +1,5 @@ import { ResourceUpdateMap } from '../actor/resource-update-map.mjs'; -import { omit } from '../../helpers/functional.mjs'; +import { omit, pick } from '../../helpers/functional.mjs'; import D20Roll from '../../dice/d20Roll.mjs'; /** @import DHBaseAction from './baseAction.mjs'; */ @@ -128,12 +128,6 @@ export class MoveContext { }, data.flags ?? {}); } - /** @deprecated */ - get data() { - foundry.utils.logCompatibilityWarning('MoveContext#data is deprecated. Use MoveContext#getRollData() instead', { since: '2.12.8' }) - return this.getRollData(); - } - /** * @returns {typeof CONFIG.Dice.daggerheart[keyof typeof CONFIG.Dice.daggerheart]} */ @@ -153,6 +147,10 @@ export class MoveContext { data.scale = this.costs?.length // Right now only return the first scalable cost. ? (this.costs.find(c => c.scalable)?.total ?? 1) : 1; + data.toJSON = () => { + // In case anyone tries to serialize this roll data, keep to a very minimal set of things + return pick(this.data, ['experiences', 'traits', 'rules', 'action', 'criticalThreshold']) + } return data; } diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 2138eb44d..e0c603f38 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -127,10 +127,6 @@ export default class D20Roll extends DHRoll { } else if (config.roll.difficulty) data.success = roll.isCritical || roll.total >= config.roll.difficulty; } - resetFormula() { - return (this._formula = this.constructor.getFormula(this.terms)); - } - async evaluate(options) { const result = await super.evaluate(options); diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index dd9b6f9ed..dd65eb0f5 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -26,6 +26,9 @@ export default class DHRoll extends BaseRoll { if (!this.data || !Object.keys(this.data).length) { this.data = options.getRollData?.() ?? options.data ?? {}; } + + // temporarily saved to allow restoring, since this.data is not persisted. Remove in 2.14.0 + options.data = this.data; } get title() { diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index bb21ef5ec..90ebfe54b 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -877,6 +877,12 @@ export function createShallowProxy(obj) { if (obj._isShallowProxy) return obj; const overrides = {}; + + // override any wrapped data models to return non-source data instead of source data + if (typeof obj.toObject === 'function' && obj.toJSON) { + overrides.toJSON = undefined; + } + return new Proxy(obj, { get(target, prop, receiver) { if (prop === '_isShallowProxy') return true; @@ -893,6 +899,14 @@ export function createShallowProxy(obj) { }, has(target, key) { return key in overrides || key in target; + }, + getOwnPropertyDescriptor(target, p) { + return Reflect.getOwnPropertyDescriptor(overrides, p) ?? Reflect.getOwnPropertyDescriptor(target, p); + }, + ownKeys(target) { + const baseKeys = Reflect.ownKeys(target); + const bonusKeys = Object.keys(overrides); + return [...new Set([...baseKeys, ...bonusKeys])]; } }); }