Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Global configuration

Arnis Lielturks edited this page Jul 6, 2018 · 8 revisions

Global game configuration

When game is launched a config file located in Data/Config/Game.json is loaded. These values are globally used in the system which can specifiy all sorts of settings that users may want to change and use between game sessions. For instance it can contain all the user configured game settings - shadow quality, texture quality, resolution, sound settings etc.

Config file content looks like this:

{
	"ResourcePaths": "Data;CoreData",
	"ScreenWidth": 800,
	"ScreenHeight": 600,
	"Fullscreen": false,
	"FrameLimiter": true,
	"LowQualityShadows": false,
	"MaterialQuality": 15,
	"Monitor": 1,
	"MultiSample": 1,
	"Shadows": true,
	"TextureAnisotropy": 4,
	"TextureFilterMode": 3,
	"TextureQuality": 2,
	"TripleBuffer": true,
	"VSync": true,
	"Sound": true,
	"SoundBuffer": 100,
	"SoundMixRate": 44100,
	"SoundInterpolation": true,
	"SoundStereo": true
}

BaseApplication::LoadConfig() is the method that loads this file after starting game. To retrieve any values in the code you have to call one of these methods:

GetGlobalVar("VSync").GetBool();
GetGlobalVar("ScreenWidth").GetInt();
GetGlobalVar("ResourcePaths").GetString();

Configuration saving is done by calling MyEvents::E_SAVE_CONFIG event. C++ and Angelscript

SendEvent("SaveConfig");

When this event is called application will save only the settings which were pressent when the config file was loaded. To add new values for storing them into the config file you must call the following event

C++ and AngelScript

VariantMap data;
data["Name"] = "MyTestVariable";
SendEvent("AddConfig", data);

This will register the MyTestVariable as a config key. When the actual saving process starts, it will map all the registered config keys to the engine global variables so in this case you must provide a value for the MyTestVariable variable.

C++ and AngelScript

SetGlobalVar("MyTestVariable", 123);

If everything was succesfull the saved Data/Config/Config.json will look like this

{
    .....
    "SoundStereo": true,
    "MyTestVariable": 123
}

Supported config file values

At the moment config file supports only String, integer, boolean and float values!

Custom config file loading

There might be cases where you would like to load custom configuration file for specific mod or addon. You can load custom configuration file in the following way.

C++ and AngelScript

VariantMap data;
data["Filepath"] = "Data/Mods/Helpers/Config.json";
data["Prefix"] = "Debugger_";
SendEvent("LoadConfig", data);

LoadConfig event accepts 2 parameters - Filepath and Prefix

Filepath - config file location relative to executable file

Prefix - prefix for configuration values

Data/Mods/Helpers/Config.json file content:

{
    "Developer": "Arnis"
}

In the sample all the values which will be loaded from the Data/Mods/Helpers/Config.json file will be accessible like this:

C++ and AngelScript

GetGlobalVar("Debugger_Developer").GetString()
Clone this wiki locally