class_reference_writing_guidelines.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. .. _doc_class_reference_writing_guidelines:
  2. Class reference writing guidelines
  3. ==================================
  4. This page explains how to write the class reference. You will learn where to
  5. write new descriptions for the classes, methods, and properties for Godot's
  6. built-in node types.
  7. .. seealso::
  8. To learn to submit your changes to the Godot project using the Git version
  9. control system, see :ref:`doc_updating_the_class_reference`.
  10. The reference for each class is contained in an XML file like the one below:
  11. .. code-block:: xml
  12. <class name="Node2D" inherits="CanvasItem" version="4.0">
  13. <brief_description>
  14. A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
  15. </brief_description>
  16. <description>
  17. A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order.
  18. </description>
  19. <tutorials>
  20. <link title="Custom drawing in 2D">https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html</link>
  21. <link title="All 2D Demos">https://github.com/godotengine/godot-demo-projects/tree/master/2d</link>
  22. </tutorials>
  23. <methods>
  24. <method name="apply_scale">
  25. <return type="void">
  26. </return>
  27. <argument index="0" name="ratio" type="Vector2">
  28. </argument>
  29. <description>
  30. Multiplies the current scale by the [code]ratio[/code] vector.
  31. </description>
  32. </method>
  33. [...]
  34. <method name="translate">
  35. <return type="void">
  36. </return>
  37. <argument index="0" name="offset" type="Vector2">
  38. </argument>
  39. <description>
  40. Translates the node by the given [code]offset[/code] in local coordinates.
  41. </description>
  42. </method>
  43. </methods>
  44. <members>
  45. <member name="global_position" type="Vector2" setter="set_global_position" getter="get_global_position">
  46. Global position.
  47. </member>
  48. [...]
  49. <member name="z_index" type="int" setter="set_z_index" getter="get_z_index" default="0">
  50. Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others.
  51. </member>
  52. </members>
  53. <constants>
  54. </constants>
  55. </class>
  56. It starts with brief and long descriptions. In the generated docs, the brief
  57. description is always at the top of the page, while the long description lies
  58. below the list of methods, variables, and constants. You can find methods,
  59. member variables, constants, and signals in separate XML nodes.
  60. For each, you want to learn how they work in Godot's source code. Then, fill
  61. their documentation by completing or improving the text in these tags:
  62. - `<brief_description>`
  63. - `<description>`
  64. - `<constant>`
  65. - `<method>` (in its `<description>` tag; return types and arguments don't take separate
  66. documentation strings)
  67. - `<member>`
  68. - `<signal>` (in its `<description>` tag; arguments don't take separate documentation strings)
  69. - `<constant>`
  70. Write in a clear and simple language. Always follow the :ref:`writing guidelines
  71. <doc_docs_writing_guidelines>` to keep your descriptions short and easy to read.
  72. **Do not leave empty lines** in the descriptions: each line in the XML file will
  73. result in a new paragraph, even if it is empty.
  74. .. _doc_class_reference_writing_guidelines_editing_xml:
  75. How to edit class XML
  76. ---------------------
  77. Edit the file for your chosen class in ``doc/classes/`` to update the class
  78. reference. The folder contains an XML file for each class. The XML lists the
  79. constants and methods you will find in the class reference. Godot generates and
  80. updates the XML automatically.
  81. .. note:: For some modules in the engine's source code, you'll find the XML
  82. files in the ``modules/<module_name>/doc_classes/`` directory instead.
  83. Edit it using your favorite text editor. If you use a code editor, make sure
  84. that it doesn't change the indent style: you should use tabs for the XML and
  85. four spaces inside BBCode-style blocks. More on that below.
  86. To check that the modifications you've made are correct in the generated
  87. documentation, navigate to the ``doc/`` folder and run the command ``make rst``.
  88. This will convert the XML files to the online documentation's format and output
  89. errors if anything's wrong.
  90. Alternatively, you can build Godot and open the modified page in the built-in
  91. code reference. To learn how to compile the engine, read the :ref:`compilation
  92. guide <toc-devel-compiling>`.
  93. We recommend using a code editor that supports XML files like Vim, Atom, Visual Studio Code,
  94. Notepad++, or another to comfortably edit the file. You can also use their
  95. search feature to find classes and properties quickly.
  96. .. tip::
  97. If you use Visual Studio Code, you can install the
  98. `vscode-xml extension <https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml>`__
  99. to get linting for class reference XML files.
  100. .. _doc_class_reference_writing_guidelines_bbcode:
  101. Improve formatting with BBCode style tags
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. Godot's class reference supports BBCode-like tags. They add nice formatting to
  104. the text. Here's the list of available tags:
  105. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  106. | Tag | Effect | Usage | Result |
  107. +============================+======================================+===================================+===================================================+
  108. | [Class] | Link a class | Move the [Sprite2D]. | Move the :ref:`class_Sprite2D`. |
  109. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  110. | [method methodname] | Link to a method in this class | Call [method hide]. | Call :ref:`hide <class_Node3D_method_hide>`. |
  111. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  112. | [method Class.methodname] | Link to another class's method | Call [method Node3D.hide]. | Call :ref:`hide <class_Node3D_method_hide>`. |
  113. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  114. | [member membername] | Link to a member in this class | Get [member scale]. | Get :ref:`scale <class_Node2D_property_scale>`. |
  115. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  116. | [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get :ref:`scale <class_Node2D_property_scale>`. |
  117. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  118. | [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit :ref:`renamed <class_Node_signal_renamed>`. |
  119. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  120. | [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit :ref:`renamed <class_Node_signal_renamed>`. |
  121. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  122. | [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
  123. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  124. | [i] [/i] | Italic | Some [i]italic[/i] text. | Some *italic* text. |
  125. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  126. | [code] [/code] | Monospace | Some [code]monospace[/code] text. | Some ``monospace`` text. |
  127. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  128. | [kbd] [/kbd] | Keyboard/mouse shortcut | Some [kbd]Ctrl + C[/kbd] key. | Some :kbd:`Ctrl + C` key. |
  129. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  130. | [codeblock] [/codeblock] | Multiline preformatted block | *See below.* | *See below.* |
  131. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  132. | [codeblocks] [/codeblocks] | [codeblock] for multiple languages | *See below.* | *See below.* |
  133. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  134. | [gdscript] [/gdscript] | GDScript codeblock tab in codeblocks | *See below.* | *See below.* |
  135. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  136. | [csharp] [/csharp] | C# codeblock tab in codeblocks | *See below.* | *See below.* |
  137. +----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
  138. Use ``[codeblock]`` for pre-formatted code blocks. Inside ``[codeblock]``,
  139. always use **four spaces** for indentation. The parser will delete tabs. For
  140. example:
  141. .. code-block:: none
  142. [codeblock]
  143. func _ready():
  144. var sprite = get_node("Sprite2D")
  145. print(sprite.get_pos())
  146. [/codeblock]
  147. Will display as:
  148. .. code-block:: gdscript
  149. func _ready():
  150. var sprite = get_node("Sprite2D")
  151. print(sprite.get_pos())
  152. If you need to have different code version in GDScript and C#, use
  153. ``[codeblocks]`` instead. If you use ``[codeblocks]``, you also need to have at
  154. least one of the language-specific tags, ``[gdscript]`` and ``[csharp]``.
  155. Always write GDScript code examples first! You can use this `experimental code
  156. translation tool <https://github.com/HaSa1002/codetranslator>`_ to speed up your
  157. workflow.
  158. .. code-block:: none
  159. [codeblocks]
  160. [gdscript]
  161. func _ready():
  162. var sprite = get_node("Sprite2D")
  163. print(sprite.get_pos())
  164. [/gdscript]
  165. [csharp]
  166. public override void _Ready()
  167. {
  168. var sprite = GetNode("Sprite2D");
  169. GD.Print(sprite.GetPos());
  170. }
  171. [/csharp]
  172. [/codeblocks]
  173. The above will display as:
  174. .. tabs::
  175. .. code-tab:: gdscript GDScript
  176. func _ready():
  177. var sprite = get_node("Sprite2D")
  178. print(sprite.get_pos())
  179. .. code-tab:: csharp
  180. public override void _Ready()
  181. {
  182. var sprite = GetNode("Sprite2D");
  183. GD.Print(sprite.GetPos());
  184. }
  185. To denote important information, add a paragraph starting with "[b]Note:[/b]" at
  186. the end of the description:
  187. .. code-block:: none
  188. [b]Note:[/b] Only available when using the Vulkan renderer.
  189. To denote crucial information that could cause security issues or loss of data
  190. if not followed carefully, add a paragraph starting with "[b]Warning:[/b]" at
  191. the end of the description:
  192. .. code-block:: none
  193. [b]Warning:[/b] If this property is set to [code]true[/code], it allows clients to execute arbitrary code on the server.
  194. For deprecated properties, add a paragraph starting with "[i]Deprecated.[/i]".
  195. Notice the use of italics instead of bold:
  196. .. code-block:: none
  197. [i]Deprecated.[/i] This property has been replaced by [member other_property].
  198. In all the paragraphs described above, make sure the punctuation is part of the
  199. BBCode tags for consistency.
  200. I don't know what this method does!
  201. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202. No problem. Leave it behind, and list the methods you skipped when you request a
  203. pull of your changes. Another writer will take care of it.
  204. You can still look at the methods' implementation in Godot's source code on
  205. GitHub. If you have doubts, feel free to ask on the `Q&A website
  206. <https://godotengine.org/qa/>`__ and `Godot Contributors Chat <https://chat.godotengine.org/>`_.