[GraphEdit] Make connections a property
Fixes #97015 After investigating the issue above, I found no obvious reasons why connections shouldn't be a property.
Main changes:
- The connections array is now a property and can be modified via the inspector (although that is a bit finicky due to the fact that dead/invalid connections are removed after each update, so can't add connections right now through the inspector). This means connections are now properly serialized/deserialized.
Additional refactoring/optimization:
- Use
Vectorinstead ofListinternally for connections (this also removes unreadable list element access, e.g. E->get()->...) - Make names of local variables of type
Ref<Connection>consistent (c->conn) - Method declaration order
Note: In order to avoid breaking compatibility, I kept the name get_connection_list (just for scripting), but since this name is kind of weird and GraphEdit is still experimental we could change it for consistency.
Use Vector instead of List internally for connections (this also removes unreadable list element access, e.g. E->get()->...)
You can get rid of E->get() in list too, List supports the same iteration as Vector.
If the connections are local GraphEdit (i.e. not passed anywhere), you can use LocalVector.
EDIT:
Nevermind, there is even a getter. So a Vector is fine.
Editing connections in the inspector is quite buggy. I think the property should either be hidden or readonly (with a note in the docs).
Fixed the editing in the inspector via implementing a new connection "property": keep_alive.
Connections which have keep_alive set to true won't get automatically deleted during redrawing even if they are invalid. This should also be useful in other cases.
Ideally, I would like to wait with this PR until we have structs as part of the API, but if that happens, we'd need to break compat all over the place (or have another solution at hand) so I guess it doesn't matter. Even with a array of dicts, the editing of connections feels quite nice.
Needs rebase.
Rebased.
Thanks!
-const List<Ref<GraphEdit::Connection>> &GraphEdit::get_connection_list() const {
+const Vector<Ref<GraphEdit::Connection>> &GraphEdit::get_connections() const {
This is not renamed in the scripting API, but my module uses it, so it kind of breaks compatibility, in addition to making names different between extensions and core (which we try to keep matching with PRs such as https://github.com/godotengine/godot/pull/98132).
@Zylann I guess we can rename it in the scripting API as GraphEdit is still experimental. What do you think?
If it's ok to break compat, then that would make sense.