Added get_global_class_name method to Script. Now GDScriptParser uses this first to determine global class names, instead of parsing the script file again.

This commit is contained in:
Relintai 2024-02-13 20:09:46 +01:00
parent e615073951
commit 3da74f0703
6 changed files with 18 additions and 1 deletions

View File

@ -154,6 +154,8 @@ public:
virtual void get_script_method_list(List<MethodInfo> *p_list) const = 0; virtual void get_script_method_list(List<MethodInfo> *p_list) const = 0;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const = 0; virtual void get_script_property_list(List<PropertyInfo> *p_list) const = 0;
virtual String get_global_class_name() const = 0;
virtual int get_member_line(const StringName &p_member) const { return -1; } virtual int get_member_line(const StringName &p_member) const { return -1; }
virtual void get_constants(RBMap<StringName, Variant> *p_constants) {} virtual void get_constants(RBMap<StringName, Variant> *p_constants) {}
@ -418,6 +420,8 @@ public:
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr); virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr);
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr); virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr);
virtual String get_global_class_name() const { return String(); }
PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner); PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner);
~PlaceHolderScriptInstance(); ~PlaceHolderScriptInstance();
}; };

View File

@ -239,6 +239,8 @@ public:
} }
#endif #endif
virtual String get_global_class_name() const { return name; }
CScript(); CScript();
~CScript(); ~CScript();
}; };

View File

@ -175,6 +175,8 @@ public:
virtual void get_script_method_list(List<MethodInfo> *p_list) const; virtual void get_script_method_list(List<MethodInfo> *p_list) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const; virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
virtual String get_global_class_name() const { return script_class_name; }
String get_class_documentation() const; String get_class_documentation() const;
String get_method_documentation(const StringName &p_method) const; String get_method_documentation(const StringName &p_method) const;
String get_signal_documentation(const StringName &p_signal_name) const; String get_signal_documentation(const StringName &p_signal_name) const;

View File

@ -120,6 +120,8 @@ public:
virtual int get_member_line(const StringName &p_member) const; virtual int get_member_line(const StringName &p_member) const;
virtual String get_global_class_name() const { return _name; }
PluginScript(); PluginScript();
void init(PluginScriptLanguage *language); void init(PluginScriptLanguage *language);
virtual ~PluginScript(); virtual ~PluginScript();

View File

@ -220,6 +220,8 @@ public:
virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; } virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; }
#endif #endif
virtual String get_global_class_name() const { return name; }
GDScript(); GDScript();
~GDScript(); ~GDScript();
}; };

View File

@ -4686,7 +4686,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
Ref<Script> res_script = constant; Ref<Script> res_script = constant;
StringName script_class; StringName script_class;
if (res_script.is_valid()) { if (res_script.is_valid()) {
script_class = res_script->get_language()->get_global_class_name(res_script->get_path()); script_class = res_script->get_global_class_name();
if (script_class == "") {
// Note this will currently fail for gdscript if the scripts are remapped in an exported .pck!
script_class = res_script->get_language()->get_global_class_name(res_script->get_path());
}
if (ClassDB::is_parent_class(ScriptServer::get_global_class_native_base(script_class), "Resource")) { if (ClassDB::is_parent_class(ScriptServer::get_global_class_native_base(script_class), "Resource")) {
class_name = script_class; class_name = script_class;