ACE3/addons/common/functions/fnc_setSettingFromConfig.sqf

80 lines
2.2 KiB
Plaintext
Raw Normal View History

2015-01-30 21:56:45 +00:00
/*
* Author: CAA-Picard
* Load a setting from config if it was not previosuly forced. Force if neccesary.
*
* Arguments:
2015-02-03 00:13:31 +00:00
* 0: Config entry (config entry)
*
2015-01-30 21:56:45 +00:00
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
2015-02-03 00:13:31 +00:00
EXPLODE_1_PVT(_this,_optionEntry);
2015-01-30 21:56:45 +00:00
_fnc_getValueWithType = {
EXPLODE_2_PVT(_this,_optionEntry,_typeName);
_value = getNumber (_optionEntry >> "value");
2015-02-03 00:13:31 +00:00
diag_log text format ["%1 %2: %3", configName _optionEntry, _typeName, _value];
2015-01-30 21:56:45 +00:00
if (_typeName == "BOOL") exitWith {
2015-02-03 00:13:31 +00:00
_value > 0
2015-01-30 21:56:45 +00:00
};
if (_typeName == "STRING") exitWith {
2015-02-03 00:13:31 +00:00
getText (_optionEntry >> "value")
2015-01-30 21:56:45 +00:00
};
if (_typeName == "ARRAY") exitWith {
2015-02-03 00:13:31 +00:00
getArray (_optionEntry >> "value")
2015-01-30 21:56:45 +00:00
};
_value
};
2015-02-03 00:13:31 +00:00
_name = configName _optionEntry;
2015-01-30 21:56:45 +00:00
// Check if the variable is already defined
2015-02-03 00:13:31 +00:00
if (isNil _name) then {
2015-01-30 21:56:45 +00:00
// That setting was not loaded yet
2015-02-03 00:13:31 +00:00
// Get type from config
_typeName = getText (_optionEntry >> "typeName");
2015-01-30 21:56:45 +00:00
2015-02-03 00:13:31 +00:00
// Read entry and cast it to the correct type
2015-01-30 21:56:45 +00:00
_value = [_optionEntry, _typeName] call _fnc_getValueWithType;
// Init the variable and publish it
missionNamespace setVariable [_name, _value];
publicVariable _name;
// Set the variable to not forced
missionNamespace setVariable [format ["%1_forced", _name], false];
publicVariable format ["%1_forced", _name];
// Add the variable to a list on the server
GVAR(settingsList) pushBack _name;
} else {
// The setting already exists.
// Check if it's already forced and quit
if (missionNamespace getVariable format ["%1_forced", _name]) exitWith {};
// The setting is not forced, so update the value
// Get the type from the existing variable
2015-02-03 00:13:31 +00:00
_typeName = typeName (missionNamespace getVariable _name);
// Read entry and cast it to the correct type
2015-01-30 21:56:45 +00:00
_value = [_optionEntry, _typeName] call _fnc_getValueWithType;
// Update the variable and publish it
missionNamespace setVariable [_name, _value];
publicVariable _name;
// Check if it needs forcing
if (getNumber (_optionEntry >> "force") > 0) then {
missionNamespace setVariable [format ["%1_forced", _name], true];
publicVariable format ["%1_forced", _name];
};
};