| 1 | = !ConfigFileManager = |
| 2 | [[TracNav(TracNav/TOC_Development)]] |
| 3 | |
| 4 | == Description == |
| 5 | The !ConfigFileManager loads and saves config-files. Config-files are a list of [wiki:howto/ConfigValue config-values] divided into sections. Usually one section corresponds to une class and one config-value corresponds to one variable of this class. Read [wiki:howto/ConfigFile this guide] to learn more about how to edit the config-file. |
| 6 | |
| 7 | General structure of a config-file: |
| 8 | {{{ |
| 9 | [Section1] |
| 10 | variable1=value |
| 11 | variable2=value |
| 12 | |
| 13 | [Section2] |
| 14 | other_variable1=value |
| 15 | other_variable2=value |
| 16 | other_variable3=value |
| 17 | |
| 18 | ... |
| 19 | }}} |
| 20 | |
| 21 | == Types == |
| 22 | There are several types of config-files, denoted by an enum: |
| 23 | * '''CFT_Settings''': Normal config file, usually {{{orxonox.ini}}} |
| 24 | * '''CFT_Keybindings''': Keybinding file, usually {{{keybindings.ini}}} |
| 25 | * '''CFT_JoyStickCalibration''': Special file for joystick callibration |
| 26 | |
| 27 | == Usage == |
| 28 | === Load === |
| 29 | * '''setFile('''''type, filename''''')''': Sets the path to the config-file of the given type (CFT_Settings, CFT_Keybindings, CFT_JoyStickCalibration) and loads the file. |
| 30 | |
| 31 | * '''load('''''type''''')''': Reloads the config-file of the given type if the path was already set by setFile, else loads the default file. |
| 32 | |
| 33 | When loading a config-file, the file is parsed into sections and values. Each value belongs to a section, each section usually belongs to a class. For every value a [wiki:ConfigValueContainer] is created to store the value. The container is then stored in the [wiki:Identifier] of the corresponding class (usually denoted by the section). This allows new instances of a class to get the loaded config-values without parsing the file every time. |
| 34 | |
| 35 | === Save === |
| 36 | * '''load('''''type''''')''': Saves the config-file of the given type if the path was already set by setFile, else saves the default file. |
| 37 | |
| 38 | When saving a config-file, every existing [wiki:ConfigValueContainer] writes it's value into the file, grouped into sections (where a section usually corresponds to a class). New config-values and sections are automatically added to the file. |
| 39 | |
| 40 | A config-file is usually saved after a config-value has changed (for example by using the '''config''' or '''keybind''' commands) except for temporary changes (for example by using '''tconfig''' or '''tkeybind'''). |