ConfigFile.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="ConfigFile" inherits="Reference" category="Core" version="3.0.alpha.custom_build">
  3. <brief_description>
  4. Helper class to handle INI-style files.
  5. </brief_description>
  6. <description>
  7. This helper class can be used to store [Variant] values on the filesystem using INI-style formatting. The stored values are indentified by a section and a key:
  8. [codeblock]
  9. [section]
  10. some_key=42
  11. string_example="Hello World!"
  12. a_vector=Vector3( 1, 0, 2 )
  13. [/codeblock]
  14. The stored data can be saved to or parsed from a file, though ConfigFile objects can also be used directly without accessing the filesystem.
  15. The following example shows how to parse an INI-style file from the system, read its contents and store new values in it:
  16. [codeblock]
  17. var config = ConfigFile.new()
  18. var err = config.load("user://settings.cfg")
  19. if err == OK: # if not, something went wrong with the file loading
  20. # Look for the display/width pair, and default to 1024 if missing
  21. var screen_width = get_value("display", "width", 1024)
  22. # Store a variable if and only if it hasn't been defined yet
  23. if not config.has_section_key("audio", "mute"):
  24. config.set_value("audio", "mute", false)
  25. # Save the changes by overwriting the previous file
  26. config.save("user://settings.cfg")
  27. [/codeblock]
  28. </description>
  29. <tutorials>
  30. </tutorials>
  31. <demos>
  32. </demos>
  33. <methods>
  34. <method name="erase_section">
  35. <return type="void">
  36. </return>
  37. <argument index="0" name="section" type="String">
  38. </argument>
  39. <description>
  40. Deletes the specified section along with all the key-value pairs inside.
  41. </description>
  42. </method>
  43. <method name="get_section_keys" qualifiers="const">
  44. <return type="PoolStringArray">
  45. </return>
  46. <argument index="0" name="section" type="String">
  47. </argument>
  48. <description>
  49. Returns an array of all defined key identifiers in the specified section.
  50. </description>
  51. </method>
  52. <method name="get_sections" qualifiers="const">
  53. <return type="PoolStringArray">
  54. </return>
  55. <description>
  56. Returns an array of all defined section identifiers.
  57. </description>
  58. </method>
  59. <method name="get_value" qualifiers="const">
  60. <return type="Variant">
  61. </return>
  62. <argument index="0" name="section" type="String">
  63. </argument>
  64. <argument index="1" name="key" type="String">
  65. </argument>
  66. <argument index="2" name="default" type="Variant" default="null">
  67. </argument>
  68. <description>
  69. Returns the current value for the specified section and key. If the section and/or the key do not exist, the method returns the value of the optional [code]default[/code] argument, or [code]null[/code] if it is omitted.
  70. </description>
  71. </method>
  72. <method name="has_section" qualifiers="const">
  73. <return type="bool">
  74. </return>
  75. <argument index="0" name="section" type="String">
  76. </argument>
  77. <description>
  78. Returns [code]true[/code] if the specified section exists.
  79. </description>
  80. </method>
  81. <method name="has_section_key" qualifiers="const">
  82. <return type="bool">
  83. </return>
  84. <argument index="0" name="section" type="String">
  85. </argument>
  86. <argument index="1" name="key" type="String">
  87. </argument>
  88. <description>
  89. Returns [code]true[/code] if the specified section-key pair exists.
  90. </description>
  91. </method>
  92. <method name="load">
  93. <return type="int" enum="Error">
  94. </return>
  95. <argument index="0" name="path" type="String">
  96. </argument>
  97. <description>
  98. Loads the config file specified as a parameter. The file's contents are parsed and loaded in the ConfigFile object which the method was called on. Returns one of the [code]OK[/code], [code]FAILED[/code] or [code]ERR_*[/code] constants listed in [@Global Scope]. If the load was successful, the return value is [code]OK[/code].
  99. </description>
  100. </method>
  101. <method name="save">
  102. <return type="int" enum="Error">
  103. </return>
  104. <argument index="0" name="path" type="String">
  105. </argument>
  106. <description>
  107. Saves the contents of the ConfigFile object to the file specified as a parameter. The output file uses an INI-style structure. Returns one of the [code]OK[/code], [code]FAILED[/code] or [code]ERR_*[/code] constants listed in [@Global Scope]. If the load was successful, the return value is [code]OK[/code].
  108. </description>
  109. </method>
  110. <method name="set_value">
  111. <return type="void">
  112. </return>
  113. <argument index="0" name="section" type="String">
  114. </argument>
  115. <argument index="1" name="key" type="String">
  116. </argument>
  117. <argument index="2" name="value" type="Variant">
  118. </argument>
  119. <description>
  120. Assigns a value to the specified key of the the specified section. If the section and/or the key do not exist, they are created. Passing a [code]null[/code] value deletes the specified key if it exists, and deletes the section if it ends up empty once the key has been removed.
  121. </description>
  122. </method>
  123. </methods>
  124. <constants>
  125. </constants>
  126. </class>