updating_the_class_reference.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. .. _doc_updating_the_class_reference:
  2. Updating the class reference
  3. ============================
  4. Godot Engine provides an extensive panel of nodes and singletons that you can
  5. use with GDScript to develop your games. All those classes are listed and
  6. documented in the :ref:`class reference <toc-class-ref>`, which is available
  7. both in the online documentation and offline from within the engine.
  8. The class reference is however not 100% complete. Some methods, constants and
  9. signals have not been described yet, while others may have their implementation
  10. changed and thus need an update. Updating the class reference is a tedious work
  11. and the responsibility of the community: if we all partake in the effort, we
  12. can fill in the blanks and ensure a good documentation level in no time!
  13. **Important notes:**
  14. - To coordinate the effort and have an overview of the current status, we use
  15. `a collaborative pad <https://etherpad.net/p/godot-classref-status>`_. Please
  16. follow the instructions there to notify the other documentation writers about
  17. what you are working on.
  18. - We aim at completely filling the class reference in English
  19. first. Once it nears 90-95% completion, we could start thinking about
  20. localisating in other languages.
  21. Workflow for updating the class reference
  22. -----------------------------------------
  23. The source file of the class reference is an XML file in the main Godot source
  24. repository on GitHub, `doc/base/classes.xml <https://github.com/godotengine/godot/blob/master/doc/base/classes.xml>`_.
  25. As of now, it is relatively heavy (more than 1 MB), so it can't be edited online
  26. using GitHub's text editor.
  27. The workflow to update the class reference is therefore:
  28. - Fork the `upstream repository <https://github.com/godotengine/godot>`_ and clone
  29. your fork.
  30. - Edit the ``doc/base/classes.xml`` file, commit your changes and push to your
  31. fork.
  32. - Make a pull request on the upstream repository.
  33. The following section details this workflow, and gives also additional information
  34. about how to synchronise the XML template with the current state of the source code,
  35. or what should be the formatting of the added text.
  36. **Important:** The class reference is also :ref:`available in the online documentation <toc-class-ref>`,
  37. which is hosted alongside the rest of the documentation in the
  38. `godot-docs <https://github.com/godotengine/godot-docs>`_ git repository. The rST files
  39. should however **not be edited directly**, they are generated via a script from the
  40. ``doc/base/classes.xml`` file described above.
  41. Getting started with GitHub
  42. ---------------------------
  43. This section describes step-by-step the typical workflow to fork the git repository,
  44. or update an existing local clone of your fork, and then prepare a pull request.
  45. Fork Godot Engine
  46. ~~~~~~~~~~~~~~~~~
  47. First of all, you need to fork the Godot Engine on your own GitHub
  48. repository.
  49. You will then need to clone the master branch of Godot Engine in order
  50. to work on the most recent version of the engine, including all of its
  51. features.
  52. ::
  53. git clone https://github.com/your_name/godot.git
  54. Then, create a new git branch that will contain your changes.
  55. ::
  56. git checkout -b classref-edit
  57. The branch you just created is identical to current master branch of
  58. Godot Engine. It already contains a ``doc/`` folder, with the current
  59. state of the class reference. Note that you can set whatever name
  60. you want for the branch, ``classref-edit`` is just an example.
  61. Keeping your local clone up-to-date
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. If you already have a local clone of your own fork, it might happen
  64. pretty fast that it will diverge with the upstream git repository.
  65. For example other contributors might have updated the class reference
  66. since you last worked on it, or your own commits might have been squashed
  67. together when merging your pull request, and thus appear as diverging
  68. from the upstream master branch.
  69. To keep your local clone up-to-date, you should first add an ``upstream``
  70. git *remote* to work with:
  71. ::
  72. git remote add upstream https://github.com/godotengine/godot
  73. git fetch upstream
  74. You only need to run this once to define this remote. The following steps
  75. will have to be run each time you want to sync your branch to the state
  76. of the upstream repo:
  77. ::
  78. git pull --rebase upstream/master
  79. This command would reapply your local changes (if any) on top of the current
  80. state of the upstream branch, thus bringing you up-to-date with your own commits
  81. on top. In case you have local commits that should be discarded (e.g. if your
  82. previous pull request had 5 small commits that were all merged into one bigger
  83. commit in the upstream branch), you need to *reset* your branch:
  84. ::
  85. git fetch upstream
  86. git reset --hard upstream/master
  87. **Warning:** The above command will reset your branch to the state of the
  88. ``upstream/master`` branch, i.e. it will discard all changes which are
  89. specific to your local branch. So make sure to run this *before* making new
  90. changes and not afterwards.
  91. Alternatively, you can also keep your own master branch (``origin/master``)
  92. up-to-date and create new branches when wanting to commit changes to the
  93. class reference:
  94. ::
  95. git checkout master
  96. git branch -d my-previous-doc-branch
  97. git pull --rebase upstream/master
  98. git checkout -b my-new-doc-branch
  99. In case of doubt, ask for help on our IRC channels, we have some git gurus
  100. there.
  101. Updating the documentation template
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. When classes are modified in the source code, the documentation template
  104. might become outdated. To make sure that you are editing an up-to-date
  105. version, you first need to compile Godot (you can follow the
  106. :ref:`doc_introduction_to_the_buildsystem` page), and then run the
  107. following command (assuming 64-bit Linux):
  108. ::
  109. ./bin/godot.x11.tools.64 --doctool doc/base/classes.xml
  110. The doc/base/classes.xml should then be up-to-date with current Godot
  111. Engine features. You can then check what changed using the
  112. ``git diff`` command. If there are changes to other classes than the one
  113. you are planning to document, please commit those changes first before
  114. starting to edit the template:
  115. ::
  116. git add doc/base/classes.xml
  117. git commit -m "Sync classes reference template with current code base"
  118. You are now ready to edit this file to add stuff.
  119. **Note:** If this has been done recently by another contributor, you don't
  120. forcefully need to go through these steps (unless you know that the class
  121. you plan to edit *has* been modified recently).
  122. Push and request a pull of your changes
  123. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. Once your modifications are finished, push your changes on your GitHub
  125. repository:
  126. ::
  127. git add doc/base/classes.xml
  128. git commit -m "Explain your modifications."
  129. git push
  130. When it's done, you can ask for a Pull Request via the GitHub UI of your
  131. Godot fork.
  132. Editing the doc/base/classes.xml file
  133. -------------------------------------
  134. This file is generated and updated by Godot Engine. It is used by the
  135. editor as base for the Help section.
  136. You can edit this file using your favourite text editor. If you use a code
  137. editor, make sure that it won't needlessly change the indentation behaviour
  138. (e.g. change all tabs to spaces).
  139. Formatting of the XML file
  140. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. Here is an example with the Node2D class:
  142. .. code:: xml
  143. <class name="Node2D" inherits="CanvasItem" category="Core">
  144. <brief_description>
  145. Base node for 2D system.
  146. </brief_description>
  147. <description>
  148. Base node for 2D system. Node2D contains a position, rotation and scale, which is used to position and animate. It can alternatively be used with a custom 2D transform ([Matrix32]). A tree of Node2Ds allows complex hierarchies for animation and positioning.
  149. </description>
  150. <methods>
  151. <method name="set_pos">
  152. <argument index="0" name="pos" type="Vector2">
  153. </argument>
  154. <description>
  155. Set the position of the 2d node.
  156. </description>
  157. </method>
  158. <method name="set_rot">
  159. <argument index="0" name="rot" type="float">
  160. </argument>
  161. <description>
  162. Set the rotation of the 2d node.
  163. </description>
  164. </method>
  165. <method name="set_scale">
  166. <argument index="0" name="scale" type="Vector2">
  167. </argument>
  168. <description>
  169. Set the scale of the 2d node.
  170. </description>
  171. </method>
  172. <method name="get_pos" qualifiers="const">
  173. <return type="Vector2">
  174. </return>
  175. <description>
  176. Return the position of the 2D node.
  177. </description>
  178. </method>
  179. <method name="get_rot" qualifiers="const">
  180. <return type="float">
  181. </return>
  182. <description>
  183. Return the rotation of the 2D node.
  184. </description>
  185. </method>
  186. <method name="get_scale" qualifiers="const">
  187. <return type="Vector2">
  188. </return>
  189. <description>
  190. Return the scale of the 2D node.
  191. </description>
  192. </method>
  193. <method name="rotate">
  194. <argument index="0" name="degrees" type="float">
  195. </argument>
  196. <description>
  197. </description>
  198. </method>
  199. <method name="move_local_x">
  200. <argument index="0" name="delta" type="float">
  201. </argument>
  202. <argument index="1" name="scaled" type="bool" default="false">
  203. </argument>
  204. <description>
  205. </description>
  206. </method>
  207. <method name="move_local_y">
  208. <argument index="0" name="delta" type="float">
  209. </argument>
  210. <argument index="1" name="scaled" type="bool" default="false">
  211. </argument>
  212. <description>
  213. </description>
  214. </method>
  215. <method name="get_global_pos" qualifiers="const">
  216. <return type="Vector2">
  217. </return>
  218. <description>
  219. Return the global position of the 2D node.
  220. </description>
  221. </method>
  222. <method name="set_global_pos">
  223. <argument index="0" name="arg0" type="Vector2">
  224. </argument>
  225. <description>
  226. </description>
  227. </method>
  228. <method name="set_transform">
  229. <argument index="0" name="xform" type="Matrix32">
  230. </argument>
  231. <description>
  232. </description>
  233. </method>
  234. <method name="set_global_transform">
  235. <argument index="0" name="xform" type="Matrix32">
  236. </argument>
  237. <description>
  238. </description>
  239. </method>
  240. <method name="edit_set_pivot">
  241. <argument index="0" name="arg0" type="Vector2">
  242. </argument>
  243. <description>
  244. </description>
  245. </method>
  246. </methods>
  247. <constants>
  248. </constants>
  249. </class>
  250. As you can see, some methods in this class have no description (i.e.
  251. there is no text between their marks). This can also happen for the
  252. ``description`` and ``brief_description`` of the class, but in our example
  253. they are already filled. Let's edit the description of the ``rotate()``
  254. method:
  255. .. code:: xml
  256. <method name="rotate">
  257. <argument index="0" name="degrees" type="float">
  258. </argument>
  259. <description>
  260. Rotates the node of a given number of degrees.
  261. </description>
  262. </method>
  263. That's all!
  264. You simply have to write any missing text between these marks:
  265. - <description></description>
  266. - <brief_description></brief_description>
  267. - <constant></constant>
  268. - <member></member>
  269. - <signal></signal>
  270. Describe clearly and shortly what the method does, or what the
  271. constant, member variable or signal mean. You can include an example
  272. of use if needed. Try to use grammatically correct English, and check
  273. the other descriptions to get an impression of the writing style.
  274. For setters/getters, the convention is to describe in depth what the
  275. method does in the setter, and to say only the minimal in the getter to
  276. avoid duplication of the contents.
  277. Tags available for improved formatting
  278. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. For more control over the formatting of the help, Godot's XML
  280. documentation supports various BBcode-like tags which are
  281. interpreted by both the offline in-editor Help, as well as the
  282. online documentation (via the reST converter).
  283. Those tags are listed below. See existing documentation entries
  284. for more examples of how to use them properly.
  285. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  286. | Tag | Effect | Usage | Result |
  287. +===========================+================================+===================================+============================================+
  288. | [Class] | Link a class | Move the [Sprite]. | Move the :ref:`class_sprite`. |
  289. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  290. | [method methodname] | Link a method of this class | See [method set_pos]. | See :ref:`set_pos <class_node2d_set_pos>`. |
  291. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  292. | [method Class.methodname] | Link a method of another class | See [method Node2D.set_pos]. | See :ref:`set_pos <class_node2d_set_pos>`. |
  293. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  294. | [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
  295. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  296. | [i] [/i] | Italic | Some [i]italic[/b] text. | Some *italic* text. |
  297. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  298. | [code] [/code] | Monospace | Some [code]monospace[/code] text. | Some ``monospace`` text. |
  299. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  300. | [codeblock] [/codeblock] | Multiline preformatted block | *See below.* | *See below.* |
  301. +---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
  302. The ``[codeblock]`` is meant to be used for pre-formatted code
  303. block, using spaces as indentation (tabs will be removed by the
  304. reST converter). For example:
  305. .. code:: xml
  306. [codeblock]
  307. func _ready():
  308. var sprite = get_node("Sprite")
  309. print(sprite.get_pos())
  310. [/codeblock]
  311. Which would be rendered as:
  312. ::
  313. func _ready():
  314. var sprite = get_node("Sprite")
  315. print(sprite.get_pos())
  316. I don't know what this method does!
  317. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  318. Not a problem. Leave it behind for now, and don't forget to notify the
  319. missing methods when you request a pull of your changes. Another
  320. editor will take care of it.
  321. If you wonder what a method does, you can still have a look at its
  322. implementation in Godot Engine's source code on GitHub. Also, if you
  323. have a doubt, feel free to ask on the
  324. `Q&A website <https://godotengine.org/qa/>`__
  325. and on IRC (freenode, #godotengine).