godot icon indicating copy to clipboard operation
godot copied to clipboard

[GraphEdit] Make connections a property

Open Geometror opened this issue 1 year ago • 5 comments

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 Vector instead of List internally 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.

Geometror avatar Sep 25 '24 14:09 Geometror

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.

KoBeWi avatar Oct 17 '24 13:10 KoBeWi

Editing connections in the inspector is quite buggy. I think the property should either be hidden or readonly (with a note in the docs).

KoBeWi avatar Oct 17 '24 14:10 KoBeWi

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.

Geometror avatar Oct 24 '24 12:10 Geometror

Needs rebase.

akien-mga avatar Dec 02 '24 16:12 akien-mga

Rebased.

Geometror avatar Dec 16 '24 01:12 Geometror

Thanks!

Repiteo avatar Dec 16 '24 18:12 Repiteo

-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 avatar Dec 20 '24 11:12 Zylann

@Zylann I guess we can rename it in the scripting API as GraphEdit is still experimental. What do you think?

Geometror avatar Dec 23 '24 15:12 Geometror

If it's ok to break compat, then that would make sense.

Zylann avatar Dec 28 '24 23:12 Zylann