Update get_global_class_name to use StringName.

This commit is contained in:
willnationsdev 2021-08-01 20:10:32 -05:00
parent 222df0b165
commit fc544c50e6
18 changed files with 70 additions and 127 deletions

View file

@ -381,8 +381,8 @@ public:
virtual void frame();
virtual bool handles_global_class_type(const String &p_type) const { return false; }
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const { return String(); }
virtual bool handles_global_class_type(const StringName &p_type) const { return false; }
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type = nullptr, String *r_icon_path = nullptr) const { return StringName(); }
virtual ~ScriptLanguage() {}
};

View file

@ -50,20 +50,6 @@
Returns the path to the file at index [code]idx[/code].
</description>
</method>
<method name="get_file_script_class_extends" qualifiers="const">
<return type="String" />
<argument index="0" name="idx" type="int" />
<description>
Returns the base class of the script class defined in the file at index [code]idx[/code]. If the file doesn't define a script class using the [code]class_name[/code] syntax, this will return an empty string.
</description>
</method>
<method name="get_file_script_class_name" qualifiers="const">
<return type="String" />
<argument index="0" name="idx" type="int" />
<description>
Returns the name of the script class defined in the file at index [code]idx[/code]. If the file doesn't define a script class using the [code]class_name[/code] syntax, this will return an empty string.
</description>
</method>
<method name="get_file_type" qualifiers="const">
<return type="StringName" />
<argument index="0" name="idx" type="int" />

View file

@ -24,30 +24,6 @@
Returns the [StringName] names of all global script class names known by the ScriptServer.
</description>
</method>
<method name="get_global_class_map" qualifiers="const">
<return type="Dictionary" />
<description>
Returns a Dictionary of all information known by the ScriptServer. If a project contained two GDScript files, "BaseNode" that extends [Node] and "DerivedNode" that extends "BaseNode", then the Dictionary might look like this:
[codeblock]
{
@"BaseNode": {
"language": @"GDScript",
"path": "res://base_node.gd",
"base": @"Node",
"native": @"Node",
"icon_path": "res://base_node.svg"
},
@"DerivedNode": {
"language": @"GDScript",
"path": "res://derived_node.gd",
"base": @"BaseNode",
"native": @"Node",
"icon_path": null
}
}
[/codeblock]
</description>
</method>
<method name="get_global_class_name" qualifiers="const">
<return type="StringName" />
<argument index="0" name="path" type="String" />

View file

