hexus / pragma

Declarative form builder
3 stars 1 forks source link

Processing maps #2

Closed hexus closed 6 years ago

hexus commented 6 years ago

Propagation map

Denotes paths that should be copied to the keyed path. Cool. :+1:

Array values are iterated and the last non-null value is used.

Must be run before other maps, and other maps cannot use the same keys.

Customisable by merging in custom maps that users build into their sheets through the UI.

string or string[] values.

'defense.armorClass.abilityModifier': 'abilities.dex.modifier'

// or, for an outdated but relevant example of array values
'defense.armorClass.abilityModifier': ['abilities.dex.modifier', 'abilities.dex.tempModifier']

Summation map

Denotes paths that should be added to the keyed path... nice. :v:

Customisable by merging in custom maps that users build into their sheets through the UI.

string or string[] values.

'armorClass.total': ['armorClass.armorBonus', 'armorClass.shieldBonus', 'armorClass...', ...]

Customisable by merging in custom maps that users could build into their sheets through the UI.

Interpolation map

Denotes fields with values that should be interpolated from other values... tight. :ok_hand:

A flattened set of character sheet properties could be passed to these as template arguments.

A select set of Lodash functions could be made available for utility, if needed.

This wouldn't be customisable, or maybe only in an advanced mode with an expression guide.

string values.

'*.spell.damage': '{class.level}d6'

Implemented

Operation order

Interpolating ability modifiers, for example, would require need to be interpolated prior to the propagation mapping. :thinking:

The right solution would involve checking which properties are used in which maps, resolving them backwards, depth first. Properties would be processed individually as part of being processed in a list. Determining these from interpolation maps would be especially fun... it'd have to be part of the interpolation process.

This would also involve keeping track of which have already been processed (removing those processed from a temporary copy of the relevant map).

Conclusion

A domain model suddenly seems less relevant!

hexus commented 6 years ago

Pivoting the solution to generic form building.

Properties are defined in a flat list with paths that can expand to a tree. These can contain optional derivation definitions that declare a function to apply to set of arguments (which are derived from the property's current value, or the values of other properties).

The maps described above can be derived from this list easily, and aren't limited to just three functions. :+1:

Crikey, that's a lot of derivation.