Settings ​

To give players control over your addon, declare its settings under options in swofty.json. They'll appear on the launcher's Addons page and in the game's ADDON SETTINGS, with values stored in the profile. Your plugin reads each one by its option id. For an example of each type, follow the settings tutorial.

Headerswofty/mixin.hpp
MembersSwoftyApi::setting, SwoftyApi::watch_setting
Featureoptions
API version3
ThreadFlow thread (for SWOFTY_ON_CHANGE and watch_setting)

Declare in the manifest ​

FieldMeaning
idLowercase letters, digits and _, starting with a letter, at most 40 characters
typetoggle, slider or choice
label, descriptionText shown to players; label defaults to the id
defaulttrue/false, a number on the slider's steps, or one of the choice values
min, max, stepSlider range. max - min is a whole number of steps, at most 100
valuesChoice values, 1 to 16: strings, or { "value", "label" }
bindsUse native for a value your plugin reads while the game runs, or db for one built into the game files, where a change needs a rebuild

To use a db option in your operation files, reference it through {{id}} and when; see database operations.

Read from C++ ​

Declare each setting with its type, the option id and a fallback. If you need to react when the player changes it, add SWOFTY_ON_CHANGE:

cpp
#include <swofty/mixin.hpp>

SWOFTY_SETTING(bool, show_panel, true);
SWOFTY_SETTING(int, ai_offset, 0);
SWOFTY_SETTING(std::string_view, team_livery, "titlesponsor");

SWOFTY_ON_CHANGE(show_panel, bool on)
{
    swofty::log("[my-addon] panel %s", on ? "on" : "off");
}

SWOFTY_ON_LOAD
{
    if (show_panel && team_livery == "replica")
        swofty::log("[my-addon] offset %d", int(ai_offset));
}

SWOFTY_ADDON()
typeOption typeConversion
booltoggle
An integer typesliderRounded to the nearest whole number
A floating-point typeslider
std::string_viewchoiceThe choice's value

SWOFTY_SETTING(type, id, fallback) declares inline const swofty::setting<type> id. You can read it as a T, as in the example above, or call get():

cpp
template <class T> struct swofty::setting {
    using type = T;
    const char *id;
    T fallback;
    T get() const;
    operator T() const;
    friend bool operator==(const setting &s, T v);
};
  • get() gives you the profile's value for the session. You'll get fallback if the loader is older than version 3 or swofty.json has no option with that id and type.
  • To name your variable differently from the option id, construct swofty::setting<T>{"id", fallback} directly.
  • When the player changes a value in ADDON SETTINGS, SWOFTY_ON_CHANGE runs with the new value.
  • At init, SWOFTY_ADDON() checks every setting you've declared. It logs each one that swofty.json doesn't declare with the same type.

Read from C ​

c
enum { SWOFTY_SETTING_TOGGLE = 1, SWOFTY_SETTING_SLIDER = 2, SWOFTY_SETTING_CHOICE = 3 };

typedef struct SwoftySettingValue {
    uint32_t type;
    int32_t toggle;
    double slider;
    const char *choice;
} SwoftySettingValue;

typedef void (*SwoftySettingFn)(const char *id, const SwoftySettingValue *value, void *user);
  • To read a value, call api->setting(id, type, &out). It fills out with the calling addon's value and returns non-zero. If the addon has no option id of that type, it returns 0.
  • To react to changes, call api->watch_setting(id, fn, user). It calls fn with user on every change.

Both calls need API version 3 and identify your addon by the calling DLL.

Files ​

FileWritten byHolds
$DATA/profiles/<name>.jsonThe launcheroptions: each addon's values that differ from the default
swofty/settings.jsonThe buildEvery enabled addon with its options, values and the commands ADDON SETTINGS sends
The requests fileswofty_coreChanges made in game, merged into the profile by the launcher
Publishing