Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Last updated: May 30, 2023 21:40:52

Config

Table of contents

  1. Usage

Configs are used to save and use some values in your mod that you want the end user to be able to easily change.

Usage

To start using the configs create a class that inherits the IConfig interface. For example

public class TestConfig : IConfig
{
    ...
}

Next you want want to set the filename using the ConfigFileName field. For example

public string ConfigFileName => "Filename";

Then you can add your configs as public properties. For example

public string Foo1 {get; set;}

public int Foo2 {get; set;}

Set the default values in a constructor

public TestConfig()
{
    Foo1 = "value1";
    Foo2 = 123;
}

To get a reference to the config call the IMod.Configs.Get<>() method. For example

public class FooMod: IModEntryPoint
{
    public static TestConfig Config;

    public void Entry(IMod mod, IConsoleWriter consoleWriter)
    {
        Config = mod.Configs.Get<TestConfig>();
    }
}

Calling the Get method will create the config file in your mod’s configs folder if it doesn’t exist. In this example it would be

// configs/Filename.json
{"Foo1":"value1,"Foo2":2}

Full example:

public class TestConfig : IConfig
{
    public string ConfigFileName => "Filename";

    public string Foo1 {get; set;}

    public int Foo2 {get; set;}

    public TestConfig()
    {
        Foo1 = "value1";
        Foo2 = 123;
    }
}

public class FooMod: IModEntryPoint
{
    public static TestConfig Config;

    public void Entry(IMod mod, IConsoleWriter consoleWriter)
    {
        Config = mod.Configs.Get<TestConfig>();
    }
}