Skip to content

Adding new Settings

Florian Preinfalk edited this page May 25, 2015 · 1 revision

Adding new Settings

Adding new variables to GameConfigValues

First you have to add your variable to the GameConfigValues structure in GameConfig.vb. Then assign the default value in the constructor.

Public Structure GameConfigValues
    ...
    Sub New(c As Constructor)
        If c = Constructor.DefaultValues
            ...
            SomeVar = SomeVarDefaultValue
            ...
        End If
    End Sub
    ...
    Dim SomeVar As SomeVarType
    ...
End Structure

Load values from config.ini

You can load values by using getProp in GameConfig.load. It will detetect which type of variable you supply and assign the appropriate value (it takes String, Integer and Boolean)

Shared Sub load(file As String)
    ...
    getProp("section", "some_var", values.SomeVar)
    ...
End Sub

Save values to config.ini

Instead of getProp use setProp. It has the same syntax but sets the value instead.

Shared Sub save(file As String)
    ...
    setProp("section", "some_var", values.SomeVar)
    ...
End Sub

Make Options Window interact with settings

To update controls of the Options Window you have to add your code in fromGameConfigValues

Private Sub fromGameConfigValues(c As GameConfigValues)
    ...
    cbSomeVar.SelectedIndex = c.SomeVar
    ...
End Sub

To apply the new configuration you have to add your code in toGameConfigValues

Private Function toGameConfigValues() As GameConfigValues
    ...
    c.SomeVar = cbSomeVar.SelectedIndex
    ...
End Function

Load/Save Integer with String Representations

To represent an Integer as a String you have to make a Dictionary(Of String, Integer) in GameConfig and add some values to it.

Shared Public DictSomeValue As New Dictionary(Of String, Integer)
...
Shared Sub New()
    ...
    DictSomeValue.Add("string value", IntegerValue)
    ...
End Sub

Instead of getProp and setProp you should use getPropDictionary and setPropDictionary and pass the dictionary variable as the fourth parameter to the function. getPropDictionary looks the String value up in the dicionary and set the variable to the corresponding Integer value. setPropDictionary will look the Integer in the dictionary up and saves the String