-
Notifications
You must be signed in to change notification settings - Fork 6
3. Creating, saving and loading configs
one-nora edited this page May 16, 2026
·
3 revisions
WKLib config is built around folders, files, and typed values.
-
ConfigFolderowns folders and files -
ConfigFilereads and writes JSON -
ConfigValue<T>binds a typed value to a JSON key
- Create
ConfigValue<T>objects using yourWKLibAPIinstance - Modify values when needed
- Call
SaveSync()orSaveAsync()to save changes
This flow uses the default config file. To make more files check the full doc.
Represents a folder directory, when created it will use the "BepInEx/config" directory.
For example, doing new ConfigFolder("MyMod") will use the "BepInEx/config/MyMod" directory.
By default the WKLibAPI instance creates a config folder using the DisplayName field (which would look like so "BepInEx/config/{DisplayName}").
ConfigFolder(string folderName)
ConfigFolder(ConfigFolder parent, string folderName)var myFolder = new ConfigFolder("MyFolder");Creating a nested folder
var subFolder = new ConfigFolder(myFolder, "MySubFolder");-
BasePathfull folder path -
FolderNamefolder name only
GetSubFolder(string folderName)CreateSubFolder(string folderName)GetOrCreateSubFolder(string folderName)RegisterConfigFolder(string folderName)
GetConfigFile(string fileName)CreateConfigFile(string fileName)GetOrCreateConfigFile(string fileName)RegisterConfigFile(string fileName)
-
LoadFiles()scans for JSON files and subfolders -
GetConfigFolders()returns a copy of subfolders -
GetConfigFiles()returns a copy of config files -
EnumerateFiles()recursively enumerates files
Represents one JSON file on disk.
ConfigFile(ConfigFolder configFolder, string fileName)
ConfigFile(WKLibAPI api, string fileName)// Will be created on ../BepInEx/config/FolderName/Settings.json
var file = new ConfigFile(folder, "Settings");// This needs the API instance to be created
// Will be created on ../BepInEx/config/ModName/Settings.json
var file = new ConfigFile(WKLibAPI, "Settings");-
FilePathfull path to the JSON file -
FullFileNamefile name with extension -
FileNamefile name without extension
-
LoadFromDisk()reads the file and loads the values -
SaveAsync()writes the current values to disk -
SaveSync()synchronous wrapper forSaveAsync()
TryGetParsedToken(string key, out JToken token)TryGetParsedValueObject(string key, out object value)
- The
.jsonextension is appended automatically when needed
ConfigValue<T> stores a typed value bound to a ConfigFile.
ConfigValue(ConfigFile file, string key, T currentValue, bool loadOnCreation = true)
ConfigValue(WKLibAPI api, string key, T currentValue, bool loadOnCreation = true)public static ConfigValue<float> speed = new ConfigValue<float>(file, "MoveSpeed", 5f);// Uses the default config file
public static ConfigValue<float> speed = new ConfigValue<float>(WKLibAPI, "MoveSpeed", 5f);-
Valuecurrent value -
RefValuegivesrefaccess to the stored value
- JSON parse errors are ignored
- implicit conversion to
Value