summaryrefslogtreecommitdiff
path: root/editor/doc/doc_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/doc/doc_data.cpp')
-rw-r--r--editor/doc/doc_data.cpp183
1 files changed, 120 insertions, 63 deletions
diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp
index 7d2159d365..d472b41f2e 100644
--- a/editor/doc/doc_data.cpp
+++ b/editor/doc/doc_data.cpp
@@ -205,6 +205,29 @@ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const Pr
}
}
+static Variant get_documentation_default_value(const StringName &p_class_name, const StringName &p_property_name, bool &r_default_value_valid) {
+
+ Variant default_value = Variant();
+ r_default_value_valid = false;
+
+ if (ClassDB::can_instance(p_class_name)) {
+ default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid);
+ } else {
+ // Cannot get default value of classes that can't be instanced
+ List<StringName> inheriting_classes;
+ ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes);
+ for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) {
+ if (ClassDB::can_instance(E2->get())) {
+ default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid);
+ if (r_default_value_valid)
+ break;
+ }
+ }
+ }
+
+ return default_value;
+}
+
void DocData::generate(bool p_basic_types) {
List<StringName> classes;
@@ -229,22 +252,50 @@ void DocData::generate(bool p_basic_types) {
c.category = ClassDB::get_category(name);
List<PropertyInfo> properties;
+ List<PropertyInfo> own_properties;
if (name == "ProjectSettings") {
//special case for project settings, so settings can be documented
ProjectSettings::get_singleton()->get_property_list(&properties);
+ own_properties = properties;
} else {
- ClassDB::get_property_list(name, &properties, true);
+ ClassDB::get_property_list(name, &properties);
+ ClassDB::get_property_list(name, &own_properties, true);
}
+ List<PropertyInfo>::Element *EO = own_properties.front();
for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
+ bool inherited = EO == NULL;
+ if (EO && EO->get() == E->get()) {
+ inherited = false;
+ EO = EO->next();
+ }
+
if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL)
continue;
PropertyDoc prop;
+
+ prop.name = E->get().name;
+
+ prop.overridden = inherited;
+
+ bool default_value_valid = false;
+ Variant default_value = get_documentation_default_value(name, E->get().name, default_value_valid);
+
+ if (inherited) {
+ bool base_default_value_valid = false;
+ Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid);
+ if (!default_value_valid || !base_default_value_valid || default_value == base_default_value)
+ continue;
+ }
+
+ if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
+ prop.default_value = default_value.get_construct_string().replace("\n", "");
+ }
+
StringName setter = ClassDB::get_property_setter(name, E->get().name);
StringName getter = ClassDB::get_property_getter(name, E->get().name);
- prop.name = E->get().name;
prop.setter = setter;
prop.getter = getter;
@@ -301,8 +352,14 @@ void DocData::generate(bool p_basic_types) {
if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL)))
continue; //hidden, don't count
- if (skip_setter_getter_methods && setters_getters.has(E->get().name) && E->get().name.find("/") == -1)
- continue;
+ if (skip_setter_getter_methods && setters_getters.has(E->get().name)) {
+ // Don't skip parametric setters and getters, i.e. method which require
+ // one or more parameters to define what property should be set or retrieved.
+ // E.g. CPUParticles::set_param(Parameter param, float value).
+ if (E->get().arguments.size() == 0 /* getter */ || (E->get().arguments.size() == 1 && E->get().return_val.type == Variant::NIL /* setter */)) {
+ continue;
+ }
+ }
MethodDoc method;
@@ -344,21 +401,6 @@ void DocData::generate(bool p_basic_types) {
method.arguments.push_back(argument);
}
-
- /*
- String hint;
- switch(arginfo.hint) {
- case PROPERTY_HINT_DIR: hint="A directory."; break;
- case PROPERTY_HINT_RANGE: hint="Range - min: "+arginfo.hint_string.get_slice(",",0)+" max: "+arginfo.hint_string.get_slice(",",1)+" step: "+arginfo.hint_string.get_slice(",",2); break;
- case PROPERTY_HINT_ENUM: hint="Values: "; for(int j=0;j<arginfo.hint_string.get_slice_count(",");j++) { if (j>0) hint+=", "; hint+=arginfo.hint_string.get_slice(",",j)+"="+itos(j); } break;
- case PROPERTY_HINT_LENGTH: hint="Length: "+arginfo.hint_string; break;
- case PROPERTY_HINT_FLAGS: hint="Values: "; for(int j=0;j<arginfo.hint_string.get_slice_count(",");j++) { if (j>0) hint+=", "; hint+=arginfo.hint_string.get_slice(",",j)+"="+itos(1<<j); } break;
- case PROPERTY_HINT_FILE: hint="A file:"; break;
- //case PROPERTY_HINT_RESOURCE_TYPE: hint="Type: "+arginfo.hint_string; break;
- };
- if (hint!="")
- _write_string(f,4,hint);
-*/
}
c.methods.push_back(method);
@@ -412,6 +454,7 @@ void DocData::generate(bool p_basic_types) {
PropertyDoc pd;
pd.name = E->get();
pd.type = "int";
+ pd.default_value = itos(Theme::get_default()->get_constant(E->get(), cname));
c.theme_properties.push_back(pd);
}
@@ -422,6 +465,7 @@ void DocData::generate(bool p_basic_types) {
PropertyDoc pd;
pd.name = E->get();
pd.type = "Color";
+ pd.default_value = Variant(Theme::get_default()->get_color(E->get(), cname)).get_construct_string();
c.theme_properties.push_back(pd);
}
@@ -530,6 +574,7 @@ void DocData::generate(bool p_basic_types) {
PropertyDoc property;
property.name = pi.name;
property.type = Variant::get_type_name(pi.type);
+ property.default_value = v.get(pi.name).get_construct_string();
c.properties.push_back(property);
}
@@ -704,8 +749,7 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &
methods.push_back(method);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + parser->get_node_name());
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section)
@@ -725,10 +769,9 @@ Error DocData::load_classes(const String &p_dir) {
da->list_dir_begin();
String path;
- bool isdir;
- path = da->get_next(&isdir);
+ path = da->get_next();
while (path != String()) {
- if (!isdir && path.ends_with("xml")) {
+ if (!da->current_is_dir() && path.ends_with("xml")) {
Ref<XMLParser> parser = memnew(XMLParser);
Error err2 = parser->open(p_dir.plus_file(path));
if (err2)
@@ -736,7 +779,7 @@ Error DocData::load_classes(const String &p_dir) {
_load(parser);
}
- path = da->get_next(&isdir);
+ path = da->get_next();
}
da->list_dir_end();
@@ -755,13 +798,12 @@ Error DocData::erase_classes(const String &p_dir) {
da->list_dir_begin();
String path;
- bool isdir;
- path = da->get_next(&isdir);
+ path = da->get_next();
while (path != String()) {
- if (!isdir && path.ends_with("xml")) {
+ if (!da->current_is_dir() && path.ends_with("xml")) {
to_erase.push_back(path);
}
- path = da->get_next(&isdir);
+ path = da->get_next();
}
da->list_dir_end();
@@ -827,11 +869,10 @@ Error DocData::_load(Ref<XMLParser> parser) {
if (parser->get_node_type() == XMLParser::NODE_TEXT)
c.tutorials.push_back(parser->get_node_data().strip_edges());
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name3);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials")
- break; //end of <tutorials>
+ break; // End of <tutorials>.
}
} else if (name2 == "methods") {
@@ -864,17 +905,18 @@ Error DocData::_load(Ref<XMLParser> parser) {
prop2.getter = parser->get_attribute_value("getter");
if (parser->has_attribute("enum"))
prop2.enumeration = parser->get_attribute_value("enum");
- parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
- prop2.description = parser->get_node_data();
+ if (!parser->is_empty()) {
+ parser->read();
+ if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ prop2.description = parser->get_node_data();
+ }
c.properties.push_back(prop2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name3);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members")
- break; //end of <constants>
+ break; // End of <members>.
}
} else if (name2 == "theme_items") {
@@ -893,17 +935,18 @@ Error DocData::_load(Ref<XMLParser> parser) {
prop2.name = parser->get_attribute_value("name");
ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
prop2.type = parser->get_attribute_value("type");
- parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
- prop2.description = parser->get_node_data();
+ if (!parser->is_empty()) {
+ parser->read();
+ if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ prop2.description = parser->get_node_data();
+ }
c.theme_properties.push_back(prop2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name3);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items")
- break; //end of <constants>
+ break; // End of <theme_items>.
}
} else if (name2 == "constants") {
@@ -924,27 +967,27 @@ Error DocData::_load(Ref<XMLParser> parser) {
if (parser->has_attribute("enum")) {
constant2.enumeration = parser->get_attribute_value("enum");
}
- parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
- constant2.description = parser->get_node_data();
+ if (!parser->is_empty()) {
+ parser->read();
+ if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ constant2.description = parser->get_node_data();
+ }
c.constants.push_back(constant2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name3);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants")
- break; //end of <constants>
+ break; // End of <constants>.
}
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name2);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + ".");
}
} else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class")
- break; //end of <asset>
+ break; // End of <class>.
}
}
@@ -977,10 +1020,8 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
Error err;
String save_file = save_path.plus_file(c.name + ".xml");
FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err);
- if (err) {
- ERR_EXPLAIN("Can't write doc file: " + save_file);
- ERR_CONTINUE(err);
- }
+
+ ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
_write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
@@ -1063,14 +1104,23 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
for (int i = 0; i < c.properties.size(); i++) {
- String enum_text;
+ String additional_attributes;
if (c.properties[i].enumeration != String()) {
- enum_text = " enum=\"" + c.properties[i].enumeration + "\"";
+ additional_attributes += " enum=\"" + c.properties[i].enumeration + "\"";
+ }
+ if (c.properties[i].default_value != String()) {
+ additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\"";
}
+
const PropertyDoc &p = c.properties[i];
- _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + enum_text + ">");
- _write_string(f, 3, p.description.strip_edges().xml_escape());
- _write_string(f, 2, "</member>");
+
+ if (c.properties[i].overridden) {
+ _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\" override=\"true\"" + additional_attributes + " />");
+ } else {
+ _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">");
+ _write_string(f, 3, p.description.strip_edges().xml_escape());
+ _write_string(f, 2, "</member>");
+ }
}
_write_string(f, 1, "</members>");
}
@@ -1125,7 +1175,14 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
for (int i = 0; i < c.theme_properties.size(); i++) {
const PropertyDoc &p = c.theme_properties[i];
- _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">");
+
+ if (p.default_value != "")
+ _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\" default=\"" + p.default_value.xml_escape(true) + "\">");
+ else
+ _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">");
+
+ _write_string(f, 3, p.description.strip_edges().xml_escape());
+
_write_string(f, 2, "</theme_item>");
}
_write_string(f, 1, "</theme_items>");