From 37199f2ba29b1697810eb908456c272caab71d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Mon, 2 Feb 2015 21:14:16 -0300 Subject: [PATCH] Load client setable settings from profile --- addons/common/XEH_postInit.sqf | 3 ++ .../functions/fnc_loadSettingsFromProfile.sqf | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 addons/common/functions/fnc_loadSettingsFromProfile.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 542c4277cf..df48d076f2 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -1,6 +1,9 @@ // ACE - Common #include "script_component.hpp" +// Load settings from profile +call FUNC(loadSettingsFromProfile); + // hack to get PFH to work in briefing [QGVAR(onBriefingPFH), "onEachFrame", { if (time > 0) exitWith { diff --git a/addons/common/functions/fnc_loadSettingsFromProfile.sqf b/addons/common/functions/fnc_loadSettingsFromProfile.sqf new file mode 100644 index 0000000000..a77af66309 --- /dev/null +++ b/addons/common/functions/fnc_loadSettingsFromProfile.sqf @@ -0,0 +1,48 @@ +/* + * Author: CAA-Picard + * Load the user setable setting from the user profile. + * Config < Server UserConfig < Mission Config < Client settings + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +_fnc_setSettingFromProfile = { + EXPLODE_1_PVT(_this,_optionEntry); + + _name = configName _optionEntry; + _valueEntry = _optionEntry >> "value"; + _isClientSetable = getNumber (_optionEntry >> "isClientSetable"); + + if (_isClientSetable > 0) then { + if !(missionNamespace getVariable format ["%1_forced", _name, false]) then { + _profileValue = profileNamespace getvariable _name; + if !(isNil _profileValue) then { + if (typeName _profileValue == typeName (missionNamespace getvariable _name)) then { + missionNamespace setvariable [_name, _profileValue]; + }; + }; + }; + }; +}; + +// Iterate through settings from main config +_countOptions = count (configFile >> "ACE_Settings"); +for "_index" from 0 to (_countOptions - 1) do { + _optionEntry = (configFile >> "ACE_Settings") select _index; + [_optionEntry] call _fnc_setSettingFromProfile; + +}; + +// Iterate through settings from mission config +_countOptions = count (missionConfigFile >> "ACE_Settings"); +for "_index" from 0 to (_countOptions - 1) do { + _optionEntry = (missionConfigFile >> "ACE_Settings") select _index; + [_optionEntry] call _fnc_setSettingFromProfile; +};