Adding a Setting
jrpm's settings system is INI-driven: src/table/settings/*.ini are the setting definition sources, with code generated by settingsgen at build time; corresponding struct fields are in src/settings_type.h. Using network.content_download_parallel implemented in this project as an example.
1. Struct Field
src/settings_type.h, find the corresponding settings struct (network → NetworkSettings, game → GameSettings related substructs, scripts → ScriptSettings):
cpp
struct NetworkSettings {
// ...
std::string content_mirrors; ///< comma-separated mirror URIs
uint8_t content_download_parallel = 4; ///< number of parallel download files
// ...
};2. INI Definition
src/table/settings/network_settings.ini, append a [SDTC_VAR] block (client settings use SDTC_*, game settings use SDT_*):
ini
[SDTC_VAR]
var = network.content_download_parallel
type = SLE_UINT8
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = 4
min = 1
max = 8
cat = SC_BASICCommon fields:
| Field | Description |
|---|---|
var | Full setting name (struct path, e.g., network.xxx / game.script.xxx) |
type | SLE_UINT8/16/32/64, SLE_INT*, SLE_BOOL, SLE_STR (string, needs length) |
flags | SettingFlag::NotInSave (not saved), NoNetworkSync (not synced), NetworkOnly, GuiZeroIsSpecial, etc. |
def/min/max/interval | Default value/range/step |
str/strhelp | Display strings in the settings UI |
cat | Setting category (SC_BASIC/SC_EXPERT/SC_ADVANCED) |
3. Strings (Settings UI Display)
src/lang/english.txt:
txt
STR_CONFIG_SETTING_ALLOW_GLOBAL_AI_ACCESS :Allow AIs to access whole-game data: {STRING2}
STR_CONFIG_SETTING_ALLOW_GLOBAL_AI_ACCESS_HELPTEXT :Allow AIs to use the Global API...- Boolean settings end with
{STRING2}(on/off); - For numeric settings, reference the format of similar strings.
4. Usage in Code
cpp
// Client setting
_settings_client.network.content_download_parallel
// Game setting
_settings_game.script.allow_global_ai_access5. Special Scenarios
- Server settings:
network.*are sent by the server in multiplayer (NetworkOnly+ serversyncmechanism); - Save association: Game settings (
game.*) are saved with the save (default); client settings (network.*/gui.*) default toNotInSave; - Callbacks:
pre_cb/post_cbcan hook value change processing (e.g.,UpdateClientConfigValues()).
Completion Checklist
- [ ]
settings_type.hfield - [ ] Corresponding
.ini[SDT*_VAR]/[SDT_BOOL]/[SDTC_SSTR]block - [ ] (For settings UI display) english.txt string
- [ ] Reconfigure + build