doc_data.cpp 39 KB

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