Skip to content

Config#

Defined in Config.hpp. Persistent key-value storage for plugin settings. Each plugin has its own config scope — keys don't collide between plugins.

Getters#

GetBool#

bool Config::GetBool(const char* key, bool defaultValue = false);

Returns the stored boolean value, or defaultValue if the key doesn't exist.

GetInt#

int32_t Config::GetInt(const char* key, int32_t defaultValue = 0);

Returns the stored integer value, or defaultValue if the key doesn't exist.

GetFloat#

float Config::GetFloat(const char* key, float defaultValue = 0.f);

Returns the stored float value, or defaultValue if the key doesn't exist.


Setters#

SetBool#

void Config::SetBool(const char* key, bool value);

Stores a boolean value. Not written to disk until Save() is called.

SetInt#

void Config::SetInt(const char* key, int32_t value);

Stores an integer value.

SetFloat#

void Config::SetFloat(const char* key, float value);

Stores a float value.


Save#

void Config::Save();

Writes all pending config changes to disk. Call this in on_unload() to persist settings.


Color Helpers#

GetColor#

Color Config::GetColor(const char* key, Color defaultColor = Color::White());

Loads a Color from 4 integer keys: key_r, key_g, key_b, key_a. Returns defaultColor if keys don't exist.

Color enemyColor = Config::GetColor("enemy", Color::Red());

SetColor#

void Config::SetColor(const char* key, Color color);

Saves a Color as 4 integer keys: key_r, key_g, key_b, key_a.

Config::SetColor("enemy", g_enemyColor);
Config::Save();

Tip

GetColor/SetColor replace the tedious pattern of 4 separate GetInt/SetInt calls per color. The key suffixes (_r, _g, _b, _a) are added automatically.


Typical Pattern#

Load settings in on_load, save them in on_unload:

static bool g_enabled = true;
static float g_range = 50.f;
static int32_t g_mode = 0;

extern "C" void on_load()
{
    g_enabled = Config::GetBool("enabled", true);
    g_range = Config::GetFloat("range", 50.f);
    g_mode = Config::GetInt("mode", 0);
}

extern "C" void on_unload()
{
    Config::SetBool("enabled", g_enabled);
    Config::SetFloat("range", g_range);
    Config::SetInt("mode", g_mode);
    Config::Save();
}

Note

Config is scoped per plugin — two plugins can both use the key "enabled" without conflicts.