Add code input for number props
Experimenting on this issue https://github.com/pmndrs/triplex/issues/254
This PR aims to improve the regular number input (as seen for the position, rotation, scale props) by adding a toggle to allow the user to input simple code expressions.
In this context, a valid expression is an expression that can be resolved in isolation, eg. 2 + 2, Math.PI / 2, Math.sqrt(2) and so on. If a prop contains an identifier from an external variable (myVariable * 2), it then falls under the standard unhandled category.
Recommended review path:
- Code parsing mock and test
- Expression parsing implementation and addition to type-infer
- NumberOrExpressionInput component that wraps a
NumberInputand aStringInputto allow switching between number and code inputs. - NumberOrExpressionInput implementation with the code toggle button
- String utilities : just like we don't want
undefinedto end up as a string in the code when saving, we want to save actual expressions in the code (Math.PIinstead of"Math.PI") - Prop unwrapping to ensure the preview works correctly even with wrapped expressions
To be improved : there is no visible validation as of now, if an incorrect expression is saved, the prop value is silently replaced with undefined
@benjamincloquet is attempting to deploy a commit to the Triplex Team on Vercel.
A member of the Team first needs to authorize it.
Awesome mate I'll take a look asap :-) — feel free to make comments over the PR if you think there's areas of interest!
@itsdouges hey Mike, back on this as I was away for the last weeks - I have an idea to improve this without needing a whole new component, just making the NumberInput smarter so that we don't need a manual toggle 👍 quick question, what's your preferred setup when it comes to logging debug info? I'm very new to extension development and I'm struggling to do my basic console logs. I somehow managed when I first jumped on this but I can't get it to work anymore 😭 any tips?
Console logs and viewing the developer console when building :-)
Open it with command palette!
- https://triplex.dev/docs/building-your-scene/console-logs/dev-tools
- https://triplex.dev/docs/building-your-scene/console-logs/logs