|
@@ -32,21 +32,29 @@
|
|
|
|
|
|
#include "../gdscript.h"
|
|
|
|
|
|
-String GDScriptDocGen::_get_script_path(const String &p_path) {
|
|
|
+#include "core/config/project_settings.h"
|
|
|
+
|
|
|
+HashMap<String, String> GDScriptDocGen::singletons;
|
|
|
+
|
|
|
+String GDScriptDocGen::_get_script_name(const String &p_path) {
|
|
|
+ const HashMap<String, String>::ConstIterator E = singletons.find(p_path);
|
|
|
+ if (E) {
|
|
|
+ return E->value;
|
|
|
+ }
|
|
|
return p_path.trim_prefix("res://").quote();
|
|
|
}
|
|
|
|
|
|
String GDScriptDocGen::_get_class_name(const GDP::ClassNode &p_class) {
|
|
|
const GDP::ClassNode *curr_class = &p_class;
|
|
|
if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
|
|
|
- return _get_script_path(curr_class->fqcn);
|
|
|
+ return _get_script_name(curr_class->fqcn);
|
|
|
}
|
|
|
|
|
|
String full_name = curr_class->identifier->name;
|
|
|
while (curr_class->outer) {
|
|
|
curr_class = curr_class->outer;
|
|
|
if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
|
|
|
- return vformat("%s.%s", _get_script_path(curr_class->fqcn), full_name);
|
|
|
+ return vformat("%s.%s", _get_script_name(curr_class->fqcn), full_name);
|
|
|
}
|
|
|
full_name = vformat("%s.%s", curr_class->identifier->name, full_name);
|
|
|
}
|
|
@@ -97,12 +105,12 @@ void GDScriptDocGen::_doctype_from_gdtype(const GDType &p_gdtype, String &r_type
|
|
|
return;
|
|
|
}
|
|
|
if (!p_gdtype.script_type->get_path().is_empty()) {
|
|
|
- r_type = _get_script_path(p_gdtype.script_type->get_path());
|
|
|
+ r_type = _get_script_name(p_gdtype.script_type->get_path());
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (!p_gdtype.script_path.is_empty()) {
|
|
|
- r_type = _get_script_path(p_gdtype.script_path);
|
|
|
+ r_type = _get_script_name(p_gdtype.script_path);
|
|
|
return;
|
|
|
}
|
|
|
r_type = "Object";
|
|
@@ -221,24 +229,25 @@ String GDScriptDocGen::_docvalue_from_variant(const Variant &p_variant, int p_re
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
|
|
|
+void GDScriptDocGen::_generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
|
|
|
p_script->_clear_doc();
|
|
|
|
|
|
DocData::ClassDoc &doc = p_script->doc;
|
|
|
|
|
|
- doc.script_path = _get_script_path(p_script->get_script_path());
|
|
|
+ doc.is_script_doc = true;
|
|
|
+
|
|
|
if (p_script->local_name == StringName()) {
|
|
|
- doc.name = doc.script_path;
|
|
|
+ // This is an outer unnamed class.
|
|
|
+ doc.name = _get_script_name(p_script->get_script_path());
|
|
|
} else {
|
|
|
+ // This is an inner or global outer class.
|
|
|
doc.name = p_script->local_name;
|
|
|
+ if (p_script->_owner) {
|
|
|
+ doc.name = p_script->_owner->doc.name + "." + doc.name;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (p_script->_owner) {
|
|
|
- doc.name = p_script->_owner->doc.name + "." + doc.name;
|
|
|
- doc.script_path = doc.script_path + "." + doc.name;
|
|
|
- }
|
|
|
-
|
|
|
- doc.is_script_doc = true;
|
|
|
+ doc.script_path = p_script->get_script_path();
|
|
|
|
|
|
if (p_script->base.is_valid() && p_script->base->is_valid()) {
|
|
|
if (!p_script->base->doc.name.is_empty()) {
|
|
@@ -271,7 +280,7 @@ void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_c
|
|
|
|
|
|
// Recursively generate inner class docs.
|
|
|
// Needs inner GDScripts to exist: previously generated in GDScriptCompiler::make_scripts().
|
|
|
- GDScriptDocGen::generate_docs(*p_script->subclasses[class_name], inner_class);
|
|
|
+ GDScriptDocGen::_generate_docs(*p_script->subclasses[class_name], inner_class);
|
|
|
} break;
|
|
|
|
|
|
case GDP::ClassNode::Member::CONSTANT: {
|
|
@@ -451,3 +460,13 @@ void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_c
|
|
|
// Add doc to the outer-most class.
|
|
|
p_script->_add_doc(doc);
|
|
|
}
|
|
|
+
|
|
|
+void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
|
|
|
+ for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
|
|
|
+ if (E.value.is_singleton) {
|
|
|
+ singletons[E.value.path] = E.key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _generate_docs(p_script, p_class);
|
|
|
+ singletons.clear();
|
|
|
+}
|