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.cpp214
1 files changed, 109 insertions, 105 deletions
diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp
index 24a746d159..0f99e2ba1e 100644
--- a/editor/doc/doc_data.cpp
+++ b/editor/doc/doc_data.cpp
@@ -54,7 +54,6 @@ void DocData::merge_from(const DocData &p_data) {
c.description = cf.description;
c.brief_description = cf.brief_description;
c.tutorials = cf.tutorials;
- c.demos = cf.demos;
for (int i = 0; i < c.methods.size(); i++) {
@@ -137,9 +136,6 @@ void DocData::merge_from(const DocData &p_data) {
const PropertyDoc &pf = cf.properties[j];
p.description = pf.description;
- p.setter = pf.setter;
- p.getter = pf.getter;
-
break;
}
}
@@ -252,6 +248,28 @@ void DocData::generate(bool p_basic_types) {
prop.setter = setter;
prop.getter = getter;
+ Variant default_value = Variant();
+ bool default_value_valid = false;
+
+ if (ClassDB::can_instance(name)) {
+ default_value = ClassDB::class_get_default_property_value(name, E->get().name, &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(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(), E->get().name, &default_value_valid);
+ if (default_value_valid)
+ break;
+ }
+ }
+ }
+
+ if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
+ prop.default_value = default_value.get_construct_string().replace("\n", "");
+ }
+
bool found_type = false;
if (getter != StringName()) {
MethodBind *mb = ClassDB::get_method(name, getter);
@@ -305,8 +323,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;
@@ -348,21 +372,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);
@@ -416,6 +425,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);
}
@@ -426,6 +436,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);
}
@@ -497,9 +508,9 @@ void DocData::generate(bool p_basic_types) {
method.name = mi.name;
- for (int i = 0; i < mi.arguments.size(); i++) {
+ for (int j = 0; j < mi.arguments.size(); j++) {
- PropertyInfo arginfo = mi.arguments[i];
+ PropertyInfo arginfo = mi.arguments[j];
ArgumentDoc ad;
ad.name = arginfo.name;
@@ -509,7 +520,7 @@ void DocData::generate(bool p_basic_types) {
else
ad.type = Variant::get_type_name(arginfo.type);
- int defarg = mi.default_arguments.size() - mi.arguments.size() + i;
+ int defarg = mi.default_arguments.size() - mi.arguments.size() + j;
if (defarg >= 0)
ad.default_value = mi.default_arguments[defarg];
@@ -534,6 +545,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);
}
@@ -620,12 +632,12 @@ void DocData::generate(bool p_basic_types) {
return_doc_from_retinfo(md, mi.return_val);
- for (int i = 0; i < mi.arguments.size(); i++) {
+ for (int j = 0; j < mi.arguments.size(); j++) {
ArgumentDoc ad;
- argument_doc_from_arginfo(ad, mi.arguments[i]);
+ argument_doc_from_arginfo(ad, mi.arguments[j]);
- int darg_idx = i - (mi.arguments.size() - mi.default_arguments.size());
+ int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size());
if (darg_idx >= 0) {
Variant default_arg = E->get().default_arguments[darg_idx];
@@ -708,8 +720,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)
@@ -729,18 +740,17 @@ 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 err = parser->open(p_dir.plus_file(path));
- if (err)
- return err;
+ Error err2 = parser->open(p_dir.plus_file(path));
+ if (err2)
+ return err2;
_load(parser);
}
- path = da->get_next(&isdir);
+ path = da->get_next();
}
da->list_dir_end();
@@ -759,13 +769,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();
@@ -806,139 +815,131 @@ Error DocData::_load(Ref<XMLParser> parser) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
- String name = parser->get_node_name();
+ String name2 = parser->get_node_name();
- if (name == "brief_description") {
+ if (name2 == "brief_description") {
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT)
c.brief_description = parser->get_node_data();
- } else if (name == "description") {
+ } else if (name2 == "description") {
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT)
c.description = parser->get_node_data();
- } else if (name == "tutorials") {
+ } else if (name2 == "tutorials") {
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
- String name = parser->get_node_name();
+ String name3 = parser->get_node_name();
- if (name == "link") {
+ if (name3 == "link") {
parser->read();
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: " + name);
- 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>
}
- } else if (name == "demos") {
- parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
- c.demos = parser->get_node_data();
- } else if (name == "methods") {
+ } else if (name2 == "methods") {
- Error err = _parse_methods(parser, c.methods);
- ERR_FAIL_COND_V(err, err);
+ Error err2 = _parse_methods(parser, c.methods);
+ ERR_FAIL_COND_V(err2, err2);
- } else if (name == "signals") {
+ } else if (name2 == "signals") {
- Error err = _parse_methods(parser, c.signals);
- ERR_FAIL_COND_V(err, err);
- } else if (name == "members") {
+ Error err2 = _parse_methods(parser, c.signals);
+ ERR_FAIL_COND_V(err2, err2);
+ } else if (name2 == "members") {
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
- String name = parser->get_node_name();
+ String name3 = parser->get_node_name();
- if (name == "member") {
+ if (name3 == "member") {
- PropertyDoc prop;
+ PropertyDoc prop2;
ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
- prop.name = parser->get_attribute_value("name");
+ prop2.name = parser->get_attribute_value("name");
ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
- prop.type = parser->get_attribute_value("type");
+ prop2.type = parser->get_attribute_value("type");
if (parser->has_attribute("setter"))
- prop.setter = parser->get_attribute_value("setter");
+ prop2.setter = parser->get_attribute_value("setter");
if (parser->has_attribute("getter"))
- prop.getter = parser->get_attribute_value("getter");
+ prop2.getter = parser->get_attribute_value("getter");
if (parser->has_attribute("enum"))
- prop.enumeration = parser->get_attribute_value("enum");
+ prop2.enumeration = parser->get_attribute_value("enum");
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT)
- prop.description = parser->get_node_data();
- c.properties.push_back(prop);
+ prop2.description = parser->get_node_data();
+ c.properties.push_back(prop2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name);
- 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>
}
- } else if (name == "theme_items") {
+ } else if (name2 == "theme_items") {
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
- String name = parser->get_node_name();
+ String name3 = parser->get_node_name();
- if (name == "theme_item") {
+ if (name3 == "theme_item") {
- PropertyDoc prop;
+ PropertyDoc prop2;
ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
- prop.name = parser->get_attribute_value("name");
+ prop2.name = parser->get_attribute_value("name");
ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
- prop.type = parser->get_attribute_value("type");
+ prop2.type = parser->get_attribute_value("type");
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT)
- prop.description = parser->get_node_data();
- c.theme_properties.push_back(prop);
+ prop2.description = parser->get_node_data();
+ c.theme_properties.push_back(prop2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name);
- 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>
}
- } else if (name == "constants") {
+ } else if (name2 == "constants") {
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
- String name = parser->get_node_name();
+ String name3 = parser->get_node_name();
- if (name == "constant") {
+ if (name3 == "constant") {
- ConstantDoc constant;
+ ConstantDoc constant2;
ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
- constant.name = parser->get_attribute_value("name");
+ constant2.name = parser->get_attribute_value("name");
ERR_FAIL_COND_V(!parser->has_attribute("value"), ERR_FILE_CORRUPT);
- constant.value = parser->get_attribute_value("value");
+ constant2.value = parser->get_attribute_value("value");
if (parser->has_attribute("enum")) {
- constant.enumeration = parser->get_attribute_value("enum");
+ constant2.enumeration = parser->get_attribute_value("enum");
}
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT)
- constant.description = parser->get_node_data();
- c.constants.push_back(constant);
+ constant2.description = parser->get_node_data();
+ c.constants.push_back(constant2);
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name);
- 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")
@@ -947,8 +948,7 @@ Error DocData::_load(Ref<XMLParser> parser) {
} else {
- ERR_EXPLAIN("Invalid tag in doc file: " + name);
- 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")
@@ -985,11 +985,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_FAIL_V(err);
- }
+ ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
_write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
@@ -1015,9 +1012,6 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
_write_string(f, 2, "<link>" + c.tutorials.get(i).xml_escape() + "</link>");
}
_write_string(f, 1, "</tutorials>");
- _write_string(f, 1, "<demos>");
- _write_string(f, 2, c.demos.strip_edges().xml_escape());
- _write_string(f, 1, "</demos>");
_write_string(f, 1, "<methods>");
c.methods.sort();
@@ -1075,12 +1069,15 @@ 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, 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>");
}
@@ -1137,7 +1134,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>");