2015-01-30 21:56:45 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: esteldunedain
|
2015-02-03 04:45:04 +00:00
|
|
|
* Change the value of an existing setting if it was not previously forced. Force if neccesary.
|
|
|
|
* If executed on clients it has local effect.
|
|
|
|
* If executed on server it can have global effect if the last parameter is set to true.
|
2015-01-30 21:56:45 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-09-19 21:18:07 +00:00
|
|
|
* 0: Setting name <STRING>
|
|
|
|
* 1: Value <ANY>
|
|
|
|
* 2: Force it? (default: false) <BOOL>
|
|
|
|
* 3: Broadcast the change to all clients (default: false) <BOOL>
|
2015-01-30 21:56:45 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2015-10-18 23:49:03 +00:00
|
|
|
* Example:
|
|
|
|
* ["ace_map_gestures_enabled", true, false, true] call ace_common_fnc_setSetting
|
|
|
|
*
|
2015-01-30 21:56:45 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-09-19 21:18:07 +00:00
|
|
|
params ["_name", "_value", ["_force", false], ["_broadcastChanges", false]];
|
2015-05-14 18:06:06 +00:00
|
|
|
|
2015-11-17 20:02:20 +00:00
|
|
|
private _settingData = [_name] call FUNC(getSettingData);
|
2015-01-30 21:56:45 +00:00
|
|
|
|
2015-02-03 04:45:04 +00:00
|
|
|
// Exit if the setting does not exist
|
2015-10-19 04:34:11 +00:00
|
|
|
if (_settingData isEqualTo []) exitWith {
|
|
|
|
ACE_LOGERROR_1("SetSetting [%1] setting does not exist", _name);
|
|
|
|
};
|
2015-10-18 23:49:03 +00:00
|
|
|
|
|
|
|
_settingData params ["", "_typeName", "_isClientSetable", "", "", "", "_isForced"];
|
2015-02-03 04:45:04 +00:00
|
|
|
|
|
|
|
// Exit if the setting is already forced
|
2015-10-18 23:49:03 +00:00
|
|
|
if (_isForced) exitWith {
|
|
|
|
ACE_LOGINFO_1("SetSetting [%1] Trying to set forced setting", _name);
|
|
|
|
};
|
|
|
|
|
|
|
|
//This does NOT broadcast changes to GVAR(settings), so clients would not get updated force status
|
|
|
|
if ((missionNamespace getVariable [QEGVAR(modules,serverModulesRead), false]) && {!(_isForced isEqualTo _force)}) then {
|
|
|
|
ACE_LOGWARNING_3("SetSetting [%1] attempting to broadcast a change to force (%2 to %3)", _name, _isForced, _force);
|
|
|
|
};
|
2015-02-03 04:45:04 +00:00
|
|
|
|
2015-02-03 05:51:41 +00:00
|
|
|
// If the type is not equal, try to cast it
|
2015-11-17 20:02:20 +00:00
|
|
|
private _failed = false;
|
2015-09-19 21:18:07 +00:00
|
|
|
if (typeName _value != _settingData select 1) then {
|
2015-02-03 18:46:33 +00:00
|
|
|
_failed = true;
|
2015-11-28 03:08:21 +00:00
|
|
|
if ((_typeName == "BOOL") && {_value isEqualType 0}) then {
|
2015-02-03 18:46:33 +00:00
|
|
|
// If value is not 0 or 1 consider it invalid and don't set anything
|
2015-07-23 19:05:20 +00:00
|
|
|
if (_value isEqualTo 0) then {
|
2015-02-03 18:46:33 +00:00
|
|
|
_value = false;
|
|
|
|
_failed = false;
|
|
|
|
};
|
2015-07-23 19:05:20 +00:00
|
|
|
if (_value isEqualTo 1) then {
|
2015-02-03 18:46:33 +00:00
|
|
|
_value = true;
|
|
|
|
_failed = false;
|
|
|
|
};
|
2015-02-03 05:51:41 +00:00
|
|
|
};
|
2015-11-28 03:08:21 +00:00
|
|
|
if ((_typeName == "COLOR") && {_value isEqualType []}) then {
|
2015-02-03 05:51:41 +00:00
|
|
|
_failed = false;
|
|
|
|
};
|
|
|
|
};
|
2015-09-19 21:18:07 +00:00
|
|
|
|
2015-10-18 23:49:03 +00:00
|
|
|
if (_failed) exitWith {ACE_LOGERROR_3("SetSetting [%1] bad data type expected %2 got %3", _name, _typeName, typeName _value);};
|
2015-02-03 04:45:04 +00:00
|
|
|
|
|
|
|
// Force it if it was required
|
|
|
|
_settingData set [6, _force];
|
2015-01-30 21:56:45 +00:00
|
|
|
|
2015-02-03 04:45:04 +00:00
|
|
|
// Exit if the value didn't change
|
|
|
|
if (_value isEqualTo (missionNamespace getVariable _name)) exitWith {};
|
|
|
|
|
|
|
|
// Update the variable
|
|
|
|
TRACE_2("Variable Updated",_name,_value);
|
2015-01-30 21:56:45 +00:00
|
|
|
missionNamespace setVariable [_name, _value];
|
2015-02-03 04:45:04 +00:00
|
|
|
|
2015-09-19 21:18:07 +00:00
|
|
|
if (isServer && {_broadcastChanges}) then {
|
2015-02-03 05:51:41 +00:00
|
|
|
// Publicize the new value
|
|
|
|
publicVariable _name;
|
2015-02-03 04:45:04 +00:00
|
|
|
|
2015-02-03 05:51:41 +00:00
|
|
|
// Raise event globally, this publicizes eventual changes in _force status so clients can update it locally
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_settingChanged", [_name, _value, _force]] call CBA_fnc_globalEvent;
|
2015-02-03 04:45:04 +00:00
|
|
|
} else {
|
2015-02-03 05:51:41 +00:00
|
|
|
// Raise event locally
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_settingChanged", [_name, _value, _force]] call CBA_fnc_localEvent;
|
2015-02-03 04:45:04 +00:00
|
|
|
};
|