ConfigFile.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 an INI-style formatting. The stored values as referenced by a section and a key. The stored data can be saved to or parsed from a file, though ConfigFile objects can also be used directly with accessing the filesystem.
  8. The following example shows how to parse a INI-style file from the system, read its contents and store new values in it:
  9. [codeblock]
  10. var config = ConfigFile.new()
  11. var err = config.load("user://settings.cfg")
  12. if err == OK: # if not, something went wrong with the file loading
  13. # Look for the display/width pair, and default to 1024 if missing
  14. var screen_width = get_value("display", "width", 1024)
  15. # Store a variable if and only it hasn't been defined yet
  16. if not config.has_section_key("audio", "mute"):
  17. config.set_value("audio", "mute", false)
  18. # Save the changes by overwriting the previous file
  19. config.save("user://settings.cfg")
  20. [/codeblock]
  21. </description>
  22. <tutorials>
  23. </tutorials>
  24. <demos>
  25. </demos>
  26. <methods>
  27. <method name="erase_section">
  28. <return type="void">
  29. </return>
  30. <argument index="0" name="section" type="String">
  31. </argument>
  32. <description>
  33. </description>
  34. </method>
  35. <method name="get_section_keys" qualifiers="const">
  36. <return type="PoolStringArray">
  37. </return>
  38. <argument index="0" name="section" type="String">
  39. </argument>
  40. <description>
  41. Return an array of all defined key identifiers in the specified section.
  42. </description>
  43. </method>
  44. <method name="get_sections" qualifiers="const">
  45. <return type="PoolStringArray">
  46. </return>
  47. <description>
  48. Return an array of all defined section identifiers.
  49. </description>
  50. </method>
  51. <method name="get_value" qualifiers="const">
  52. <return type="Variant">
  53. </return>
  54. <argument index="0" name="section" type="String">
  55. </argument>
  56. <argument index="1" name="key" type="String">
  57. </argument>
  58. <argument index="2" name="default" type="Variant" default="null">
  59. </argument>
  60. <description>
  61. Return 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 [i]default[/i] argument (and thus [code]NULL[/code] if not specified).
  62. </description>
  63. </method>
  64. <method name="has_section" qualifiers="const">
  65. <return type="bool">
  66. </return>
  67. <argument index="0" name="section" type="String">
  68. </argument>
  69. <description>
  70. Check if the specified section exists.
  71. </description>
  72. </method>
  73. <method name="has_section_key" qualifiers="const">
  74. <return type="bool">
  75. </return>
  76. <argument index="0" name="section" type="String">
  77. </argument>
  78. <argument index="1" name="key" type="String">
  79. </argument>
  80. <description>
  81. Check if the specified section-key pair exists.
  82. </description>
  83. </method>
  84. <method name="load">
  85. <return type="int" enum="Error">
  86. </return>
  87. <argument index="0" name="path" type="String">
  88. </argument>
  89. <description>
  90. Load the config file specified as a parameter. The file's contents are parsed and loaded in the ConfigFile object from which the method was called. The return value is one of the OK, FAILED or ERR_* constants listed in [@Global Scope] (if the load was successful, it returns OK).
  91. </description>
  92. </method>
  93. <method name="save">
  94. <return type="int" enum="Error">
  95. </return>
  96. <argument index="0" name="path" type="String">
  97. </argument>
  98. <description>
  99. Save the contents of the ConfigFile object to the file specified as a parameter. The output file uses an INI-style structure.
  100. The return value is one of the OK, FAILED or ERR_* constants listed in [@Global Scope] (if the save was successful, it returns OK).
  101. </description>
  102. </method>
  103. <method name="set_value">
  104. <return type="void">
  105. </return>
  106. <argument index="0" name="section" type="String">
  107. </argument>
  108. <argument index="1" name="key" type="String">
  109. </argument>
  110. <argument index="2" name="value" type="Variant">
  111. </argument>
  112. <description>
  113. Assign 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).
  114. </description>
  115. </method>
  116. </methods>
  117. <constants>
  118. </constants>
  119. </class>