ACE3/addons/common/functions/fnc_setKeyDefault.sqf

68 lines
1.9 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
*
2015-01-15 17:41:22 +00:00
* Set all keys from the 'ACE_Default_Keys' base class that are missing in the current user profile.
*
* Argument:
* 1: Overwrite existing key binds? (Bool)
*
* Return value:
* None.
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
private ["_overwrite", "_saveProfile", "_config", "_count", "_index", "_configFile", "_name", "_key", "_shft", "_ctrl", "_alt", "_keyCode", "_state"];
_overwrite = _this select 0;
_saveProfile = false;
2015-01-13 16:42:56 +00:00
_config = configFile >> "ACE_Default_Keys";
_count = count _config;
for "_index" from 0 to (_count - 1) do {
_configFile = _config select _index;
_name = format ["ACE_Key_%1", configName _configFile];
_key = profileNamespace getVariable _name;
if (isNil "_key" || {_overwrite}) then {
_key = getNumber (_configFile >> "Key");
_shft = getNumber (_configFile >> "Shift") == 1;
_ctrl = getNumber (_configFile >> "Control") == 1;
_alt = getNumber (_configFile >> "Alt") == 1;
2015-01-11 18:20:14 +00:00
_keyCode = [_key, _shft, _ctrl, _alt] call FUNC(convertKeyCode);
profileNamespace setVariable [_name, _keyCode];
_saveProfile = true;
};
};
2015-01-13 16:42:56 +00:00
_config = configFile >> "ACE_Options";
_count = count _config;
for "_index" from 0 to (_count - 1) do {
_configFile = _config select _index;
_name = format ["ACE_%1", configName _configFile];
_state = profileNamespace getVariable _name;
if (isNil "_state" || {_overwrite}) then {
_state = getNumber (_configFile >> "default") == 1;
profileNamespace setVariable [_name, _state];
_saveProfile = true;
};
};
if (_overwrite) then {
saveProfileNamespace;
diag_log text "[ACE]: Profile settings overwritten.";
} else {
if (_saveProfile) then {
saveProfileNamespace;
diag_log text "[ACE]: Encountered missing variable in profile namespace. Profile saved.";
} else {
diag_log text "[ACE]: No missing variables encountered in profile namespace.";
};
};