-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Expose PropertySelector to scripting #81488
Conversation
5e6e542
to
06913d5
Compare
You need to run |
@@ -575,7 +575,29 @@ void PropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filte | |||
type_filter = p_type_filter; | |||
} | |||
|
|||
//Variant::Type isn't exposed, so need a version that takes int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variant::Type
is exposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
Ah, I see, that makes sense!
Nevertheless, I am getting an error from ClassDB::bind_method
when I try to bind set_type_filter
instead of set_type_filter_exposable
In template: implicit instantiation of undefined template 'GetTypeInfo<const Vector<Variant::Type> &>'
Is it maybe because Variant::Type
isn't itself a Variant
so it can't be implicitly converted from Vector<Variant::Type>
to TypedArray<Variant::Type>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use TypedArray
, Vector
will only work if it's a packed case I think, as there's no direct conversion between Vector
and Array
, and no automatic conversion is done in the binds at all AFAIK, it just uses the built-in calling methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that first actually, and it also gave an error. I tried it again just now, and this is the error I get:
In template: no member named 'get_class_static' in 'Variant::Type'
Thanks for helping me out with this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Any ideas for a better comment to explain the choice? Maybe Need a version that takes int because TypedArray<Variant::Type> is not valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypedArray<int> because TypedArray<Variant::Type> is not supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize Variant::Type
couldn't be used with TypedArray<T>
. Would it be possible to make it work? If so, it'd be nice to do it before shipping this API; otherwise, we won't be able to change it later to avoid breaking compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that it's because Variant::Type
isn't a variant, and TypedArray can only hold Variants. I could be totally wrong here though. Who would be the best person to ask about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible that it's caused by a lack of enum conversion, will look into it
@@ -174,6 +175,7 @@ void register_editor_types() { | |||
GDREGISTER_CLASS(EditorResourcePicker); | |||
GDREGISTER_CLASS(EditorScriptPicker); | |||
GDREGISTER_ABSTRACT_CLASS(EditorUndoRedoManager); | |||
GDREGISTER_CLASS(PropertySelector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we tend to prefix the exposed classes with Editor
, we should consider renaming this class before exposing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Would this involve doing a refactor throughout the whole codebase? I can do that, it will just add a lot more files changed to the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to wait for the Editor team to offer their opinion since this is not my area. But I think if we decide to rename the class it should likely be done in this PR.
@@ -78,6 +78,7 @@ class PropertySelector : public ConfirmationDialog { | |||
void select_property_from_instance(Object *p_instance, const String &p_current = ""); | |||
|
|||
void set_type_filter(const Vector<Variant::Type> &p_type_filter); | |||
void set_type_filter_exposable(const Vector<int> &p_type_filter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when we need to provide another method just for the bindings we usually use the _bind
suffix, but it's not too important since this name won't be part of the public API. I think we also make these methods private and therefore prefixed with an underscore (_
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as in public set_type_filter
-> private _set_type_filter
and public set_type_filter_exposable
-> public set_type_filter_bind
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say private _set_type_filter_bind
Bind methods shouldn't be public (they are private almost always, with some exceptions that I think are mistakes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. So public set_type_filter
and private _set_type_filter_bind
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's not uniform but private methods should be prefixed by _
, they should be private to keep them internal, and communicating that it is a bind method is just a good practice to avoid any confusion.
Superseded by #81655. |
Exposed
PropertySelector
to scripting so aid addon/plugin developmentCloses godotengine/godot-proposals#7635.
Todos:
Parse Error: Native class "PropertySelector" cannot be constructed as it is abstract