-
-
Notifications
You must be signed in to change notification settings - Fork 20.8k
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
Add NativeScript support for script classes via exported script properties. #20561
Conversation
@mysticfall This is an example of an implementation of those methods. The C# one would just have to parse out the relevant info from its GDMonoClass stuff (I think, idk all the C# details). VisualScript would probably need you to add the name/icon_path as properties of VisualScript itself and then create GUI elements in the visual script editor that let the user input values for the name/icon, possibly use a FileDialog to select the desired icon, etc. Then the VisualScriptLanguage implementation would be a trivial task of loading the VisualScript and returning the member variables. Not sure about PluginScript. |
abba1cf
to
b1626f1
Compare
I think we can add an API to NativeScript 1.1 to get rid of that function call |
@karroffel In that case, you'll have to explain how the NativeScript class would access that information (to return it in the |
@willnationsdev we can add a new field to the |
@karroffel That'd be good. We'd also need a property for a file path to an icon. |
3113f84
to
5e4a48f
Compare
@karroffel I just modified this PR, so let me know what you think. I made properties "script_class_name" and "script_class_icon_path". Going to sleep now. ;-) |
ClassDB::bind_method(D_METHOD("get_class_documentation"), &NativeScript::get_class_documentation); | ||
ClassDB::bind_method(D_METHOD("get_method_documentation", "method"), &NativeScript::get_method_documentation); | ||
ClassDB::bind_method(D_METHOD("get_signal_documentation", "signal_name"), &NativeScript::get_signal_documentation); | ||
ClassDB::bind_method(D_METHOD("get_property_documentation", "path"), &NativeScript::get_property_documentation); | ||
|
||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name"); | ||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); | ||
ADD_GROUP("Script Class", "script_class"); |
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.
Isn't it common to include the trailing _
here? Not a deal breaker and the editor probably still shows it correctly 😄
} | ||
|
||
String NativeScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const { | ||
Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript"); |
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.
This actually loads and initializes the library. That's the only way you can get information like "base type", but it's still suboptimal.
This is just a comment, you don't need to change anything here, it's fine, just realized that it's a bit "meh" to load and unload libraries all the time when all you need is three strings 😄
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.
Is there perhaps a better way we should be defining / accessing these values then? Perhaps some way to directly access the data contained within the resource file itself? I mean, I could directly open up the file and parse it for the information...but that's kinda hacky.
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.
Actually, if it inherits Resource, is there a way to load it AS a Resource, rather than as a NativeScript, and then just directly access the member properties on it using .get() (assuming that doesn't also load the library)?
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 don't think so, if you just parse it as a regular resource it will dispatch to the custom code anyway AFAIK. And yeah, there's information like "base type" which you only know at runtime, unless we make the user specify it in the .gdns
file as well (would only be necessary for global classes then)
ClassDB::bind_method(D_METHOD("get_class_documentation"), &NativeScript::get_class_documentation); | ||
ClassDB::bind_method(D_METHOD("get_method_documentation", "method"), &NativeScript::get_method_documentation); | ||
ClassDB::bind_method(D_METHOD("get_signal_documentation", "signal_name"), &NativeScript::get_signal_documentation); | ||
ClassDB::bind_method(D_METHOD("get_property_documentation", "path"), &NativeScript::get_property_documentation); | ||
|
||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name"); | ||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); | ||
ADD_GROUP("Script Class", "script_class"); |
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.
Isn't it common to include the trailing _
here? Shouldn't make a difference in the editor, just wondering 😄
5e4a48f
to
2daf4de
Compare
2daf4de
to
e151476
Compare
reeeeebase :) |
Lol, gotcha. I'll get right on that in about an hour |
e151476
to
05f7173
Compare
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.
Looks good and can be merged, but this will probably make some underlying bugs (leaks) more annoying. This is probably a good thing so I have a reason to fix them more timely :)
@karroffel Ok, cool. I don't have the ability to merge things, so someone else will have to do that. ;-) |
Depends on #20560.
This enables NativeScripts to be registered as script classes by having the script in question implement String-returning methods
_get_script_class_name()
and_get_script_class_icon_path()
.Let me know what you guys think.