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

Registering Global Script Classes under Mono #48056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,41 @@ Map<Object *, CSharpScriptBinding>::Element *CSharpLanguage::insert_script_bindi
return script_bindings.insert(p_object, p_script_binding);
}

bool CSharpLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "CSharpScript";
}

String CSharpLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
if (!p_path.is_empty()) {
Ref<CSharpScript> script = ResourceLoader::load(p_path, "CSharpScript");

if (script.is_valid()) {
GDMonoClass *top = script->script_class;

if (top && top != script->native) {
MonoClass *parent_mono_class = mono_class_get_parent(top->get_mono_ptr());

if (r_base_type && parent_mono_class) {
*r_base_type = String::utf8(mono_class_get_name(parent_mono_class));
}

if (r_icon_path) {
*r_icon_path = script->get_script_class_icon_path();
}

return String(top->get_name());
}
}
if (r_base_type) {
*r_base_type = String();
}
if (r_icon_path) {
*r_icon_path = String();
}
}
return String();
}

void CSharpLanguage::free_instance_binding_data(void *p_data) {
if (GDMono::get_singleton() == nullptr) {
#ifdef DEBUG_ENABLED
Expand Down
11 changes: 11 additions & 0 deletions modules/mono/csharp_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class CSharpScript : public Script {

String source;
StringName name;
String _icon_path;

SelfList<CSharpScript> script_list = this;

Expand Down Expand Up @@ -202,6 +203,14 @@ class CSharpScript : public Script {
String get_source_code() const override;
void set_source_code(const String &p_code) override;

String get_script_class_name() const {
return name;
}

String get_script_class_icon_path() const {
return _icon_path;
}

#ifdef TOOLS_ENABLED
virtual const Vector<DocData::ClassDoc> &get_documentation() const override {
// TODO
Expand Down Expand Up @@ -533,6 +542,8 @@ class CSharpLanguage : public ScriptLanguage {
void free_instance_binding_data(void *p_data) override;
void refcount_incremented_instance_binding(Object *p_object) override;
bool refcount_decremented_instance_binding(Object *p_object) override;
virtual bool handles_global_class_type(const String &p_type) const;
virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const;

Map<Object *, CSharpScriptBinding>::Element *insert_script_binding(Object *p_object, const CSharpScriptBinding &p_script_binding);
bool setup_csharp_script_binding(CSharpScriptBinding &r_script_binding, Object *p_object);
Expand Down