Repository navigation
Auto Config [Soft Dependency]
Can be applied on static fields/properties to simplify config management.
Basic Features:
- Config collection & parsing.
- Syncing.
Advanced Features (requires InsanityLib present):
- validation (and auto fixing if possible through attributes such as
[DefaultValue]). - Documentation in the config file.
Properties:
-
Path(Required in constructor): The path to the config file, relative to config folder. -
ServerSync(falseby default): Whether the config file should be synced from server to client.
Note: Validation can be done through Validator Attributes
Can be applied on fields/properties at the top level of the config to keep track of major config changes and how to handle them.
Properties:
-
ExpectedValue(Required in constructor): The expected value for an up to date config file. -
UpgradeMode(EConfigVersionUpgradeMode.MergeIntoNewby default): What action to take when the config is outdated.
Config values can be used from JSON using Path Resolvers
config://RelativePathToConfig/ConfigName/PropertyPath
ConfigLib Integration [Hard Dependency]
Similar to AutoConfigLib, InsanityLib automatically creates the ImGui interface for ConfigLib. For better config generation you can make use of Data Annotation attributes and code documentation.
Note: if InsanityLib is not present then configs will show up through AutoConfigLib if present
Integrated Mod Manager Integration [Hard Dependency*]
InsanityLib automatically generates or merges with your IMM file runtime, where it fills your Auto Configs into the Configuration section.
*The config file can be exported (or generated for non AutoConfigs) using the following commands and added in the normal location as fallback for when InsanityLib is not present:
/insanitylib imm export [domain] [pretty? = false]
Exports the currently loaded IMM files for a given domain.
/insanitylib imm generate [relativeConfigPath] [appSide] [typeByName] [pretty? = true]
Generates a IMM config for a specific c# type where:
-
relativeConfigPath: path relative to ModConfig folder -
appSide:ClientorServer(InsanityLib does not support mixing server and client settings in a single AutoConfig) -
typeByName:namespace.classname
Both these commands will output the file into a Exports/IMM folder inside your data folder (exact path will be printed to chat)
Note: pretty refers to the JSON file, not the actual interface
- For configs that are not synchronized you will only see the client config (this is a limitation due to how InsanityLib defines configs)
ConfigKit Integration [Hard Dependency*]
Auto Configs are automatically registered to ConfigKit which is also responsible for the rendering logic (unlike with ConfigLib) since they use the same standard data annotation attributes as this mod it should generally work out of the box.
*Right now it's a hard dependency, I will add compile time logic for optional dependency later
- Only Synchronized configs are registered (this is a limitation due to how InsanityLib defines configs)
public class InsanityLibConfig
{
[AutoConfig("InsanityLibConfig.json", ServerSync = true, CreateIfNotExist = true, DefaultOnError = true)]
public static InsanityLibConfig Instance { get; set; }
/// <summary>
/// Wether feature X is enabled or not.
/// </summary>
[DefaultValue(true)]
public bool Enable_Feature_X { get; set; } = true;
/// <summary>
/// Chance that feature Y will trigger.
/// </summary>
[DefaultValue(0.5f)]
[Range(0, 1)]
public float Feature_Y_Chance { get; set; } = 0.5f;
/// <summary>
/// Is used to identify the mod in the logs.
/// </summary>
[DefaultValue("[insanitylib]")]
[Required(AllowEmptyStrings = false, ErrorMessage = "The Debug_Identifier has to be configured, otherwise it will crash during startup")]
public string Debug_Identifier { get; set; } = "[insanitylib]";
/// <summary>
/// The version of the config file. <br />
/// This indicateds the version of the config file and is used for upgrading the config file.
/// </summary>
[ReadOnly(true)]
[VersionIdentifier(1, UpgradeMode = EConfigVersionUpgradeMode.MergeIntoNew)]
public int ConfigVersion { get; set; } = 1;
}
{
// Wether feature X is enabled or not.
// Default: True
"Enable_Feature_X": true,
// Chance that feature Y will trigger.
// Default: 0.5
// Range: 0 ~ 1
"Feature_Y_Chance": 0.5,
// Is used to identify the mod in the logs.
// Default: [insanitylib]
// Required: The Debug_Identifier has to be configured, otherwise it will crash during startup
"Debug_Identifier": "[insanitylib]",
// The version of the config file.
// This indicateds the version of the config file and is used for upgrading the config file.
"ConfigVersion": 1
}
{
"file": "game:itemtypes/part/poundercap.json",
"op": "addmerge",
"path": "/durabilitybytype",
"value": "config://WearAndTear/Server/SpecialPartsConfig/PounderCapDurability",
"condition": {
"when": "config://WearAndTear/Server/SpecialPartsConfig/Pounder",
"isValue": "true"
}
}