updating_the_class_reference.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. .. _doc_updating_the_class_reference:
  2. Contributing to the class reference
  3. ===================================
  4. .. highlight:: shell
  5. .. note:: This guide also is available as a `video tutorial on YouTube <https://www.youtube.com/watch?v=5jeHXxeX-JY>`_.
  6. Godot ships with many nodes and singletons to help you develop your games. Each is a class, documented in the :ref:`class reference <toc-class-ref>`.
  7. This reference is essential for anyone learning the engine: it is available both online and in the engine.
  8. But it's incomplete. Some methods, variables and signals lack descriptions. Others changed with recent releases and need updates.
  9. The developers can't write the entire reference on their own. Godot needs you, and all of us, to contribute.
  10. **Important:** If you are planning to make larger changes or a more substantial contribution, it is usually a good idea
  11. to create an issue (or a comment in an existing one) to let others know so they don't start working on the same thing too.
  12. .. seealso::
  13. Not sure where to start contributing? Take a look at the current class reference
  14. completion status `here <https://godotengine.github.io/doc-status/>`__.
  15. How to contribute
  16. -----------------
  17. The class reference lies in the following XML files, in Godot's GitHub repository: `doc/classes/ <https://github.com/godotengine/godot/tree/master/doc/classes>`_.
  18. There are 5 steps to update the class reference (full guide below):
  19. 1. Fork `Godot's repository <https://github.com/godotengine/godot>`_
  20. 2. Clone your fork on your computer
  21. 3. Edit the class file in ``doc/classes/`` to write documentation
  22. 4. Commit your changes and push them to your fork
  23. 5. Make a pull request on the Godot repository
  24. .. warning:: Always use these XML files to edit the API reference. Do not edit the generated .rst files :ref:`in the online documentation <toc-class-ref>`, hosted in the `godot-docs <https://github.com/godotengine/godot-docs>`_ repository.
  25. Get started with GitHub
  26. -----------------------
  27. If you're new to Git and GitHub, this guide will help you get started. You'll learn to:
  28. - Fork and clone Godot's repository
  29. - Keep your fork up to date with other contributors
  30. - Create a pull request so your improvements end in the official docs
  31. .. note:: If you're new to Git, the version control system Godot uses, go through `GitHub's interactive guide <https://try.github.io/levels/1/challenges/1>`_. You'll learn some essential vocabulary and get a sense for the tool.
  32. Fork Godot
  33. ~~~~~~~~~~
  34. Fork the Godot Engine into a GitHub repository of your own.
  35. Clone the repository on your computer:
  36. ::
  37. git clone https://github.com/your_name/godot.git
  38. Create a new branch to make your changes. It makes it a lot easier to sync your improvements with other docs writers. It's also easier to clean up your repository if you run into any issues with Git.
  39. ::
  40. git checkout -b your-new-branch-name
  41. The new branch is the same as your master branch, until you start to write API docs. In the ``doc/`` folder, you'll find the class reference.
  42. How to keep your local clone up-to-date
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. Other writers contribute to Godot's documentation. Your local repository will fall behind it, and you'll have to synchronize it. Especially if other contributors update the class reference while you work on it.
  45. First add an ``upstream`` git *remote* to work with. Remotes are links to online repositories you can download new files from.
  46. ::
  47. git remote add upstream https://github.com/godotengine/godot
  48. You can check the list of all remote servers with:
  49. ::
  50. git remote -v
  51. You should have two: ``origin``, your fork on GitHub that Git adds by default, and ``upstream``, that you just added:
  52. ::
  53. origin https://github.com/your_name/godot.git (fetch)
  54. origin https://github.com/your_name/godot.git (push)
  55. upstream https://github.com/godotengine/godot.git (fetch)
  56. upstream https://github.com/godotengine/godot.git (push)
  57. Each time you want to sync your branch to the state of the upstream repository, enter:
  58. ::
  59. git pull --rebase upstream master
  60. This command will first ``fetch``, or download the latest version of the Godot repository. Then, it will reapply your local changes on top.
  61. If you made changes you don't want to keep in your local branch, use the following commands instead:
  62. ::
  63. git fetch upstream
  64. git reset --hard upstream master
  65. **Warning:** The above command will reset your branch to the state of the ``upstream master`` branch. It will discard all local changes. Make sure to only run this *before* you make important changes.
  66. Another option is to delete the branch you're working on, synchronize the master branch with the Godot repository, and create a new branch:
  67. ::
  68. git checkout master
  69. git branch -d your-new-branch-name
  70. git pull --rebase upstream master
  71. git checkout -b your-new-branch-name
  72. If you're feeling lost by now, come to our `IRC channels <https://webchat.freenode.net/?channels=#godotengine>`_ and ask for help. Experienced Git users will give you a hand.
  73. Updating the documentation template
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. When classes are modified in the source code, the documentation template might become outdated. To make sure that you are editing an up-to-date version, you first need to compile Godot (you can follow the :ref:`doc_introduction_to_the_buildsystem` page), and then run the following command (assuming 64-bit Linux):
  76. ::
  77. ./bin/godot.x11.tools.64 --doctool .
  78. The XML files in doc/classes should then be up-to-date with current Godot Engine features. You can then check what changed using the ``git diff`` command. If there are changes to other classes than the one you are planning to document, please commit those changes first before starting to edit the template:
  79. ::
  80. git add doc/classes/*.xml
  81. git commit -m "Sync classes reference template with current code base"
  82. You are now ready to edit this file to add stuff.
  83. **Note:** If this has been done recently by another contributor, you don't forcefully need to go through these steps (unless you know that the class you plan to edit *has* been modified recently).
  84. Push and request a pull of your changes
  85. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. Once your modifications are finished, push your changes on your GitHub
  87. repository:
  88. ::
  89. git add doc/classes/<edited_file>.xml
  90. git commit -m "Explain your modifications."
  91. git push
  92. When it's done, you can ask for a Pull Request via the GitHub UI of your Godot fork.
  93. .. warning::
  94. Although you can edit files on GitHub, it's not recommended. As hundreds of contributors work on Godot, the Git history must stay clean. Each commit should bundle all related improvements you make to the class reference, a new feature, bug fixes... When you edit from GitHub, it will create a new branch and a Pull Request every time you want to save it. If a few days pass before your changes get a review, you won't be able to update to the latest version of the repository cleanly. Also, it's harder to keep clean indents from GitHub. And they're very important in the docs.
  95. TL;DR: If you don't know what you're doing exactly, do not edit files from GitHub.
  96. How to edit class XML
  97. ---------------------
  98. Edit the file for your chosen class in ``doc/classes/`` to update the class reference. The folder contains an XML file for each class. The XML lists the constants and methods you'll find in the class reference. Godot generates and updates the XML automatically.
  99. Edit it using your favorite text editor. If you use a code editor, make sure that it doesn't change the indent style: tabs for the XML, and 4 spaces inside BBCode-style blocks. More on that below.
  100. If you need to check that the modifications you've made are correct in the generated documentation, build Godot as described :ref:`here <toc-devel-compiling>`, run the editor and open the help for the page you modified.
  101. How to write the class reference
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. Each class has a brief and a long description. The brief description is always at the top of the page, while the full description lies below the list of methods, variables and constants. Methods, member variables, constants and signals are in separate categories or XML nodes. For each, learn how they work in Godot's source code, and fill their <description>.
  104. Our job is to add the missing text between these marks:
  105. - <description></description>
  106. - <brief_description></brief_description>
  107. - <constant></constant>
  108. - <method></method>
  109. - <member></member>
  110. - <signal></signal>
  111. Write in a clear and simple language. Always follow the :ref:`writing guidelines <doc_docs_writing_guidelines>` to keep your descriptions short and easy to read. **Do not leave empty lines** in the descriptions: each line in the XML file will result in a new paragraph.
  112. Here's how a class looks like in XML:
  113. .. code-block:: xml
  114. <class name="Node2D" inherits="CanvasItem" category="Core">
  115. <brief_description>
  116. Base node for 2D system.
  117. </brief_description>
  118. <description>
  119. 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.
  120. </description>
  121. <methods>
  122. <method name="set_pos">
  123. <argument index="0" name="pos" type="Vector2">
  124. </argument>
  125. <description>
  126. Sets the position of the 2D node.
  127. </description>
  128. </method>
  129. [...]
  130. <method name="edit_set_pivot">
  131. <argument index="0" name="arg0" type="Vector2">
  132. </argument>
  133. <description>
  134. </description>
  135. </method>
  136. </methods>
  137. <members>
  138. <member name="global_position" type="Vector2" setter="set_global_position" getter="get_global_position" brief="">
  139. </member>
  140. [...]
  141. <member name="z_as_relative" type="bool" setter="set_z_as_relative" getter="is_z_relative" brief="">
  142. </member>
  143. </members>
  144. <constants>
  145. </constants>
  146. </class>
  147. Use a code editor like Vim, Atom, Code, Notepad++ or anything similar to edit the file quickly. Use the search function to find classes fast.
  148. .. _doc_updating_the_class_reference_bbcode:
  149. Improve formatting with BBCode style tags
  150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. Godot's class reference supports BBCode-like tags. They add nice formatting to the text. Here's the list of available tags:
  152. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  153. | Tag | Effect | Usage | Result |
  154. +===========================+================================+===================================+===================================================+
  155. | [Class] | Link a class | Move the [Sprite]. | Move the :ref:`class_sprite`. |
  156. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  157. | [method methodname] | Link to a method in this class | Call [method hide]. | See :ref:`hide <class_spatial_method_hide>`. |
  158. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  159. | [method Class.methodname] | Link to another class's method | Call [method Spatial.hide]. | See :ref:`hide <class_spatial_method_hide>`. |
  160. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  161. | [member membername] | Link to a member in this class | Get [member scale]. | Get :ref:`scale <class_node2d_property_scale>`. |
  162. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  163. | [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get :ref:`scale <class_node2d_property_scale>`. |
  164. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  165. | [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit :ref:`renamed <class_node_signal_renamed>`. |
  166. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  167. | [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit :ref:`renamed <class_node_signal_renamed>`. |
  168. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  169. | [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
  170. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  171. | [i] [/i] | Italic | Some [i]italic[/i] text. | Some *italic* text. |
  172. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  173. | [code] [/code] | Monospace | Some [code]monospace[/code] text. | Some ``monospace`` text. |
  174. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  175. | [kbd] [/kbd] | Keyboard/mouse shortcut | Some [kbd]Ctrl + C[/kbd] key. | Some :kbd:`Ctrl + C` key. |
  176. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  177. | [codeblock] [/codeblock] | Multiline preformatted block | *See below.* | *See below.* |
  178. +---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
  179. Use ``[codeblock]`` for pre-formatted code blocks. Inside ``[codeblock]``, always use **four spaces** for indentation (the parser will delete tabs). Example:
  180. .. code-block:: none
  181. [codeblock]
  182. func _ready():
  183. var sprite = get_node("Sprite")
  184. print(sprite.get_pos())
  185. [/codeblock]
  186. Will display as:
  187. .. code-block:: gdscript
  188. func _ready():
  189. var sprite = get_node("Sprite")
  190. print(sprite.get_pos())
  191. To denote important information, add a paragraph starting with "[b]Note:[/b]" at
  192. the end of the description:
  193. .. code-block:: none
  194. [b]Note:[/b] Only available when using the GLES2 renderer.
  195. To denote crucial information that could cause security issues or loss of data
  196. if not followed carefully, add a paragraph starting with "[b]Warning:[/b]" at the
  197. end of the description:
  198. .. code-block:: none
  199. [b]Warning:[/b] If this property is set to [code]true[/code], it allows clients to execute arbitrary code on the server.
  200. For deprecated properties, add a paragraph starting with "[i]Deprecated.[/i]".
  201. Notice the use of italics instead of bold:
  202. .. code-block:: none
  203. [i]Deprecated.[/i] This property has been replaced by [member other_property].
  204. In all the paragraphs described above, make sure the punctuation is part of the
  205. BBCode tags for consistency.
  206. I don't know what this method does!
  207. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. No problem. Leave it behind, and list the methods you skipped when you request a pull of your changes. Another writer will take care of it.
  209. You can still have a look at the methods' implementation in Godot's source code on GitHub. Also, if you have doubts, feel free to ask on the `Q&A website <https://godotengine.org/qa/>`__ and on IRC (freenode, #godotengine).
  210. Localization
  211. ~~~~~~~~~~~~
  212. The documentation can be translated in any language on `Hosted Weblate
  213. <https://hosted.weblate.org/projects/godot-engine/godot-docs/>`__.
  214. Translated strings are synced manually by documentation maintainers in
  215. the `godot-docs-l10n <https://github.com/godotengine/godot-docs-l10n>`__
  216. repository.
  217. Languages with a good level of completion have their own localized
  218. instances of ReadTheDocs. Open an issue on the ``godot-docs-l10n``
  219. repository if you think that a new language is complete enough to get
  220. its own instance.