doc_data.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /**************************************************************************/
  2. /* doc_data.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "doc_data.h"
  31. #include "core/engine.h"
  32. #include "core/global_constants.h"
  33. #include "core/io/compression.h"
  34. #include "core/io/marshalls.h"
  35. #include "core/os/dir_access.h"
  36. #include "core/project_settings.h"
  37. #include "core/script_language.h"
  38. #include "core/translation.h"
  39. #include "core/version.h"
  40. #include "editor/editor_settings.h"
  41. #include "scene/resources/theme.h"
  42. static String _get_indent(const String &p_text) {
  43. String indent;
  44. bool has_text = false;
  45. int line_start = 0;
  46. for (int i = 0; i < p_text.length(); i++) {
  47. const char32_t c = p_text[i];
  48. if (c == '\n') {
  49. line_start = i + 1;
  50. } else if (c > 32) {
  51. has_text = true;
  52. indent = p_text.substr(line_start, i - line_start);
  53. break; // Indentation of the first line that has text.
  54. }
  55. }
  56. if (!has_text) {
  57. return p_text;
  58. }
  59. return indent;
  60. }
  61. static String _translate_doc_string(const String &p_text) {
  62. const String indent = _get_indent(p_text);
  63. const String message = p_text.dedent().strip_edges();
  64. const String translated = TranslationServer::get_singleton()->doc_translate(message);
  65. // No need to restore stripped edges because they'll be stripped again later.
  66. return translated.indent(indent);
  67. }
  68. void DocData::merge_from(const DocData &p_data) {
  69. for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
  70. ClassDoc &c = E->get();
  71. if (!p_data.class_list.has(c.name)) {
  72. continue;
  73. }
  74. const ClassDoc &cf = p_data.class_list[c.name];
  75. c.description = cf.description;
  76. c.brief_description = cf.brief_description;
  77. c.tutorials = cf.tutorials;
  78. for (int i = 0; i < c.methods.size(); i++) {
  79. MethodDoc &m = c.methods.write[i];
  80. for (int j = 0; j < cf.methods.size(); j++) {
  81. if (cf.methods[j].name != m.name) {
  82. continue;
  83. }
  84. if (cf.methods[j].arguments.size() != m.arguments.size()) {
  85. continue;
  86. }
  87. // since polymorphic functions are allowed we need to check the type of
  88. // the arguments so we make sure they are different.
  89. int arg_count = cf.methods[j].arguments.size();
  90. Vector<bool> arg_used;
  91. arg_used.resize(arg_count);
  92. for (int l = 0; l < arg_count; ++l) {
  93. arg_used.write[l] = false;
  94. }
  95. // also there is no guarantee that argument ordering will match, so we
  96. // have to check one by one so we make sure we have an exact match
  97. for (int k = 0; k < arg_count; ++k) {
  98. for (int l = 0; l < arg_count; ++l) {
  99. if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) {
  100. arg_used.write[l] = true;
  101. break;
  102. }
  103. }
  104. }
  105. bool not_the_same = false;
  106. for (int l = 0; l < arg_count; ++l) {
  107. if (!arg_used[l]) { // at least one of the arguments was different
  108. not_the_same = true;
  109. }
  110. }
  111. if (not_the_same) {
  112. continue;
  113. }
  114. const MethodDoc &mf = cf.methods[j];
  115. m.description = mf.description;
  116. break;
  117. }
  118. }
  119. for (int i = 0; i < c.signals.size(); i++) {
  120. MethodDoc &m = c.signals.write[i];
  121. for (int j = 0; j < cf.signals.size(); j++) {
  122. if (cf.signals[j].name != m.name) {
  123. continue;
  124. }
  125. const MethodDoc &mf = cf.signals[j];
  126. m.description = mf.description;
  127. break;
  128. }
  129. }
  130. for (int i = 0; i < c.constants.size(); i++) {
  131. ConstantDoc &m = c.constants.write[i];
  132. for (int j = 0; j < cf.constants.size(); j++) {
  133. if (cf.constants[j].name != m.name) {
  134. continue;
  135. }
  136. const ConstantDoc &mf = cf.constants[j];
  137. m.description = mf.description;
  138. break;
  139. }
  140. }
  141. for (int i = 0; i < c.properties.size(); i++) {
  142. PropertyDoc &p = c.properties.write[i];
  143. for (int j = 0; j < cf.properties.size(); j++) {
  144. if (cf.properties[j].name != p.name) {
  145. continue;
  146. }
  147. const PropertyDoc &pf = cf.properties[j];
  148. p.description = pf.description;
  149. break;
  150. }
  151. }
  152. for (int i = 0; i < c.theme_properties.size(); i++) {
  153. ThemeItemDoc &ti = c.theme_properties.write[i];
  154. for (int j = 0; j < cf.theme_properties.size(); j++) {
  155. if (cf.theme_properties[j].name != ti.name || cf.theme_properties[j].data_type != ti.data_type) {
  156. continue;
  157. }
  158. const ThemeItemDoc &pf = cf.theme_properties[j];
  159. ti.description = pf.description;
  160. break;
  161. }
  162. }
  163. }
  164. }
  165. void DocData::remove_from(const DocData &p_data) {
  166. for (Map<String, ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) {
  167. if (class_list.has(E->key())) {
  168. class_list.erase(E->key());
  169. }
  170. }
  171. }
  172. static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
  173. if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  174. p_method.return_enum = p_retinfo.class_name;
  175. if (p_method.return_enum.begins_with("_")) { //proxy class
  176. p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
  177. }
  178. p_method.return_type = "int";
  179. } else if (p_retinfo.class_name != StringName()) {
  180. p_method.return_type = p_retinfo.class_name;
  181. } else if (p_retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  182. p_method.return_type = p_retinfo.hint_string;
  183. } else if (p_retinfo.type == Variant::NIL && p_retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
  184. p_method.return_type = "Variant";
  185. } else if (p_retinfo.type == Variant::NIL) {
  186. p_method.return_type = "void";
  187. } else {
  188. p_method.return_type = Variant::get_type_name(p_retinfo.type);
  189. }
  190. }
  191. static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo) {
  192. p_argument.name = p_arginfo.name;
  193. if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  194. p_argument.enumeration = p_arginfo.class_name;
  195. if (p_argument.enumeration.begins_with("_")) { //proxy class
  196. p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
  197. }
  198. p_argument.type = "int";
  199. } else if (p_arginfo.class_name != StringName()) {
  200. p_argument.type = p_arginfo.class_name;
  201. } else if (p_arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  202. p_argument.type = p_arginfo.hint_string;
  203. } else if (p_arginfo.type == Variant::NIL) {
  204. // Parameters cannot be void, so PROPERTY_USAGE_NIL_IS_VARIANT is not necessary
  205. p_argument.type = "Variant";
  206. } else {
  207. p_argument.type = Variant::get_type_name(p_arginfo.type);
  208. }
  209. }
  210. static Variant get_documentation_default_value(const StringName &p_class_name, const StringName &p_property_name, bool &r_default_value_valid) {
  211. Variant default_value = Variant();
  212. r_default_value_valid = false;
  213. if (ClassDB::can_instance(p_class_name)) {
  214. default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid);
  215. } else {
  216. // Cannot get default value of classes that can't be instanced
  217. List<StringName> inheriting_classes;
  218. ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes);
  219. for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) {
  220. if (ClassDB::can_instance(E2->get())) {
  221. default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid);
  222. if (r_default_value_valid) {
  223. break;
  224. }
  225. }
  226. }
  227. }
  228. return default_value;
  229. }
  230. void DocData::generate(bool p_basic_types) {
  231. List<StringName> classes;
  232. ClassDB::get_class_list(&classes);
  233. classes.sort_custom<StringName::AlphCompare>();
  234. // Move ProjectSettings, so that other classes can register properties there.
  235. classes.move_to_back(classes.find("ProjectSettings"));
  236. bool skip_setter_getter_methods = true;
  237. while (classes.size()) {
  238. Set<StringName> setters_getters;
  239. String name = classes.front()->get();
  240. if (!ClassDB::is_class_exposed(name)) {
  241. print_verbose(vformat("Class '%s' is not exposed, skipping.", name));
  242. classes.pop_front();
  243. continue;
  244. }
  245. String cname = name;
  246. if (cname.begins_with("_")) { //proxy class
  247. cname = cname.substr(1, name.length());
  248. }
  249. class_list[cname] = ClassDoc();
  250. ClassDoc &c = class_list[cname];
  251. c.name = cname;
  252. c.inherits = ClassDB::get_parent_class(name);
  253. List<PropertyInfo> properties;
  254. List<PropertyInfo> own_properties;
  255. // Special case for editor and project settings, so they can be documented.
  256. if (name == "EditorSettings") {
  257. // We don't create the full blown EditorSettings (+ config file) with `create()`,
  258. // instead we just make a local instance to get default values.
  259. Ref<EditorSettings> edset = memnew(EditorSettings);
  260. edset->get_property_list(&properties);
  261. own_properties = properties;
  262. } else if (name == "ProjectSettings") {
  263. ProjectSettings::get_singleton()->get_property_list(&properties);
  264. own_properties = properties;
  265. } else {
  266. ClassDB::get_property_list(name, &properties);
  267. ClassDB::get_property_list(name, &own_properties, true);
  268. }
  269. List<PropertyInfo>::Element *EO = own_properties.front();
  270. for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
  271. bool inherited = EO == nullptr;
  272. if (EO && EO->get() == E->get()) {
  273. inherited = false;
  274. EO = EO->next();
  275. }
  276. if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) {
  277. continue;
  278. }
  279. PropertyDoc prop;
  280. prop.name = E->get().name;
  281. prop.overridden = inherited;
  282. if (inherited) {
  283. String parent = ClassDB::get_parent_class(c.name);
  284. while (!ClassDB::has_property(parent, prop.name, true)) {
  285. parent = ClassDB::get_parent_class(parent);
  286. }
  287. prop.overrides = parent;
  288. }
  289. bool default_value_valid = false;
  290. Variant default_value;
  291. if (name == "EditorSettings") {
  292. if (E->get().name == "resource_local_to_scene" || E->get().name == "resource_name" || E->get().name == "resource_path" || E->get().name == "script") {
  293. // Don't include spurious properties in the generated EditorSettings class reference.
  294. continue;
  295. }
  296. }
  297. if (name == "ProjectSettings") {
  298. // Special case for project settings, so that settings are not taken from the current project's settings
  299. if (E->get().name == "script" ||
  300. ProjectSettings::get_singleton()->get_order(E->get().name) >= ProjectSettings::NO_BUILTIN_ORDER_BASE) {
  301. continue;
  302. }
  303. if (E->get().usage & PROPERTY_USAGE_EDITOR) {
  304. if (!ProjectSettings::get_singleton()->get_ignore_value_in_docs(E->get().name)) {
  305. default_value = ProjectSettings::get_singleton()->property_get_revert(E->get().name);
  306. default_value_valid = true;
  307. }
  308. }
  309. } else {
  310. default_value = get_documentation_default_value(name, E->get().name, default_value_valid);
  311. if (inherited) {
  312. bool base_default_value_valid = false;
  313. Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid);
  314. if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) {
  315. continue;
  316. }
  317. }
  318. }
  319. if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
  320. prop.default_value = default_value.get_construct_string().replace("\n", "");
  321. }
  322. StringName setter = ClassDB::get_property_setter(name, E->get().name);
  323. StringName getter = ClassDB::get_property_getter(name, E->get().name);
  324. prop.setter = setter;
  325. prop.getter = getter;
  326. bool found_type = false;
  327. if (getter != StringName()) {
  328. MethodBind *mb = ClassDB::get_method(name, getter);
  329. if (mb) {
  330. PropertyInfo retinfo = mb->get_return_info();
  331. found_type = true;
  332. if (retinfo.type == Variant::INT && retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  333. prop.enumeration = retinfo.class_name;
  334. if (prop.enumeration.begins_with("_")) { //proxy class
  335. prop.enumeration = prop.enumeration.substr(1, prop.enumeration.length());
  336. }
  337. prop.type = "int";
  338. } else if (retinfo.class_name != StringName()) {
  339. prop.type = retinfo.class_name;
  340. } else if (retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  341. prop.type = retinfo.hint_string;
  342. } else if (retinfo.type == Variant::NIL && retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
  343. prop.type = "Variant";
  344. } else if (retinfo.type == Variant::NIL) {
  345. prop.type = "void";
  346. } else {
  347. prop.type = Variant::get_type_name(retinfo.type);
  348. }
  349. }
  350. setters_getters.insert(getter);
  351. }
  352. if (setter != StringName()) {
  353. setters_getters.insert(setter);
  354. }
  355. if (!found_type) {
  356. if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
  357. prop.type = E->get().hint_string;
  358. } else {
  359. prop.type = Variant::get_type_name(E->get().type);
  360. }
  361. }
  362. c.properties.push_back(prop);
  363. }
  364. List<MethodInfo> method_list;
  365. ClassDB::get_method_list(name, &method_list, true);
  366. method_list.sort();
  367. for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
  368. if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) {
  369. continue; //hidden, don't count
  370. }
  371. if (skip_setter_getter_methods && setters_getters.has(E->get().name)) {
  372. // Don't skip parametric setters and getters, i.e. method which require
  373. // one or more parameters to define what property should be set or retrieved.
  374. // E.g. CPUParticles::set_param(Parameter param, float value).
  375. if (E->get().arguments.size() == 0 /* getter */ || (E->get().arguments.size() == 1 && E->get().return_val.type == Variant::NIL /* setter */)) {
  376. continue;
  377. }
  378. }
  379. MethodDoc method;
  380. method.name = E->get().name;
  381. if (E->get().flags & METHOD_FLAG_VIRTUAL) {
  382. method.qualifiers = "virtual";
  383. }
  384. if (E->get().flags & METHOD_FLAG_CONST) {
  385. if (method.qualifiers != "") {
  386. method.qualifiers += " ";
  387. }
  388. method.qualifiers += "const";
  389. } else if (E->get().flags & METHOD_FLAG_VARARG) {
  390. if (method.qualifiers != "") {
  391. method.qualifiers += " ";
  392. }
  393. method.qualifiers += "vararg";
  394. }
  395. for (int i = -1; i < E->get().arguments.size(); i++) {
  396. if (i == -1) {
  397. #ifdef DEBUG_METHODS_ENABLED
  398. return_doc_from_retinfo(method, E->get().return_val);
  399. #endif
  400. } else {
  401. const PropertyInfo &arginfo = E->get().arguments[i];
  402. ArgumentDoc argument;
  403. argument_doc_from_arginfo(argument, arginfo);
  404. int darg_idx = i - (E->get().arguments.size() - E->get().default_arguments.size());
  405. if (darg_idx >= 0) {
  406. Variant default_arg = E->get().default_arguments[darg_idx];
  407. argument.default_value = default_arg.get_construct_string();
  408. }
  409. method.arguments.push_back(argument);
  410. }
  411. }
  412. c.methods.push_back(method);
  413. }
  414. List<MethodInfo> signal_list;
  415. ClassDB::get_signal_list(name, &signal_list, true);
  416. if (signal_list.size()) {
  417. for (List<MethodInfo>::Element *EV = signal_list.front(); EV; EV = EV->next()) {
  418. MethodDoc signal;
  419. signal.name = EV->get().name;
  420. for (int i = 0; i < EV->get().arguments.size(); i++) {
  421. const PropertyInfo &arginfo = EV->get().arguments[i];
  422. ArgumentDoc argument;
  423. argument_doc_from_arginfo(argument, arginfo);
  424. signal.arguments.push_back(argument);
  425. }
  426. c.signals.push_back(signal);
  427. }
  428. }
  429. List<String> constant_list;
  430. ClassDB::get_integer_constant_list(name, &constant_list, true);
  431. for (List<String>::Element *E = constant_list.front(); E; E = E->next()) {
  432. ConstantDoc constant;
  433. constant.name = E->get();
  434. constant.value = itos(ClassDB::get_integer_constant(name, E->get()));
  435. constant.is_value_valid = true;
  436. constant.enumeration = ClassDB::get_integer_constant_enum(name, E->get());
  437. c.constants.push_back(constant);
  438. }
  439. // Theme items.
  440. {
  441. List<StringName> l;
  442. Theme::get_default()->get_color_list(cname, &l);
  443. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  444. ThemeItemDoc tid;
  445. tid.name = E->get();
  446. tid.type = "Color";
  447. tid.data_type = "color";
  448. tid.default_value = Variant(Theme::get_default()->get_color(E->get(), cname)).get_construct_string();
  449. c.theme_properties.push_back(tid);
  450. }
  451. l.clear();
  452. Theme::get_default()->get_constant_list(cname, &l);
  453. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  454. ThemeItemDoc tid;
  455. tid.name = E->get();
  456. tid.type = "int";
  457. tid.data_type = "constant";
  458. tid.default_value = itos(Theme::get_default()->get_constant(E->get(), cname));
  459. c.theme_properties.push_back(tid);
  460. }
  461. l.clear();
  462. Theme::get_default()->get_font_list(cname, &l);
  463. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  464. ThemeItemDoc tid;
  465. tid.name = E->get();
  466. tid.type = "Font";
  467. tid.data_type = "font";
  468. c.theme_properties.push_back(tid);
  469. }
  470. l.clear();
  471. Theme::get_default()->get_icon_list(cname, &l);
  472. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  473. ThemeItemDoc tid;
  474. tid.name = E->get();
  475. tid.type = "Texture";
  476. tid.data_type = "icon";
  477. c.theme_properties.push_back(tid);
  478. }
  479. l.clear();
  480. Theme::get_default()->get_stylebox_list(cname, &l);
  481. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  482. ThemeItemDoc tid;
  483. tid.name = E->get();
  484. tid.type = "StyleBox";
  485. tid.data_type = "style";
  486. c.theme_properties.push_back(tid);
  487. }
  488. c.theme_properties.sort();
  489. }
  490. classes.pop_front();
  491. }
  492. {
  493. // So we can document the concept of Variant even if it's not a usable class per se.
  494. class_list["Variant"] = ClassDoc();
  495. class_list["Variant"].name = "Variant";
  496. }
  497. if (!p_basic_types) {
  498. return;
  499. }
  500. // Add Variant types.
  501. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  502. if (i == Variant::NIL) {
  503. continue; // Not exposed outside of 'null', should not be in class list.
  504. }
  505. if (i == Variant::OBJECT) {
  506. continue; // Use the core type instead.
  507. }
  508. String cname = Variant::get_type_name(Variant::Type(i));
  509. class_list[cname] = ClassDoc();
  510. ClassDoc &c = class_list[cname];
  511. c.name = cname;
  512. Variant::CallError cerror;
  513. Variant v = Variant::construct(Variant::Type(i), nullptr, 0, cerror);
  514. List<MethodInfo> method_list;
  515. v.get_method_list(&method_list);
  516. method_list.sort();
  517. Variant::get_constructor_list(Variant::Type(i), &method_list);
  518. for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
  519. MethodInfo &mi = E->get();
  520. MethodDoc method;
  521. method.name = mi.name;
  522. for (int j = 0; j < mi.arguments.size(); j++) {
  523. PropertyInfo arginfo = mi.arguments[j];
  524. ArgumentDoc ad;
  525. argument_doc_from_arginfo(ad, mi.arguments[j]);
  526. ad.name = arginfo.name;
  527. int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j;
  528. if (darg_idx >= 0) {
  529. Variant default_arg = mi.default_arguments[darg_idx];
  530. ad.default_value = default_arg.get_construct_string();
  531. }
  532. method.arguments.push_back(ad);
  533. }
  534. if (mi.return_val.type == Variant::NIL) {
  535. if (mi.return_val.name != "") {
  536. method.return_type = "Variant";
  537. }
  538. } else {
  539. method.return_type = Variant::get_type_name(mi.return_val.type);
  540. }
  541. c.methods.push_back(method);
  542. }
  543. List<PropertyInfo> properties;
  544. v.get_property_list(&properties);
  545. for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
  546. PropertyInfo pi = E->get();
  547. PropertyDoc property;
  548. property.name = pi.name;
  549. property.type = Variant::get_type_name(pi.type);
  550. property.default_value = v.get(pi.name).get_construct_string();
  551. c.properties.push_back(property);
  552. }
  553. List<StringName> constants;
  554. Variant::get_constants_for_type(Variant::Type(i), &constants);
  555. for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
  556. ConstantDoc constant;
  557. constant.name = E->get();
  558. Variant value = Variant::get_constant_value(Variant::Type(i), E->get());
  559. constant.value = value.get_type() == Variant::INT ? itos(value) : value.get_construct_string();
  560. constant.is_value_valid = true;
  561. c.constants.push_back(constant);
  562. }
  563. }
  564. //built in constants and functions
  565. {
  566. String cname = "@GlobalScope";
  567. class_list[cname] = ClassDoc();
  568. ClassDoc &c = class_list[cname];
  569. c.name = cname;
  570. for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) {
  571. ConstantDoc cd;
  572. cd.name = GlobalConstants::get_global_constant_name(i);
  573. if (!GlobalConstants::get_ignore_value_in_docs(i)) {
  574. cd.value = itos(GlobalConstants::get_global_constant_value(i));
  575. cd.is_value_valid = true;
  576. } else {
  577. cd.is_value_valid = false;
  578. }
  579. cd.enumeration = GlobalConstants::get_global_constant_enum(i);
  580. c.constants.push_back(cd);
  581. }
  582. List<Engine::Singleton> singletons;
  583. Engine::get_singleton()->get_singletons(&singletons);
  584. //servers (this is kind of hackish)
  585. for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
  586. PropertyDoc pd;
  587. Engine::Singleton &s = E->get();
  588. if (!s.ptr) {
  589. continue;
  590. }
  591. pd.name = s.name;
  592. pd.type = s.ptr->get_class();
  593. while (String(ClassDB::get_parent_class(pd.type)) != "Object") {
  594. pd.type = ClassDB::get_parent_class(pd.type);
  595. }
  596. if (pd.type.begins_with("_")) {
  597. pd.type = pd.type.substr(1, pd.type.length());
  598. }
  599. c.properties.push_back(pd);
  600. }
  601. }
  602. // Built-in script reference.
  603. // We only add a doc entry for languages which actually define any built-in
  604. // methods or constants.
  605. {
  606. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  607. ScriptLanguage *lang = ScriptServer::get_language(i);
  608. String cname = "@" + lang->get_name();
  609. ClassDoc c;
  610. c.name = cname;
  611. // Get functions.
  612. List<MethodInfo> minfo;
  613. lang->get_public_functions(&minfo);
  614. for (List<MethodInfo>::Element *E = minfo.front(); E; E = E->next()) {
  615. MethodInfo &mi = E->get();
  616. MethodDoc md;
  617. md.name = mi.name;
  618. if (mi.flags & METHOD_FLAG_VARARG) {
  619. if (md.qualifiers != "") {
  620. md.qualifiers += " ";
  621. }
  622. md.qualifiers += "vararg";
  623. }
  624. return_doc_from_retinfo(md, mi.return_val);
  625. for (int j = 0; j < mi.arguments.size(); j++) {
  626. ArgumentDoc ad;
  627. argument_doc_from_arginfo(ad, mi.arguments[j]);
  628. int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size());
  629. if (darg_idx >= 0) {
  630. Variant default_arg = E->get().default_arguments[darg_idx];
  631. ad.default_value = default_arg.get_construct_string();
  632. }
  633. md.arguments.push_back(ad);
  634. }
  635. c.methods.push_back(md);
  636. }
  637. // Get constants.
  638. List<Pair<String, Variant>> cinfo;
  639. lang->get_public_constants(&cinfo);
  640. for (List<Pair<String, Variant>>::Element *E = cinfo.front(); E; E = E->next()) {
  641. ConstantDoc cd;
  642. cd.name = E->get().first;
  643. cd.value = E->get().second;
  644. cd.is_value_valid = true;
  645. c.constants.push_back(cd);
  646. }
  647. // Skip adding the lang if it doesn't expose anything (e.g. C#).
  648. if (c.methods.empty() && c.constants.empty()) {
  649. continue;
  650. }
  651. class_list[cname] = c;
  652. }
  653. }
  654. }
  655. static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &methods) {
  656. String section = parser->get_node_name();
  657. String element = section.substr(0, section.length() - 1);
  658. while (parser->read() == OK) {
  659. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  660. if (parser->get_node_name() == element) {
  661. DocData::MethodDoc method;
  662. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  663. method.name = parser->get_attribute_value("name");
  664. if (parser->has_attribute("qualifiers")) {
  665. method.qualifiers = parser->get_attribute_value("qualifiers");
  666. }
  667. while (parser->read() == OK) {
  668. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  669. String name = parser->get_node_name();
  670. if (name == "return") {
  671. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  672. method.return_type = parser->get_attribute_value("type");
  673. if (parser->has_attribute("enum")) {
  674. method.return_enum = parser->get_attribute_value("enum");
  675. }
  676. } else if (name == "argument") {
  677. DocData::ArgumentDoc argument;
  678. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  679. argument.name = parser->get_attribute_value("name");
  680. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  681. argument.type = parser->get_attribute_value("type");
  682. if (parser->has_attribute("enum")) {
  683. argument.enumeration = parser->get_attribute_value("enum");
  684. }
  685. method.arguments.push_back(argument);
  686. } else if (name == "description") {
  687. parser->read();
  688. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  689. method.description = parser->get_node_data();
  690. }
  691. }
  692. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) {
  693. break;
  694. }
  695. }
  696. methods.push_back(method);
  697. } else {
  698. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + ".");
  699. }
  700. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) {
  701. break;
  702. }
  703. }
  704. return OK;
  705. }
  706. Error DocData::load_classes(const String &p_dir) {
  707. Error err;
  708. DirAccessRef da = DirAccess::open(p_dir, &err);
  709. if (!da) {
  710. return err;
  711. }
  712. da->list_dir_begin();
  713. String path;
  714. path = da->get_next();
  715. while (path != String()) {
  716. if (!da->current_is_dir() && path.ends_with("xml")) {
  717. Ref<XMLParser> parser = memnew(XMLParser);
  718. Error err2 = parser->open(p_dir.plus_file(path));
  719. if (err2) {
  720. return err2;
  721. }
  722. _load(parser);
  723. }
  724. path = da->get_next();
  725. }
  726. da->list_dir_end();
  727. return OK;
  728. }
  729. Error DocData::erase_classes(const String &p_dir) {
  730. Error err;
  731. DirAccessRef da = DirAccess::open(p_dir, &err);
  732. if (!da) {
  733. return err;
  734. }
  735. List<String> to_erase;
  736. da->list_dir_begin();
  737. String path;
  738. path = da->get_next();
  739. while (path != String()) {
  740. if (!da->current_is_dir() && path.ends_with("xml")) {
  741. to_erase.push_back(path);
  742. }
  743. path = da->get_next();
  744. }
  745. da->list_dir_end();
  746. while (to_erase.size()) {
  747. da->remove(to_erase.front()->get());
  748. to_erase.pop_front();
  749. }
  750. return OK;
  751. }
  752. Error DocData::_load(Ref<XMLParser> parser) {
  753. Error err = OK;
  754. while ((err = parser->read()) == OK) {
  755. if (parser->get_node_type() == XMLParser::NODE_ELEMENT && parser->get_node_name() == "?xml") {
  756. parser->skip_section();
  757. }
  758. if (parser->get_node_type() != XMLParser::NODE_ELEMENT) {
  759. continue; //no idea what this may be, but skipping anyway
  760. }
  761. ERR_FAIL_COND_V(parser->get_node_name() != "class", ERR_FILE_CORRUPT);
  762. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  763. String name = parser->get_attribute_value("name");
  764. class_list[name] = ClassDoc();
  765. ClassDoc &c = class_list[name];
  766. c.name = name;
  767. if (parser->has_attribute("inherits")) {
  768. c.inherits = parser->get_attribute_value("inherits");
  769. }
  770. while (parser->read() == OK) {
  771. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  772. String name2 = parser->get_node_name();
  773. if (name2 == "brief_description") {
  774. parser->read();
  775. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  776. c.brief_description = parser->get_node_data();
  777. }
  778. } else if (name2 == "description") {
  779. parser->read();
  780. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  781. c.description = parser->get_node_data();
  782. }
  783. } else if (name2 == "tutorials") {
  784. while (parser->read() == OK) {
  785. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  786. String name3 = parser->get_node_name();
  787. if (name3 == "link") {
  788. TutorialDoc tutorial;
  789. if (parser->has_attribute("title")) {
  790. tutorial.title = parser->get_attribute_value("title");
  791. }
  792. parser->read();
  793. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  794. tutorial.link = parser->get_node_data().strip_edges();
  795. c.tutorials.push_back(tutorial);
  796. }
  797. } else {
  798. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  799. }
  800. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") {
  801. break; // End of <tutorials>.
  802. }
  803. }
  804. } else if (name2 == "methods") {
  805. Error err2 = _parse_methods(parser, c.methods);
  806. ERR_FAIL_COND_V(err2, err2);
  807. } else if (name2 == "signals") {
  808. Error err2 = _parse_methods(parser, c.signals);
  809. ERR_FAIL_COND_V(err2, err2);
  810. } else if (name2 == "members") {
  811. while (parser->read() == OK) {
  812. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  813. String name3 = parser->get_node_name();
  814. if (name3 == "member") {
  815. PropertyDoc prop2;
  816. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  817. prop2.name = parser->get_attribute_value("name");
  818. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  819. prop2.type = parser->get_attribute_value("type");
  820. if (parser->has_attribute("setter")) {
  821. prop2.setter = parser->get_attribute_value("setter");
  822. }
  823. if (parser->has_attribute("getter")) {
  824. prop2.getter = parser->get_attribute_value("getter");
  825. }
  826. if (parser->has_attribute("enum")) {
  827. prop2.enumeration = parser->get_attribute_value("enum");
  828. }
  829. if (!parser->is_empty()) {
  830. parser->read();
  831. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  832. prop2.description = parser->get_node_data();
  833. }
  834. }
  835. c.properties.push_back(prop2);
  836. } else {
  837. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  838. }
  839. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") {
  840. break; // End of <members>.
  841. }
  842. }
  843. } else if (name2 == "theme_items") {
  844. while (parser->read() == OK) {
  845. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  846. String name3 = parser->get_node_name();
  847. if (name3 == "theme_item") {
  848. ThemeItemDoc prop2;
  849. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  850. prop2.name = parser->get_attribute_value("name");
  851. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  852. prop2.type = parser->get_attribute_value("type");
  853. ERR_FAIL_COND_V(!parser->has_attribute("data_type"), ERR_FILE_CORRUPT);
  854. prop2.data_type = parser->get_attribute_value("data_type");
  855. if (!parser->is_empty()) {
  856. parser->read();
  857. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  858. prop2.description = parser->get_node_data();
  859. }
  860. }
  861. c.theme_properties.push_back(prop2);
  862. } else {
  863. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  864. }
  865. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") {
  866. break; // End of <theme_items>.
  867. }
  868. }
  869. } else if (name2 == "constants") {
  870. while (parser->read() == OK) {
  871. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  872. String name3 = parser->get_node_name();
  873. if (name3 == "constant") {
  874. ConstantDoc constant2;
  875. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  876. constant2.name = parser->get_attribute_value("name");
  877. ERR_FAIL_COND_V(!parser->has_attribute("value"), ERR_FILE_CORRUPT);
  878. constant2.value = parser->get_attribute_value("value");
  879. constant2.is_value_valid = true;
  880. if (parser->has_attribute("enum")) {
  881. constant2.enumeration = parser->get_attribute_value("enum");
  882. }
  883. if (!parser->is_empty()) {
  884. parser->read();
  885. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  886. constant2.description = parser->get_node_data();
  887. }
  888. }
  889. c.constants.push_back(constant2);
  890. } else {
  891. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  892. }
  893. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") {
  894. break; // End of <constants>.
  895. }
  896. }
  897. } else {
  898. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + ".");
  899. }
  900. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") {
  901. break; // End of <class>.
  902. }
  903. }
  904. }
  905. return OK;
  906. }
  907. static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) {
  908. if (p_string == "") {
  909. return;
  910. }
  911. String tab;
  912. for (int i = 0; i < p_tablevel; i++) {
  913. tab += "\t";
  914. }
  915. f->store_string(tab + p_string + "\n");
  916. }
  917. Error DocData::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
  918. for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
  919. ClassDoc &c = E->get();
  920. String save_path;
  921. if (p_class_path.has(c.name)) {
  922. save_path = p_class_path[c.name];
  923. } else {
  924. save_path = p_default_path;
  925. }
  926. Error err;
  927. String save_file = save_path.plus_file(c.name + ".xml");
  928. FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err);
  929. ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
  930. _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
  931. String header = "<class name=\"" + c.name + "\"";
  932. if (c.inherits != "") {
  933. header += " inherits=\"" + c.inherits + "\"";
  934. }
  935. // Reference the XML schema so editors can provide error checking.
  936. // Modules are nested deep, so change the path to reference the same schema everywhere.
  937. const String schema_path = save_path.find("modules/") != -1 ? "../../../doc/class.xsd" : "../class.xsd";
  938. header += vformat(
  939. R"( xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="%s">)",
  940. schema_path);
  941. _write_string(f, 0, header);
  942. _write_string(f, 1, "<brief_description>");
  943. _write_string(f, 2, _translate_doc_string(c.brief_description).strip_edges().xml_escape());
  944. _write_string(f, 1, "</brief_description>");
  945. _write_string(f, 1, "<description>");
  946. _write_string(f, 2, _translate_doc_string(c.description).strip_edges().xml_escape());
  947. _write_string(f, 1, "</description>");
  948. _write_string(f, 1, "<tutorials>");
  949. for (int i = 0; i < c.tutorials.size(); i++) {
  950. TutorialDoc tutorial = c.tutorials.get(i);
  951. String title_attribute = (!tutorial.title.empty()) ? " title=\"" + _translate_doc_string(tutorial.title).xml_escape() + "\"" : "";
  952. _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>");
  953. }
  954. _write_string(f, 1, "</tutorials>");
  955. _write_string(f, 1, "<methods>");
  956. c.methods.sort();
  957. for (int i = 0; i < c.methods.size(); i++) {
  958. const MethodDoc &m = c.methods[i];
  959. String qualifiers;
  960. if (m.qualifiers != "") {
  961. qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
  962. }
  963. _write_string(f, 2, "<method name=\"" + m.name + "\"" + qualifiers + ">");
  964. if (m.return_type != "") {
  965. String enum_text;
  966. if (m.return_enum != String()) {
  967. enum_text = " enum=\"" + m.return_enum + "\"";
  968. }
  969. _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />");
  970. }
  971. for (int j = 0; j < m.arguments.size(); j++) {
  972. const ArgumentDoc &a = m.arguments[j];
  973. String enum_text;
  974. if (a.enumeration != String()) {
  975. enum_text = " enum=\"" + a.enumeration + "\"";
  976. }
  977. if (a.default_value != "") {
  978. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />");
  979. } else {
  980. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " />");
  981. }
  982. }
  983. _write_string(f, 3, "<description>");
  984. _write_string(f, 4, _translate_doc_string(m.description).strip_edges().xml_escape());
  985. _write_string(f, 3, "</description>");
  986. _write_string(f, 2, "</method>");
  987. }
  988. _write_string(f, 1, "</methods>");
  989. if (c.properties.size()) {
  990. _write_string(f, 1, "<members>");
  991. c.properties.sort();
  992. for (int i = 0; i < c.properties.size(); i++) {
  993. String additional_attributes;
  994. if (c.properties[i].enumeration != String()) {
  995. additional_attributes += " enum=\"" + c.properties[i].enumeration + "\"";
  996. }
  997. if (c.properties[i].default_value != String()) {
  998. additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\"";
  999. }
  1000. const PropertyDoc &p = c.properties[i];
  1001. if (c.properties[i].overridden) {
  1002. _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\" overrides=\"" + p.overrides + "\"" + additional_attributes + " />");
  1003. } else {
  1004. _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">");
  1005. _write_string(f, 3, _translate_doc_string(p.description).strip_edges().xml_escape());
  1006. _write_string(f, 2, "</member>");
  1007. }
  1008. }
  1009. _write_string(f, 1, "</members>");
  1010. }
  1011. if (c.signals.size()) {
  1012. c.signals.sort();
  1013. _write_string(f, 1, "<signals>");
  1014. for (int i = 0; i < c.signals.size(); i++) {
  1015. const MethodDoc &m = c.signals[i];
  1016. _write_string(f, 2, "<signal name=\"" + m.name + "\">");
  1017. for (int j = 0; j < m.arguments.size(); j++) {
  1018. const ArgumentDoc &a = m.arguments[j];
  1019. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\" />");
  1020. }
  1021. _write_string(f, 3, "<description>");
  1022. _write_string(f, 4, _translate_doc_string(m.description).strip_edges().xml_escape());
  1023. _write_string(f, 3, "</description>");
  1024. _write_string(f, 2, "</signal>");
  1025. }
  1026. _write_string(f, 1, "</signals>");
  1027. }
  1028. _write_string(f, 1, "<constants>");
  1029. for (int i = 0; i < c.constants.size(); i++) {
  1030. const ConstantDoc &k = c.constants[i];
  1031. if (k.is_value_valid) {
  1032. if (k.enumeration != String()) {
  1033. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
  1034. } else {
  1035. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
  1036. }
  1037. } else {
  1038. if (k.enumeration != String()) {
  1039. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">");
  1040. } else {
  1041. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
  1042. }
  1043. }
  1044. _write_string(f, 3, _translate_doc_string(k.description).strip_edges().xml_escape());
  1045. _write_string(f, 2, "</constant>");
  1046. }
  1047. _write_string(f, 1, "</constants>");
  1048. if (c.theme_properties.size()) {
  1049. c.theme_properties.sort();
  1050. _write_string(f, 1, "<theme_items>");
  1051. for (int i = 0; i < c.theme_properties.size(); i++) {
  1052. const ThemeItemDoc &ti = c.theme_properties[i];
  1053. if (ti.default_value != "") {
  1054. _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\" default=\"" + ti.default_value.xml_escape(true) + "\">");
  1055. } else {
  1056. _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\">");
  1057. }
  1058. _write_string(f, 3, _translate_doc_string(ti.description).strip_edges().xml_escape());
  1059. _write_string(f, 2, "</theme_item>");
  1060. }
  1061. _write_string(f, 1, "</theme_items>");
  1062. }
  1063. _write_string(f, 0, "</class>");
  1064. }
  1065. return OK;
  1066. }
  1067. Error DocData::load_compressed(const uint8_t *p_data, int p_compressed_size, int p_uncompressed_size) {
  1068. Vector<uint8_t> data;
  1069. data.resize(p_uncompressed_size);
  1070. int ret = Compression::decompress(data.ptrw(), p_uncompressed_size, p_data, p_compressed_size, Compression::MODE_DEFLATE);
  1071. ERR_FAIL_COND_V_MSG(ret == -1, ERR_FILE_CORRUPT, "Compressed file is corrupt.");
  1072. class_list.clear();
  1073. Ref<XMLParser> parser = memnew(XMLParser);
  1074. Error err = parser->open_buffer(data);
  1075. if (err) {
  1076. return err;
  1077. }
  1078. _load(parser);
  1079. return OK;
  1080. }