Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InspectorArray feature #2

Closed
m21-cerutti opened this issue Mar 21, 2024 · 7 comments
Closed

InspectorArray feature #2

m21-cerutti opened this issue Mar 21, 2024 · 7 comments

Comments

@m21-cerutti
Copy link

m21-cerutti commented Mar 21, 2024

Hello,

Thank you for this useful addon, was searching to do my own for my tool but have come to a bigger solution than yours.
It would be complete if we could make it for array and have a recursive making of InspectorProperty.
If I found a way I could share it here.

@4d49
Copy link
Owner

4d49 commented Mar 22, 2024

@m21-cerutti hello!

I was planning to add array support after refactoring the code. But unfortunately I don't have time for it now :(

If you have the desire and time I will gladly accept your pull request.

@m21-cerutti
Copy link
Author

What kind of refactoring ?
Would not be linked to this issue but I am planning to :

  • Suport array (from what I found with Inspector gadget code would need a key substring to parse and get nested value inside array)
  • Make InspectorProperty in independant files with automatic loading (got it in my own solution)
  • Use scene to instantiate (because meh, we could more easily customize UI)

That's some big changes and maybe suited for my need only but if you are interested don't hesitate to ask.

@4d49
Copy link
Owner

4d49 commented Mar 23, 2024

What kind of refactoring ?

I plan to get away from using the InspectorProperty class and replace it with functions to create objects of the Control class for properties. Something like this:

static func is_valid_custom_property(property: Dictionary) -> bool:
	return true # Some custom validity check.

static func create_custom_property_control(object: Object, property: Dictionary, parent: Control) -> Control:
	return null # Return custom Control.

func _ready() -> void:
	Inspector.registry_property(is_valid_custom_property, create_custom_property_control)

This will allow the creation of "nested" properties. Also will make it relatively easy to create properties for categories and groups.

@m21-cerutti
Copy link
Author

m21-cerutti commented Mar 23, 2024

Would be nice.
For now I got some problems for creating controls due to this issue godotengine/godot#89816.
I continue to prototype on my own project for now, got a working-ish version for 1D Array but would need more development to be shared, but I use actively InspectorProperty to store a

var property: Dictionary
var data_container: Node
var data_access: PackedStringArray
var is_editable:bool

and to get/set values.

func get_value():
	if(data_access.is_empty()):
		data_access.append(property["name"])
	return _get_sub_value(data_container, data_access)

func _get_sub_value(data, access: PackedStringArray):
	if(access.is_empty()):
		return data
	if(data is Object):
		assert(access[0].is_valid_identifier())
		return _get_sub_value(data.get(access[0]), access.slice(1))
	if(data is Array):
		assert(access[0].is_valid_int())
		return _get_sub_value(data[int(access[0])], access.slice(1))
	if(data is Dictionary):
		return _get_sub_value(data.get(access[0]), access.slice(1))
	# Vector, etc
	var sub_property_path = NodePath(":".join(access))
	return data.get_indexed(sub_property_path.get_as_property_path())

func set_value(value):
	if(data_access.is_empty()):
		data_access.append(property["name"])
	data_container = _set_sub_value(data_container, data_access, value)

func _set_sub_value(data, access: PackedStringArray, value):
	if(access.is_empty()):
		return value
	if (data is Object):
		assert(access[0].is_valid_identifier())
		var newvalue = _set_sub_value(data.get(access[0]), access.slice(1), value)
		data.set(access[0], newvalue)
		return data
	elif(data is Array):
		assert(access[0].is_valid_int())
		var newvalue = _set_sub_value(data[int(access[0])], access.slice(1), value)
		data[int(access[0])] = newvalue
		return data
	elif (data is Dictionary):
		var newvalue = _set_sub_value(data[access], access.slice(1), value)
		data[access[0]] = newvalue
		return data
	# Vector, etc
	var sub_property_path = NodePath(":".join(access))
	data.set_indexed(sub_property_path.get_as_property_path(), value)
	return data

without that I am not confident that the signals would work inside arrays (when adding, removing element for example).

@4d49
Copy link
Owner

4d49 commented Mar 26, 2024

@m21-cerutti so I've made some progress:

@m21-cerutti
Copy link
Author

Oh that's great ! Did it work with array of array ? I have trouble with them.

@4d49
Copy link
Owner

4d49 commented Mar 27, 2024

Did it work with array of array ?

Unfortunately, so far I have been able to implement only typed arrays, and GDScript does not allow the use of "nested" arrays. I think it is potentially possible to force the use of "nested" arrays, but for this you will have to use custom properties.

4d49 added a commit that referenced this issue Apr 23, 2024
@4d49 4d49 closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants