diff options
Diffstat (limited to 'modules/mono/csharp_script.h')
-rw-r--r-- | modules/mono/csharp_script.h | 95 |
1 files changed, 86 insertions, 9 deletions
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 401f5c62e5..14a9dc2850 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -61,12 +61,87 @@ class CSharpScript : public Script { friend class CSharpInstance; friend class CSharpLanguage; - bool tool = false; - bool global_class = false; - bool abstract_class = false; +public: + struct TypeInfo { + /** + * Name of the C# class. + */ + String class_name; + + /** + * Path to the icon that will be used for this class by the editor. + */ + String icon_path; + + /** + * Script is marked as tool and runs in the editor. + */ + bool is_tool = false; + + /** + * Script is marked as global class and will be registered in the editor. + * Registered classes can be created using certain editor dialogs and + * can be referenced by name from other languages that support the feature. + */ + bool is_global_class = false; + + /** + * Script is declared abstract. + */ + bool is_abstract = false; + + /** + * The C# type that corresponds to this script is a constructed generic type. + * E.g.: `Dictionary<int, string>` + */ + bool is_constructed_generic_type = false; + + /** + * The C# type that corresponds to this script is a generic type definition. + * E.g.: `Dictionary<,>` + */ + bool is_generic_type_definition = false; + + /** + * The C# type that corresponds to this script contains generic type parameters, + * regardless of whether the type parameters are bound or not. + */ + bool is_generic() const { + return is_constructed_generic_type || is_generic_type_definition; + } + + /** + * Check if the script can be instantiated. + * C# types can't be instantiated if they are abstract or contain generic + * type parameters, but a CSharpScript is still created for them. + */ + bool can_instantiate() const { + return !is_abstract && !is_generic_type_definition; + } + }; + +private: + /** + * Contains the C# type information for this script. + */ + TypeInfo type_info; + + /** + * Scripts are valid when the corresponding C# class is found and used + * to extract the script info using the [update_script_class_info] method. + */ bool valid = false; + /** + * Scripts extract info from the C# class in the reload methods but, + * if the reload is not invalidated, then the current extracted info + * is still valid and there's no need to reload again. + */ bool reload_invalidated = false; + /** + * Base script that this script derives from, or null if it derives from a + * native Godot class. + */ Ref<CSharpScript> base_script; HashSet<Object *> instances; @@ -87,9 +162,10 @@ class CSharpScript : public Script { HashSet<ObjectID> pending_replace_placeholders; #endif + /** + * Script source code. + */ String source; - String class_name; - String icon_path; SelfList<CSharpScript> script_list = this; @@ -166,7 +242,7 @@ public: return docs; } virtual String get_class_icon_path() const override { - return icon_path; + return type_info.icon_path; } #endif // TOOLS_ENABLED @@ -184,13 +260,13 @@ public: void get_members(HashSet<StringName> *p_members) override; bool is_tool() const override { - return tool; + return type_info.is_tool; } bool is_valid() const override { return valid; } bool is_abstract() const override { - return abstract_class; + return type_info.is_abstract; } bool inherits_script(const Ref<Script> &p_script) const override; @@ -423,7 +499,7 @@ public: void get_string_delimiters(List<String> *p_delimiters) const override; bool is_using_templates() override; virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override; - virtual Vector<ScriptTemplate> get_built_in_templates(StringName p_object) override; + virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override; /* TODO */ bool validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override { return true; @@ -478,6 +554,7 @@ public: /* TODO? */ void get_public_annotations(List<MethodInfo> *p_annotations) const override {} void reload_all_scripts() override; + void reload_scripts(const Array &p_scripts, bool p_soft_reload) override; void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override; /* LOADER FUNCTIONS */ |