ACE3/addons/common/functions/fnc_setSettingFromConfig.sqf

116 lines
3.2 KiB
Plaintext
Raw Normal View History

2015-01-30 21:56:45 +00:00
/*
2015-03-24 04:18:00 +00:00
* Author: esteldunedain
2015-01-30 21:56:45 +00:00
* 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);
2015-02-19 20:38:51 +00:00
_valueConfig = (_optionEntry >> "value");
_value = if (isNumber (_optionEntry >> "value")) then {getNumber (_optionEntry >> "value")} else {0};
2015-02-08 21:36:00 +00:00
TRACE_3("_fnc_getValueWithType:", 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
};
if (_typeName == "COLOR") exitWith {
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");
if (_typeName == "") then {
_typeName = "SCALAR";
};
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
2015-01-30 21:56:45 +00:00
missionNamespace setVariable [_name, _value];
// Add the setting to a list on the server
// Set the variable to not forced
/*_settingData = [
_name,
_typeName,
2015-04-14 19:43:19 +00:00
_isClientSettable,
_localizedName,
_localizedDescription,
_possibleValues,
_isForced,
_defaultValue
];*/
_settingData = [
_name,
_typeName,
2015-04-14 19:43:19 +00:00
(getNumber (_optionEntry >> "isClientSettable")) > 0,
getText (_optionEntry >> "displayName"),
getText (_optionEntry >> "description"),
getArray (_optionEntry >> "values"),
getNumber (_optionEntry >> "force") > 0,
_value
];
2015-04-17 00:29:39 +00:00
//Strings in the values array won't be localized from the config, so just do that now:
/*private "_values";
2015-04-17 00:29:39 +00:00
_values = _settingData select 5;
{
_text = _x;
if (((typeName _text) == "STRING") && {(count _text) > 1} && {(_text select [0,1]) == "$"}) then {
_text = localize (_text select [1, ((count _text) - 1)]); //chop off the leading $
_values set [_forEachIndex, _text];
};
} forEach _values;*/
GVAR(settings) pushBack _settingData;
2015-01-30 21:56:45 +00:00
} else {
// The setting already exists.
// Check if it's already forced and quit
_settingData = [_name] call FUNC(getSettingData);
if (_settingData select 6) exitWith {};
2015-01-30 21:56:45 +00:00
// The setting is not forced, so update the value
// Get the type from the existing variable
_typeName = _settingData select 1;
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;
// Update the variable
2015-01-30 21:56:45 +00:00
missionNamespace setVariable [_name, _value];
// Force the setting if requested
2015-01-30 21:56:45 +00:00
if (getNumber (_optionEntry >> "force") > 0) then {
_settingData set [6, true];
2015-01-30 21:56:45 +00:00
};
};