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
|
|
|
|
2015-05-07 19:51:03 +00:00
|
|
|
private ["_fnc_getValueWithType", "_value","_name", "_typeName", "_settingData"];
|
|
|
|
|
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");
|
2015-02-22 10:36:21 +00:00
|
|
|
_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
|
|
|
};
|
2015-02-03 03:43:23 +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");
|
2015-02-03 03:43:23 +00:00
|
|
|
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;
|
|
|
|
|
2015-02-03 04:45:04 +00:00
|
|
|
// Init the variable
|
2015-01-30 21:56:45 +00:00
|
|
|
missionNamespace setVariable [_name, _value];
|
|
|
|
|
2015-02-03 03:43:23 +00:00
|
|
|
// 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,
|
2015-02-03 03:43:23 +00:00
|
|
|
_localizedName,
|
|
|
|
_localizedDescription,
|
|
|
|
_possibleValues,
|
2015-02-03 04:03:26 +00:00
|
|
|
_isForced,
|
|
|
|
_defaultValue
|
2015-02-03 03:43:23 +00:00
|
|
|
];*/
|
|
|
|
_settingData = [
|
|
|
|
_name,
|
|
|
|
_typeName,
|
2015-04-14 19:43:19 +00:00
|
|
|
(getNumber (_optionEntry >> "isClientSettable")) > 0,
|
2015-02-03 03:43:23 +00:00
|
|
|
getText (_optionEntry >> "displayName"),
|
|
|
|
getText (_optionEntry >> "description"),
|
|
|
|
getArray (_optionEntry >> "values"),
|
2015-02-03 04:03:26 +00:00
|
|
|
getNumber (_optionEntry >> "force") > 0,
|
|
|
|
_value
|
2015-02-03 03:43:23 +00:00
|
|
|
];
|
2015-04-18 17:59:41 +00:00
|
|
|
|
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:
|
2015-04-18 17:59:41 +00:00
|
|
|
/*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];
|
|
|
|
};
|
2015-04-18 17:59:41 +00:00
|
|
|
} forEach _values;*/
|
|
|
|
|
2015-02-03 03:43:23 +00:00
|
|
|
|
|
|
|
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
|
2015-02-03 03:43:23 +00:00
|
|
|
_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
|
2015-02-03 03:43:23 +00:00
|
|
|
_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;
|
|
|
|
|
2015-02-03 04:45:04 +00:00
|
|
|
// Update the variable
|
2015-01-30 21:56:45 +00:00
|
|
|
missionNamespace setVariable [_name, _value];
|
|
|
|
|
2015-02-03 03:43:23 +00:00
|
|
|
// Force the setting if requested
|
2015-01-30 21:56:45 +00:00
|
|
|
if (getNumber (_optionEntry >> "force") > 0) then {
|
2015-02-03 03:43:23 +00:00
|
|
|
_settingData set [6, true];
|
2015-01-30 21:56:45 +00:00
|
|
|
};
|
|
|
|
};
|