ModConfig class
A mod's settings file, Lustral/config/<id>.toml in the game folder. Users edit the file, and the mod reads it into a settings class.
public sealed class Settings
{
[Description("Show the frame rate in the corner.")]
public bool ShowFps { get; set; }
public float Volume { get; set; } = 0.8f;
}
var settings = Config.Bind<Settings>(); // in the mod classThe file is stored outside the mod's folder, so settings are preserved when the mod is updated or reinstalled.
public abstract class ModConfigConstructors
ModConfig()
protected ModConfig()Properties
FilePath
public abstract string FilePath { get; }The absolute path of the settings file.
Methods
Bind<T>()
public abstract T Bind<T>() where T : class, new();Reads the settings file into a new instance of T.
Remarks
Each public property with a getter and a setter is a setting. Its key in the file is the property name in snake_case (ShowFps becomes show_fps), and its initial value is the default. Supported types are bool, string, integer and floating-point types, enumerations (stored by name), arrays and lists of these types, and nested classes, which are stored as TOML tables. A [Description] attribute (System.ComponentModel) is written as a comment above the setting.
Missing settings keep their defaults, and the file is rewritten with all settings so that users can see them; comments added by users are not preserved. Invalid values and unknown settings are logged and ignored. If the file is not valid TOML, it is left unchanged and all settings keep their defaults.
Save<T>(T)
public abstract void Save<T>(T settings) where T : class;Writes settings to the settings file, for example after the user changes them in game.