-
Notifications
You must be signed in to change notification settings - Fork 6
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
Comments
@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. |
What kind of refactoring ?
That's some big changes and maybe suited for my need only but if you are interested don't hesitate to ask. |
I plan to get away from using the 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. |
Would be nice. 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). |
@m21-cerutti so I've made some progress: |
Oh that's great ! Did it work with array of array ? I have trouble with them. |
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. |
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.
The text was updated successfully, but these errors were encountered: