Skip to content

Commit

Permalink
Add config property that can make settings changes stay until restart
Browse files Browse the repository at this point in the history
  • Loading branch information
veteran29 committed Oct 12, 2023
1 parent 0e49144 commit 5404e3e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addons/settings/fnc_clear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ switch (toLower _source) do {
case "server": {
if (!isServer) exitWith {};

profileNamespace setVariable [QGVAR(hash), HASH_NULL];
GVAR(serverHashNamespace) setVariable [QGVAR(hash), HASH_NULL];
saveProfileNamespace;
GVAR(client) call CBA_fnc_deleteNamespace;
GVAR(client) = [] call CBA_fnc_createNamespace;
Expand Down
2 changes: 1 addition & 1 deletion addons/settings/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _se
private _settingInfo = GVAR(userconfig) getVariable _setting;

if (isNil "_settingInfo") then {
private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL];
private _settingsHash = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL];
_settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet;
};

Expand Down
6 changes: 6 additions & 0 deletions addons/settings/fnc_initDisplayMain.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ if (_file != "") then {

uiNamespace setVariable [QGVAR(userconfig), compileFinal str _userconfig];

private _volatile = getNumber (configFile >> QGVAR(volatile)) == 1;
uiNamespace setVariable [QGVAR(volatile), _volatile];
if (_volatile) then {
WARNING("Server settings changes will be lost upon game restart.");
};

private _ctrlAddonOptions = _display displayCtrl IDC_MAIN_ADDONOPTIONS;

if (isNil QUOTE(ADDON)) then {
Expand Down
4 changes: 2 additions & 2 deletions addons/settings/fnc_set.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ switch (toLower _source) do {
private _defaultValue = [_setting, "default"] call FUNC(get);
private _defaultPriority = SANITIZE_PRIORITY(_setting,0,_source);

private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL];
private _settingsHash = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL];

if ([_value, _priority] isEqualTo [_defaultValue, _defaultPriority]) then {
[_settingsHash, toLower _setting] call CBA_fnc_hashRem;
} else {
[_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet;
};

profileNamespace setVariable [QGVAR(hash), _settingsHash];
GVAR(serverHashNamespace) setVariable [QGVAR(hash), _settingsHash];
saveProfileNamespace;
};

Expand Down
3 changes: 3 additions & 0 deletions addons/settings/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if (isNil QGVAR(default)) then {

if (isNil QGVAR(server)) then {
GVAR(server) = NAMESPACE_NULL;

private _volatile = uiNamespace getVariable QGVAR(volatile);
GVAR(serverHashNamespace) = [profileNamespace, uiNamespace] select _volatile;
};

if (isServer) then {
Expand Down
3 changes: 3 additions & 0 deletions template/cba_settings_userconfig/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ class CfgPatches {
authors[] = {"commy2"};
};
};

// Uncommenting this will make any changes to "Server" settings be lost upon game restart
// cba_settings_volatile = 1;

0 comments on commit 5404e3e

Please sign in to comment.