-
Notifications
You must be signed in to change notification settings - Fork 37
Config Files using Abstract Json Config class
A common use case for mods is allowing users to customize how it operates via variables that you expose through a configuration file.
SMLHelper allows you to skip most of the reinventing the wheel that often goes hand-in-hand with this very common task, with minimal boilerplate.
SMLHelper provides the ConfigFile
abstract class
in the SMLHelper.V2.Json
namespace as a base for reading/writing your own configuration files.
Usage is fairly simple:
using SMLHelper.V2.Json;
using UnityEngine;
public class MyConfig : ConfigFile
{
public int MyInt = -1; // default value
public bool MyBool = true; // default value
public KeyCode MyKeyCode = KeyCode.Space; // default value
}
public static class MyMod
{
public static MyConfig Config { get; } = new MyConfig();
public static void PatchMethod()
{
Config.Load(); // loading from disk, or populating config.json with default values if not found
Config.MyBool = false; // overriding the default value
Config.KeyCode = KeyCode.Return; // overriding the default value
Config.Save();
}
}
Upon execution of MyMod.PatchMethod()
, the above will result in a config.json
file being written to your mod's subfolder with the contents:
{
"MyInt": -1,
"MyBool": false,
"MyKeyCode": "Return"
}
In some cases, you might not want to simply save to config.json
. For example, you might be writing a particularly complicated mod and want multiple configuration files. In these cases, you can customize the file path for each ConfigFile
as following:
public class StandardConfig : ConfigFile { }
public class CustomConfig : ConfigFile
{
public CustomConfig() : base("custom") { }
}
public class CustomConfigInSubfolder : ConfigFile
{
public CustomConfigInSubfolder() : base("custom", "subfolder") { }
}
Given a mod in the folder [gamedir]\QMods\MyMod
, in the above example:
-
StandardConfig
corresponds to[gamedir]\QMods\MyMod\config.json
-
CustomConfig
corresponds to[gamedir]\QMods\MyMod\custom.json
-
CustomConfigInSubfolder
corresponds to[gamedir]\QMods\MyMod\subfolder\custom.json
For more details on ConfigFile, check the documentation in Visual Studio.
If there is something missing or ambiguous, please create an issue or contact us on the Subnautica Modding Discord using our tags:
- PrimeSonic:
@PrimeSonic#0667
- Metious:
@Metious#3682
Please note that some pages are under construction and the links to them will be enabled as they are completed
[Adding]
- Items/GameObjects using Asset Classes
- Asynchronous loading for ModPrefab
- [Custom Scanner Unlocks]
- Items/GameObjects to the Spawning System
- [Recipes to uncraftable items]
- [Custom Mouse Click Actions]
[Editing]
- Background Type
- Crafting Time
- Equipment Type
- Quick Slot Type
- Size in Inventory
- [Recipes for craftable items]
- Harvest Settings
- BioReactor Fuel Values
- [Scanning Count/Time]
- [Spawning (Where/How often/How many)]
[General Utilities]
- In-Game Options Menu
- Adding crafting recipes for other mods items
- Using items from other mods
- Texture/Sprite Utilities
- [Adding/Playing Audio]
- Config Files using Abstract Json Config class
- Custom Console Commands
- [Registering OnSave/OnQuit Actions]
[Language]