Supporting JSX-like reusable nodes #7111
1998marcom
started this conversation in
Scripting
Replies: 1 comment
-
I think this is a great proposal. In both frameworks, it is poor form to query the resulting tree, but React gives developers confidence in the shape of their DOM tree. Ex, I returned a Godot nodes are flexible with their children - any node can be attached to any other node from the context of any other node! In react, all children are explicit. JSX clarifies which Nodes expect children and how children are used. I could see two other approaches fitting in with godot:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have some experience with React and JSX and I really like their syntax for writing UI components/nodes.
I have written a python script that can transpile from JSX-like code to GDScript, at least for simple cases.
You can find it on my gitlab.
Example
JSX-like syntax
Equivalent-ish GDScript code
Positive aspects of a similar workflow
The actual GDScript code output of the script tests whether parents' nodes have the "add_gdx_child" method, and uses that instead of the "add_child" method:
This has the nice effect of allowing one to customize how children get added to a custom class.
Supporting a JSX-like syntax would most likely also mean solving the issue of allowing add_child overrides (see, for example, my own question here).
Example code would solve my issue as of now:
What is discussed here is kind-of related, as they are trying to build reusable containers. In GDX their problem could be tackled with:
Just like they could solve it now with GDScript by making the scenes at runtime instead of making them at compile-time with the editor.
Downsides
Human work-hours needed for proper integration with Godot and somewhat more processing time consumed, as node trees aren't created at compile time but at runtime.
Implementation
This could be a plugin that adds support for a different format of source files (say. for example, *.gdx), transpiles those sources continuously, gets the errors from the GDScript code, and puts them back at the right line in the gdx code editor.
Or it could be some enhancement directly for GDScript.
Your thoughts
Would you like to use a syntax like this? What are your thoughts?
P:S. Thanks to all contributors for all the incredible work on Godot.
Beta Was this translation helpful? Give feedback.
All reactions