Creating Mod Settings

This guide outlines how to use OWML's config system to display mod settings in the settings menu.

Editing default-config.json

First things first, you're going to need to define your settings, open up default-config.json, and add an object called settings.

{
    "enabled": true,
    "settings": {

    }
}

The settings object is comprised of key-value pairs where the key is the ID of the setting and the value is the default value of that setting.

For example, if I wanted a check box called "Party Mode", I would do:

{
    "enabled": true,
    "settings": {
        "Party Mode": true
    }
}

You can also do other data types like numbers and strings

{
    "enabled": true,
    "settings": {
        "Number Of Ducks": 5,
        "Favorite Food": "Marshmallows"
    }
}

Complex Settings

Complex settings use JSON objects to allow for more customization. You can use it to add selectors:

{
    "enabled": true,
    "settings": {
        "Favorite Color": {
            "type": "selector",
            "value": "Green",
            "options": [
                "Purple",
                "Green",
                "Wrong >::("
            ]
        }
    }
}

And sliders as well:

{
    "enabled": true,
    "settings": {
        "Bumpscosity": {
            "type": "slider",
            "min": 0,
            "max": 1000,
            "value": 1
        }
    }
}

You can also seperate your options with separators:

{
    "enabled": true,
    "settings": {
        "My Cool Value": 50,
        "My Separator": {
            "type": "separator"
        },
        "My Other Cool Value But It's Below The Separator ::D": "Burger"
    }
}

Getting Values In C#

Now that we have these values defined, we can use ModHelper.Config.GetSettingsValue to grab our options.

public class MyMod : ModBehaviour {
    public void Start() {
        var partyMode = ModHelper.Config.GetSettingsValue<bool>("Party Mode");

        var numberOfDucks = ModHelper.Config.GetSettingsValue<int>("Number Of Ducks");
        var favoriteFood = ModHelper.Config.GetSettingsValue<string>("Favorite Food");

        var favoriteColor = ModHelper.Config.GetSettingsValue<string>("Favorite Color");

        // if (favoriteColor == "Wrong >::(") Application.Quit();
    }
}

If you want to listen for changes to your mod's config, you can override the Configure method, this will be passed the new config data.

public class MyMod : ModBehaviour {
    public override void Configure(IModConfig config) {
        var newFavorite = config.GetSettingsValue<string>("Favorite Food");
        ModHelper.Console.WriteLine($"You changed your favorite food to: {newFavorite}!");
    }
}