ACE3/addons/common/functions/fnc_setSettingFromConfig.sqf

115 lines
3.5 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-09-19 21:18:07 +00:00
* 0: Config entry <CONFIG>
2015-02-03 00:13:31 +00:00
*
2015-01-30 21:56:45 +00:00
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
2015-09-19 21:18:07 +00:00
params ["_optionEntry"];
2015-01-30 21:56:45 +00:00
private _fnc_getValueWithType = {
2015-09-19 21:18:07 +00:00
params ["_optionEntry", "_typeName"];
2015-01-30 21:56:45 +00:00
private _valueConfig = (_optionEntry >> "value");
private _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
};
private _name = configName _optionEntry;
2015-02-03 00:13:31 +00:00
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
private _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
private _value = [_optionEntry, _typeName] call _fnc_getValueWithType;
2015-01-30 21:56:45 +00:00
// 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
/*private _settingData = [
2015-05-14 22:12:40 +00:00
name,
typeName,
isClientSettable,
localizedName,
localizedDescription,
possibleValues,
isForced,
defaultValue,
category
];*/
private _settingData = [
_name,
_typeName,
2015-04-14 19:43:19 +00:00
(getNumber (_optionEntry >> "isClientSettable")) > 0,
"", //getText (_optionEntry >> "displayName"), //No need to broadcast, handeled by fnc_loadSettingsLocalizedText
"", //getText (_optionEntry >> "description"), //No need to broadcast, handeled by fnc_loadSettingsLocalizedText
[], //getArray (_optionEntry >> "values"), //No need to broadcast, handeled by fnc_loadSettingsLocalizedText
getNumber (_optionEntry >> "force") > 0,
_value,
"" //getText (_optionEntry >> "category") //No need to broadcast, handeled by fnc_loadSettingsLocalizedText
];
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 = _settingData select 5;
2015-04-17 00:29:39 +00:00
{
private _text = _x;
2015-04-17 00:29:39 +00:00
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
private _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
2015-09-19 21:18:07 +00:00
// Read entry and cast it to the correct type from the existing variable
private _value = [_optionEntry, _settingData select 1] call _fnc_getValueWithType;
2015-01-30 21:56:45 +00:00
// 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
};
};