game/godot

Godot3 - ConfigFile

C/H 2018. 11. 21. 08:30

ConfigFile


Inherits: Reference < Object

Category: Core

Brief Description

Helper class to handle INI-style files.
INI 스타일의 파일을 처리하는 헬퍼 클래스.

Member Functions

void erase_section ( String section )
PoolStringArray get_section_keys ( String section ) const
PoolStringArray get_sections ( ) const
Variant get_value ( String section, String key, Variant default=null ) const
bool has_section ( String section ) const
bool has_section_key ( String section, String key ) const
int load ( String path )
int save ( String path )
void set_value ( String section, String key, Variant value )

Description

This helper class can be used to store Variant values on the filesystem using INI-style formatting. The stored values are identified by a section and a key:
이 도우미 클래스는 INI 스타일 형식을 사용하여 파일 시스템에 Variant 값을 저장하는 데 사용할 수 있습니다. 저장된 값은 섹션과 키로 식별됩니다.

[section]
some_key=42
string_example="Hello World!"
a_vector=Vector3( 1, 0, 2 )

The stored data can be saved to or parsed from a file, though ConfigFile objects can also be used directly without accessing the filesystem.
저장된 데이터는 파일에 저장하거나 파싱 할 수 있습니다. 구성 파일 객체는 파일 시스템에 액세스하지 않고 직접 사용할 수도 있습니다.

The following example shows how to parse an INI-style file from the system, read its contents and store new values in it:
다음 예는 시스템에서 INI 스타일 파일을 구문 분석하고 내용을 읽고 새 값을 저장하는 방법을 보여줍니다.

var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK: # if not, something went wrong with the file loading
    # Look for the display/width pair, and default to 1024 if missing
    var screen_width = get_value("display", "width", 1024)
    # Store a variable if and only if it hasn't been defined yet
    if not config.has_section_key("audio", "mute"):
        config.set_value("audio", "mute", false)
    # Save the changes by overwriting the previous file
    config.save("user://settings.cfg")

Member Function Description

  • void erase_section ( String section )

    Deletes the specified section along with all the key-value pairs inside.
    내부의 모든 키-값 쌍과 함께 지정된 섹션을 삭제합니다.

  • PoolStringArray get_section_keys ( String section ) const

    Returns an array of all defined key identifiers in the specified section.
    지정된 섹션에 정의 된 모든 키 식별자의 배열을 반환합니다.

  • PoolStringArray get_sections ( ) const

    Returns an array of all defined section identifiers.
    모든 정의 된 섹션 식별자의 배열을 반환합니다.

  • Variant get_value ( String section, String key, Variant default=null ) const

    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 default argument, or null if it is omitted.
    지정된 섹션과 키의 현재 값을 반환합니다. 섹션 및 키가 존재하지 않으면 메서드는 선택적 default 인수의 값을 반환하고 생략되면 null을 반환합니다.

  • bool has_section ( String section ) const

    Returns true if the specified section exists.
    지정된 섹션이있는 경우 true를 반환합니다.

  • bool has_section_key ( String section, String key ) const

    Returns true if the specified section-key pair exists.
    지정된 섹션 키 쌍이있는 경우 true를 반환합니다.

  • int load ( String path )

    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 OK, FAILED or ERR_* constants listed in @GlobalScope. If the load was successful, the return value is OK.
    매개 변수로 지정된 구성 파일을 로드합니다. 파일의 내용은 메서드가 호출된 ConfigFile 객체에서 구문 분석되고 로드됩니다. @GlobalScope에 나열된 OK, FAILED 또는 ERR_* 상수 중 하나를 반환합니다. 로드가 성공하면 반환 값은 OK입니다.

  • int save ( String path )

    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 OK, FAILED or ERR_* constants listed in @GlobalScope. If the load was successful, the return value is OK.
    ConfigFile 객체의 내용을 매개 변수로 지정된 파일에 저장합니다. 출력 파일은 INI 스타일 구조를 사용합니다. @GlobalScope에 나열된 OK, FAILED 또는 ERR_* 상수 중 하나를 반환합니다. 로드가 성공하면 반환 값은 OK입니다.

  • void set_value ( String section, String key, Variant value )

    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 null value deletes the specified key if it exists, and deletes the section if it ends up empty once the key has been removed.
    지정된 섹션의 지정된 키에 값을 할당합니다. 섹션 및 키가 존재하지 않으면 생성됩니다. null 값을 전달하면 지정된 키가 있으면 삭제하고 키가 제거되면 비어있는 경우 섹션을 삭제합니다.


반응형

'game > godot' 카테고리의 다른 글

Godot3 - Compiling for Android - Troubleshooting Fail  (0) 2018.11.24
Godot3 - Compiling for Android  (0) 2018.11.23
Godot3 - I/O  (0) 2018.11.20
Godot3 - I/O Encrypting save games  (0) 2018.11.20
Godot3 - I/O Saving games  (0) 2018.11.19