Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions module/data/action/move-context.mjs
Original file line number Diff line number Diff line change
@@ -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'; */
Expand Down Expand Up @@ -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]}
*/
Expand All @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions module/dice/d20Roll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Comment thread
WBHarry marked this conversation as resolved.
Resolved
async evaluate(options) {
const result = await super.evaluate(options);

Expand Down
3 changes: 3 additions & 0 deletions module/dice/dhRoll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 14 additions & 0 deletions module/helpers/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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])];
}
});
}
Expand Down
Loading