@ -149,18 +149,6 @@ uint64_t EditorFileSystemDirectory::get_file_modified_time(int p_idx) const {
return files[p_idx]->modified_time;
}
String EditorFileSystemDirectory::get_file_script_class_name(int p_idx) const {
return files[p_idx]->script_class_name;
}
String EditorFileSystemDirectory::get_file_script_class_extends(int p_idx) const {
return files[p_idx]->script_class_extends;
}
String EditorFileSystemDirectory::get_file_script_class_icon_path(int p_idx) const {
return files[p_idx]->script_class_icon_path;
}
StringName EditorFileSystemDirectory::get_file_type(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, files.size(), "");
return files[p_idx]->type;
@ -181,8 +169,6 @@ void EditorFileSystemDirectory::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_file", "idx"), &EditorFileSystemDirectory::get_file);
ClassDB::bind_method(D_METHOD("get_file_path", "idx"), &EditorFileSystemDirectory::get_file_path);
ClassDB::bind_method(D_METHOD("get_file_type", "idx"), &EditorFileSystemDirectory::get_file_type);
ClassDB::bind_method(D_METHOD("get_file_script_class_name", "idx"), &EditorFileSystemDirectory::get_file_script_class_name);
ClassDB::bind_method(D_METHOD("get_file_script_class_extends", "idx"), &EditorFileSystemDirectory::get_file_script_class_extends);
ClassDB::bind_method(D_METHOD("get_file_import_is_valid", "idx"), &EditorFileSystemDirectory::get_file_import_is_valid);
ClassDB::bind_method(D_METHOD("get_name"), &EditorFileSystemDirectory::get_name);
ClassDB::bind_method(D_METHOD("get_path"), &EditorFileSystemDirectory::get_path);
@ -1444,38 +1430,38 @@ Vector<String> EditorFileSystem::_get_dependencies(const String &p_path) {
return ret;
}
String EditorFileSystem::_get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const {
StringName EditorFileSystem::_get_global_script_class(const String &p_type, const String &p_path, StringName *r_extends, String *r_icon_path) const {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptLanguage *lang = ScriptServer::get_language(i);
if (lang->handles_global_class_type(p_type)) {
if (lang->has_delayed_script_class_metadata() && compiled_lang_script_class_file_cache.has(p_path)) {
Dictionary d = compiled_lang_script_class_file_cache[p_path];
if (r_extends) {
*r_extends = d["base"].operator String();
*r_extends = d["base"].operator StringName();
}
if (r_icon_path) {
*r_icon_path = d.has("icon_path") ? d["icon_path"] : "";
}
return d["class"].operator String();
return d["class"].operator StringName();
} else {
return lang->get_global_class_name(p_path, r_extends, r_icon_path);
}
}
}
if (r_extends) {
*r_extends = "";
*r_extends = StringName();
}
if (r_icon_path) {
*r_icon_path = "";
}
return "";
return StringName();
}
void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) {
int filecount = p_dir->files.size();
const EditorFileSystemDirectory::FileInfo *const *files = p_dir->files.ptr();
for (int i = 0; i < filecount; i++) {
if (files[i]->script_class_name == String()) {
if (files[i]->script_class_name == StringName()) {
continue;
}
@ -1549,10 +1535,12 @@ void EditorFileSystem::init_compiled_lang_script_class_file_cache() {
}
for (int i = 0; i < script_classes.size(); i++) {
Dictionary d = script_classes[i];
StringName c = d["class"];
String p = d["path"];
StringName lg = d["language"];
if (compiled_language_names.has(lg)) {
StringName c = d["class"];
String p = d["path"];
String ip = script_class_icons[c];
d["icon_path"] = ip;
compiled_lang_script_class_file_cache[p] = d;

View file

@ -62,8 +62,8 @@ class EditorFileSystemDirectory : public Object {
String import_group_file;
Vector<String> deps;
bool verified = false; //used for checking changes
String script_class_name;
String script_class_extends;
StringName script_class_name;
StringName script_class_extends;
String script_class_icon_path;
};
@ -94,9 +94,6 @@ public:
Vector<String> get_file_deps(int p_idx) const;
bool get_file_import_is_valid(int p_idx) const;
uint64_t get_file_modified_time(int p_idx) const;
String get_file_script_class_name(int p_idx) const; //used for scripts
String get_file_script_class_extends(int p_idx) const; //used for scripts
String get_file_script_class_icon_path(int p_idx) const; //used for scripts
EditorFileSystemDirectory *get_parent();
@ -168,8 +165,8 @@ class EditorFileSystem : public Node {
Vector<String> deps;
bool import_valid = false;
String import_group_file;
String script_class_name;
String script_class_extends;
StringName script_class_name;
StringName script_class_extends;
String script_class_icon_path;
};
@ -234,7 +231,7 @@ class EditorFileSystem : public Node {
SafeFlag update_script_classes_queued;
void _queue_update_script_classes();
String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends = nullptr, String *r_icon_path = nullptr) const;
StringName _get_global_script_class(const String &p_type, const String &p_path, StringName *r_extends = nullptr, String *r_icon_path = nullptr) const;
static Error _resource_import(const String &p_path);

View file

@ -43,13 +43,13 @@
</method>
</methods>
<members>
<member name="class_name" type="String" setter="set_class_name" getter="get_class_name" default="&quot;&quot;">
<member name="class_name" type="StringName" setter="set_class_name" getter="get_class_name" default="&amp;&quot;&quot;">
</member>
<member name="library" type="GDNativeLibrary" setter="set_library" getter="get_library">
</member>
<member name="script_class_icon_path" type="String" setter="set_script_class_icon_path" getter="get_script_class_icon_path" default="&quot;&quot;">
</member>
<member name="script_class_name" type="String" setter="set_script_class_name" getter="get_script_class_name" default="&quot;&quot;">
<member name="script_class_name" type="StringName" setter="set_script_class_name" getter="get_script_class_name" default="&amp;&quot;&quot;">
</member>
</members>
</class>

View file

@ -136,11 +136,11 @@ bool NativeScript::inherits_script(const Ref<Script> &p_script) const {
return false;
}
void NativeScript::set_class_name(String p_class_name) {
void NativeScript::set_class_name(StringName p_class_name) {
class_name = p_class_name;
}
String NativeScript::get_class_name() const {
StringName NativeScript::get_class_name() const {
return class_name;
}
@ -170,11 +170,11 @@ Ref<GDNativeLibrary> NativeScript::get_library() const {
return library;
}
void NativeScript::set_script_class_name(String p_type) {
void NativeScript::set_script_class_name(StringName p_type) {
script_class_name = p_type;
}
String NativeScript::get_script_class_name() const {
StringName NativeScript::get_script_class_name() const {
return script_class_name;
}
@ -1607,13 +1607,13 @@ void NativeScriptLanguage::thread_exit() {
#endif // NO_THREADS
bool NativeScriptLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "NativeScript";
bool NativeScriptLanguage::handles_global_class_type(const StringName &p_type) const {
return p_type == SNAME("NativeScript");
}
String NativeScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
StringName NativeScriptLanguage::get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const {
if (!p_path.is_empty()) {
Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript");
Ref<NativeScript> script = ResourceLoader::load(p_path, NativeScript::get_class_static());
if (script.is_valid()) {
if (r_base_type) {
*r_base_type = script->get_instance_base_type();
@ -1624,13 +1624,13 @@ String NativeScriptLanguage::get_global_class_name(const String &p_path, String
return script->get_script_class_name();
}
if (r_base_type) {
*r_base_type = String();
*r_base_type = StringName();
}
if (r_icon_path) {
*r_icon_path = String();
}
}
return String();
return StringName();
}
void NativeReloadNode::_bind_methods() {

View file

@ -112,7 +112,7 @@ class NativeScript : public Script {
String class_name;
String script_class_name;
StringName script_class_name;
String script_class_icon_path;
Mutex owners_lock;
@ -126,14 +126,14 @@ public:
bool inherits_script(const Ref<Script> &p_script) const override;
void set_class_name(String p_class_name);
String get_class_name() const;
void set_class_name(StringName p_class_name);
StringName get_class_name() const;
void set_library(Ref<GDNativeLibrary> p_library);
Ref<GDNativeLibrary> get_library() const;
void set_script_class_name(String p_type);
String get_script_class_name() const;
void set_script_class_name(StringName p_type);
StringName get_script_class_name() const;
void set_script_class_icon_path(String p_icon_path);
String get_script_class_icon_path() const;
@ -354,8 +354,8 @@ public:
void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag);
const void *get_global_type_tag(int p_idx, StringName p_class_name) const;
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;
virtual bool handles_global_class_type(const StringName &p_type) const;
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const;
void profiling_add_data(StringName p_signature, uint64_t p_time);
};

View file

@ -419,13 +419,13 @@ void PluginScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool
#endif
}
bool PluginScriptLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "PluginScript";
bool PluginScriptLanguage::handles_global_class_type(const StringName &p_type) const {
return p_type == SNAME("PluginScript");
}
String PluginScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
StringName PluginScriptLanguage::get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const {
if (!p_path.is_empty()) {
Ref<PluginScript> script = ResourceLoader::load(p_path, "PluginScript");
Ref<PluginScript> script = ResourceLoader::load(p_path, PluginScript::get_class_static());
if (script.is_valid()) {
if (r_base_type) {
*r_base_type = script->get_instance_base_type();
@ -436,13 +436,13 @@ String PluginScriptLanguage::get_global_class_name(const String &p_path, String
return script->get_script_class_name();
}
if (r_base_type) {
*r_base_type = String();
*r_base_type = StringName();
}
if (r_icon_path) {
*r_icon_path = String();
}
}
return String();
return StringName();
}
void PluginScriptLanguage::lock() {

View file

@ -126,8 +126,8 @@ public:
/* GLOBAL CLASSES */
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 = nullptr, String *r_icon_path = nullptr) const;
virtual bool handles_global_class_type(const StringName &p_type) const;
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type = nullptr, String *r_icon_path = nullptr) const;
void lock();
void unlock();

View file

@ -2051,11 +2051,11 @@ bool GDScriptLanguage::is_control_flow_keyword(String p_keyword) const {
p_keyword == "while";
}
bool GDScriptLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "GDScript";
bool GDScriptLanguage::handles_global_class_type(const StringName &p_type) const {
return p_type == SNAME("GDScript");
}
String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
StringName GDScriptLanguage::get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const {
Vector<uint8_t> sourcef;
Error err;
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err);
@ -2140,12 +2140,12 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
break;
}
} else {
*r_base_type = "RefCounted";
*r_base_type = SNAME("RefCounted");
subclass = nullptr;
}
}
}
return c->identifier != nullptr ? String(c->identifier->name) : String();
return c->identifier != nullptr ? c->identifier->name : StringName();
}
return String();

View file

@ -498,8 +498,8 @@ public:
/* GLOBAL CLASSES */
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 = nullptr, String *r_icon_path = nullptr) const;
virtual bool handles_global_class_type(const StringName &p_type) const;
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type = nullptr, String *r_icon_path = nullptr) const;
void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);

View file

@ -264,10 +264,10 @@ bool GDScriptTestRunner::generate_class_index() {
StringName gdscript_name = GDScriptLanguage::get_singleton()->get_name();
for (int i = 0; i < tests.size(); i++) {
GDScriptTest test = tests[i];
String base_type;
StringName base_type;
String class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type);
if (class_name == String()) {
StringName class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type);
if (class_name == StringName()) {
continue;
}
ERR_FAIL_COND_V_MSG(ScriptServer::is_global_class(class_name), false,

View file

@ -566,12 +566,12 @@ String CSharpLanguage::_get_indentation() const {
return "\t";
}
bool CSharpLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "CSharpScript";
bool CSharpLanguage::handles_global_class_type(const StringName &p_type) const {
return p_type == SNAME("CSharpScript");
}
String CSharpLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
Ref<CSharpScript> script = ResourceLoader::load(p_path, "CSharpScript");
StringName CSharpLanguage::get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const {
Ref<CSharpScript> script = ResourceLoader::load(p_path, CSharpScript::get_class_static());
if (script.is_valid()) {
String name = script->get_script_class_name();
if (name.length()) {
@ -591,10 +591,10 @@ String CSharpLanguage::get_global_class_name(const String &p_path, String *r_bas
}
if (r_base_type)
*r_base_type = String();
*r_base_type = StringName();
if (r_icon_path)
*r_icon_path = String();
return String();
return StringName();
}
String CSharpLanguage::debug_get_error() const {

View file

@ -492,8 +492,8 @@ public:
virtual bool has_delayed_script_class_metadata() const override { return true; }
/* SCRIPT CLASS FUNCTIONS */
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 = NULL, String *r_icon_path = NULL) const;
virtual bool handles_global_class_type(const StringName &p_type) const;
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type = NULL, String *r_icon_path = NULL) const;
/* DEBUGGER FUNCTIONS */
String debug_get_error() const override;

View file

@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VisualScriptScriptClass" inherits="VisualScriptNode" version="4.0">
<brief_description>
A getter for global Script classes.
A Visual Script node for accessing global script classes defined in any language.
</brief_description>
<description>
Provides an easy way to refer to global classes defined in any language.
[b]Input Ports:[/b]
none
[b]Output Ports:[/b]
- \[ClassName\] (Script): [code]get[/code]
A Visual Script node for accessing global script classes defined in any language.
</description>
<tutorials>
</tutorials>

View file

@ -2254,12 +2254,12 @@ Error VisualScriptLanguage::execute_file(const String &p_path) {
void VisualScriptLanguage::finish() {
}
bool VisualScriptLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "VisualScript";
bool VisualScriptLanguage::handles_global_class_type(const StringName &p_type) const {
return p_type == SNAME("VisualScript");
}
String VisualScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
Ref<VisualScript> script = ResourceLoader::load(p_path, "VisualScript");
StringName VisualScriptLanguage::get_global_class_name(const String &p_path, StringName *r_base_type, String *r_icon_path) const {
Ref<VisualScript> script = ResourceLoader::load(p_path, VisualScript::get_class_static());
if (script.is_null()) {
if (r_base_type)
*r_base_type = StringName();

View file

@ -570,8 +570,8 @@ public:
virtual Error execute_file(const String &p_path);
virtual void finish();
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 = nullptr, String *r_icon_path = nullptr) const;
virtual bool handles_global_class_type(const StringName &p_type) const;
virtual StringName get_global_class_name(const String &p_path, StringName *r_base_type = nullptr, String *r_icon_path = nullptr) const;
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const;