godot icon indicating copy to clipboard operation
godot copied to clipboard

GDExtension expose add_move_array_element_function

Open nonameentername opened this issue 2 years ago • 8 comments

Add function to editor plugin to allow use in GDExtension

  • Bugsquad edit, closes: https://github.com/godotengine/godot-proposals/issues/8293

nonameentername avatar Oct 28 '23 22:10 nonameentername

Related godot-cpp pull request https://github.com/godotengine/godot-cpp/pull/1290

nonameentername avatar Oct 28 '23 22:10 nonameentername

I'm trying to create a GDExtension that has a similar structure to AudioStreamRandomizer.
https://github.com/godotengine/godot/blob/master/editor/plugins/audio_stream_randomizer_editor_plugin.cpp#L119

In my GDExtension I was not able to add the callback to add items to an array since the EditorNode is not available. These changes allowed me to add the callback in the GDExtension.

nonameentername avatar Oct 28 '23 22:10 nonameentername

Please open a proposal to clarify the use case for this and gauge support for this feature

AThousandShips avatar Oct 29 '23 15:10 AThousandShips

Thanks for taking a look at this. I created a proposal for this feature https://github.com/godotengine/godot-proposals/issues/8293

nonameentername avatar Oct 29 '23 17:10 nonameentername

@dsnopek Thanks for the suggestion. I updated the docs and squashed my pr.

nonameentername avatar Apr 24 '24 01:04 nonameentername

Ah, sorry, I missed that CI is complaining about a > in the docs - it gives this patch to fix:

diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml
index 9b0d239..577548e 100644
--- a/doc/classes/EditorPlugin.xml
+++ b/doc/classes/EditorPlugin.xml
@@ -507,7 +507,7 @@
 				The values of from_index and to_position in callback function determine if the array element is being added, removed or moved.
 				If from_index is [code]-1[/code] then a new element is being added.
 				If to_position is [code]-1[/code] then an element is being removed.
-				If from_index and to_position are >= 0 then they indicate the current and previous position in the array for a specific element.
+				If from_index and to_position are >= 0 then they indicate the current and previous position in the array for a specific element.
 			</description>
 		</method>
 		<method name="add_node_3d_gizmo_plugin">

dsnopek avatar Apr 24 '24 12:04 dsnopek

The API sounds a bit awkward, especially exposed in a very generic EditorPlugin. I know Godot fairly well and had no clue what a "move_array_element_function" could be in that context.

I think we might need to evaluate the API design a bit more before exposing a public API that we won't be able to change in the future. CC @KoBeWi

akien-mga avatar Apr 24 '24 12:04 akien-mga

I'm confused about this API tbh. From what I understand, it allows creating custom "property arrays", which is basically a set of properties linked by common prefix and indices in name. image What I don't get is the purpose of "move array element function". It seems to be implemented in 3 classes: AudioStreamRandomizer, TileMap and TileSet. But we have more property arrays than that - ItemList, PopupMenu, Path2D etc., they all use the same inspector UI, without defining any "move element" function.

Last time I tried, achieving property arrays using script was not possible. The classes I mentioned use ADD_ARRAY_COUNT() to create array properties. Seems like the "move element" function is for some advanced use cases? The exposed method is very obscure - the documentation explains what to do once you run into the mentioned inspector error, but doesn't say where to start to begin with.

I'd look into how "basic" property arrays work (like in the mentioned ItemList etc.) and see if it's sufficient to expose them instead. I think it's handled by some generic plugin that does it automatically, so using it should be simpler.

KoBeWi avatar Apr 24 '24 14:04 KoBeWi