vigetlabs/storyboard

Allow basic math computations in scenes

Closed this issue · 0 comments

There's some logic in place to parse a scene's body text for {{variables}} and replace them with the values of those variables - code.

We've gotten a few requests to allow for basic math to be applied to those variables as well. Open to ideas about the best way to implement this, I think the following public API makes sense though:

{{variable1 + variable2}}
{{variable1 * variable2}}
{{variable1 / variable2}}
{{variable1 - variable2}}

# could maybe be tolerant with whitespace too, allowing for:
{{ variable1 + variable2 }}
{{ variable1+ variable2 }}

And some severely scope-creeping thoughts

It could be neat to pull in a templating library to handle the parsing of these in a predefined way (eg: https://github.com/janl/mustache.js). That might be a can of worms if we start allowing users to write executable JS that runs on other people's machines, but could be cool to allow things like:

{{ if health < 0 }}
You need some help!
{{ else }}
You're good!
{{ end }}

Could be worth exploring though as I'm sure it'll be requested down the line.

Whatever you decide

Probably about time we add some documentation about the availability of variable parsing, perhaps in the form of some helper text, or if there's more than a few words to say, then adding a page to the Tutorial component, and throwing a link near the Content field to deep link to that Tutorial page.