9: Add formula (derived) attributes

- Added a new "Formula" attribute type for both actors and items.
- When iterating through attributes, formula attributes are noted in an
  array so that they can be iterated through in a second pass to
  evaluate their referenced attributes. The second iteration just
  handles attribute replacement rather than rolling the formula, that's
  deferred until the attributes are used in an actual roll formula.
- Items also have the same behavior. If an attribute isn't on the item,
  it will fall back to check the parent actor instead.
- Likely areas with issues would be formula attributes that reference
  other formula attributes, or item formula attributes that reference
  actor formula attributes.
This commit is contained in:
Matt Smith 2020-08-10 03:42:55 +00:00 committed by Andrew
parent 3e2a95f5f1
commit a490448a15
3 changed files with 131 additions and 14 deletions

View file

@ -20,7 +20,7 @@ export class SimpleItemSheet extends ItemSheet {
/** @override */
getData() {
const data = super.getData();
data.dtypes = ["String", "Number", "Boolean"];
data.dtypes = ["String", "Number", "Boolean", "Formula"];
for ( let attr of Object.values(data.data.attributes) ) {
attr.isCheckbox = attr.dtype === "Boolean";
}
@ -97,7 +97,7 @@ export class SimpleItemSheet extends ItemSheet {
obj[k] = v;
return obj;
}, {});
// Remove attributes which are no longer used
for ( let k of Object.keys(this.object.data.data.attributes) ) {
if ( !attributes.hasOwnProperty(k) ) attributes[`-=${k}`] = null;