Merge pull request #2766 from acemod/settingsErrorChecking

Add Error Checking to Settings + MapGesture Settings
This commit is contained in:
PabstMirror 2015-11-20 14:51:31 -06:00
commit f9a77a62ab
32 changed files with 172 additions and 77 deletions

View File

@ -192,6 +192,7 @@ class CfgVehicles {
scope = 2;
icon = QUOTE(PATHTOF(UI\Icon_Module_settings_ca.paa));
isGlobal = 1;
isSingular = 1;
class Arguments {
class allowHandcuffOwnSide {
displayName = CSTRING(ModuleSettings_handcuffSide_name);

View File

@ -8,6 +8,7 @@ class CfgVehicles {
function = QFUNC(moduleSettings);
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);

View File

@ -35,6 +35,7 @@ class CfgVehicles {
function = QFUNC(moduleCheckPBOs);
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_CheckPBO_ca.paa));
class Arguments {
class Action {

View File

@ -194,9 +194,17 @@ call FUNC(checkFiles);
ACE_LOGINFO("Settings received from server.");
if (isServer) then { //read settings from paramsArray
[] call FUNC(readSettingsFromParamsArray);
};
// Event so that ACE_Modules have their settings loaded:
["InitSettingsFromModules", []] call FUNC(localEvent);
if (isServer) then {
// Publish all settings data after all configs and modules are read
publicVariable QGVAR(settings);
};
// Load user settings from profile
if (hasInterface) then {
call FUNC(loadSettingsFromProfile);

View File

@ -139,6 +139,7 @@ PREP(playerSide);
PREP(positionToASL);
PREP(progressBar);
PREP(readSettingFromModule);
PREP(readSettingsFromParamsArray);
PREP(receiveRequest);
PREP(removeCanInteractWithCondition);
PREP(removeSpecificMagazine);

View File

@ -35,12 +35,23 @@ _fnc_parseConfigForDisplayNames = {
_values set [_forEachIndex, _text];
};
} forEach _values;
if (!(_values isEqualTo [])) then {
if (_typeOf != "SCALAR") then {
ACE_LOGWARNING_2("Setting [%1] has values[] but is not SCALAR (%2)", _name, _typeOf);
} else {
private _value = missionNamespace getVariable [_name, -1];
if ((_value < 0) || {_value >= (count _values)}) then {
ACE_LOGWARNING_3("Setting [%1] out of bounds %2 (values[] count is %3)(", _name, _value, count _values);
};
};
};
true
};
// Iterate through settings
{
_x params ["_name"];
_x params ["_name", "_typeOf"];
if !([configFile >> "ACE_Settings" >> _name] call _fnc_parseConfigForDisplayNames) then {
if !([configFile >> "ACE_ServerSettings" >> _name] call _fnc_parseConfigForDisplayNames) then {

View File

@ -51,8 +51,6 @@ _fnc_parseConfigForSettings = {
// mission side settings
[missionConfigFile >> "ACE_Settings"] call _fnc_parseConfigForSettings;
// Publish all settings data
publicVariable QGVAR(settings);
// Publish all setting values
{
publicVariable (_x select 0);

View File

@ -0,0 +1,63 @@
/*
* Author: PabstMirror
* Read settins from paramsArray that have a ACE_setting = 1.
* Happens before modules but after all other configs (for force priority)
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_common_fnc_readSettingsFromParamsArray
*
* Public: No
*/
#include "script_component.hpp"
//paramsArray is a normal variable not a command
private _paramsArray = missionnamespace getvariable ["paramsArray", []];
TRACE_1("Reading missionConfigFile params",_paramsArray);
{
private _config = (missionConfigFile >> "params") select _forEachIndex;
if ((getNumber (_config >> "ACE_setting")) > 0) then {
private _settingName = configName _config;
private _settingValue = _x;
private _title = getText (_config >> "title");
TRACE_3("ace_setting",_title,_settingName,_settingValue);
// Check if the variable is already defined
if (isNil _settingName) exitWith {
ACE_LOGERROR_1("readSettingsFromParamsArray - param [%1] is not an ace_setting", _settingName);
};
private _settingData = [_settingName] call FUNC(getSettingData);
_settingData params ["", "_typeName", "", "", "", "", "_isForced"];
// Check if it's already forced and quit
if (_isForced) exitWith {ACE_LOGWARNING_1("readSettingsFromParamsArray - param [%1] is already set and forced", _settingName);};
// The setting is not forced, so update the value
// Read entry and cast it to the correct type from the existing variable
private _validValue = false;
switch (true) do {
case (_typeName == "SCALAR"): {_validValue = true;};
case (_typeName == "BOOL"): {
_settingValue = _settingValue > 0;
_validValue = true;
};
//TODO: Handle ARRAY,COLOR,STRING??? (bool/scalar covers most important settings)
};
if (!_validValue) exitWith {
ACE_LOGWARNING_3("readSettingsFromParamsArray - param [%1] type not valid [%2] - expected type [%3]", _settingName,_settingValue,_typeName);
};
// Update the variable globaly and Force
[_settingName, _settingValue, true, true] call FUNC(setSetting);
};
} foreach _paramsArray;

View File

@ -13,27 +13,39 @@
* Return Value:
* None
*
* Example:
* ["ace_map_gestures_enabled", true, false, true] call ace_common_fnc_setSetting
*
* Public: No
*/
#include "script_component.hpp"
params ["_name", "_value", ["_force", false], ["_broadcastChanges", false]];
private ["_settingData", "_failed"];
_settingData = [_name] call FUNC(getSettingData);
private _settingData = [_name] call FUNC(getSettingData);
// Exit if the setting does not exist
if (count _settingData == 0) exitWith {};
if (_settingData isEqualTo []) exitWith {
ACE_LOGERROR_1("SetSetting [%1] setting does not exist", _name);
};
_settingData params ["", "_typeName", "_isClientSetable", "", "", "", "_isForced"];
// Exit if the setting is already forced
if (_settingData select 6) exitWith {};
if (_isForced) exitWith {
ACE_LOGINFO_1("SetSetting [%1] Trying to set forced setting", _name);
};
//This does NOT broadcast changes to GVAR(settings), so clients would not get updated force status
if ((missionNamespace getVariable [QEGVAR(modules,serverModulesRead), false]) && {!(_isForced isEqualTo _force)}) then {
ACE_LOGWARNING_3("SetSetting [%1] attempting to broadcast a change to force (%2 to %3)", _name, _isForced, _force);
};
// If the type is not equal, try to cast it
_failed = false;
private _failed = false;
if (typeName _value != _settingData select 1) then {
_failed = true;
if (_settingData select 1 == "BOOL" && typeName _value == "SCALAR") then {
if ((_typeName == "BOOL") && {typeName _value == "SCALAR"}) then {
// If value is not 0 or 1 consider it invalid and don't set anything
if (_value isEqualTo 0) then {
_value = false;
@ -44,12 +56,12 @@ if (typeName _value != _settingData select 1) then {
_failed = false;
};
};
if (_settingData select 1 == "COLOR" && typeName _value == "ARRAY") then {
if ((_typeName == "COLOR") && {typeName _value == "ARRAY"}) then {
_failed = false;
};
};
if (_failed) exitWith {};
if (_failed) exitWith {ACE_LOGERROR_3("SetSetting [%1] bad data type expected %2 got %3", _name, _typeName, typeName _value);};
// Force it if it was required
_settingData set [6, _force];

View File

@ -6,6 +6,7 @@ class ACE_ModuleExplosive: ACE_Module {
function = QUOTE(FUNC(module));
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = PATHTOF(UI\Icon_Module_Explosives_ca.paa);
class Arguments {
class RequireSpecialist {

View File

@ -7,6 +7,7 @@ class CfgVehicles {
icon = QUOTE(PATHTOF(UI\Icon_Module_finger_ca.paa));
function = QFUNC(moduleSettings);
isGlobal = 0;
isSingular = 1;
author = ECSTRING(common,ACETeam);
class Arguments {
class enabled {

View File

@ -101,6 +101,7 @@ class CfgVehicles {
function = QFUNC(moduleHearing);
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = PATHTOF(UI\Icon_Module_Hearing_ca.paa);
class Arguments {
class EnableCombatDeafness {

View File

@ -8,6 +8,7 @@ class CfgVehicles {
function = "ACE_Interaction_fnc_moduleInteraction";
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = PATHTOF(UI\Icon_Module_Interaction_ca.paa);
class Arguments {

View File

@ -23,6 +23,7 @@ class CfgVehicles {
function = QFUNC(moduleMap);
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = PATHTOF(UI\Icon_Module_Map_ca.paa);
class Arguments {
class MapIllumination {
@ -82,6 +83,7 @@ class CfgVehicles {
function = QFUNC(blueForceTrackingModule);
scope = 2;
isGlobal = 0;
isSingular = 1;
icon = PATHTOF(UI\Icon_Module_BFTracking_ca.paa);
class Arguments {
class Enabled {

View File

@ -6,11 +6,13 @@ class CfgVehicles {
displayName = CSTRING(moduleSettings_displayName);
function = QFUNC(moduleSettings);
isGlobal = 0;
isSingular = 1;
author = ECSTRING(common,ACETeam);
icon = PATHTOF(ui\icon_module_map_gestures_ca.paa);
class Arguments {
class enabled {
displayName = CSTRING(enabled_DisplayName);
description = CSTRING(enabled_description);
typeName = "BOOL";
defaultValue = 1;
};
@ -18,7 +20,7 @@ class CfgVehicles {
displayName = CSTRING(maxRange_displayName);
description = CSTRING(maxRange_description);
typeName = "NUMBER";
defaultValue = 4;
defaultValue = 7;
};
class interval {
displayName = CSTRING(interval_displayName);
@ -30,13 +32,13 @@ class CfgVehicles {
displayName = CSTRING(defaultLeadColor_displayName);
description = CSTRING(defaultLeadColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
defaultValue = "1,0.88,0,0.95";
};
class defaultColor {
displayName = CSTRING(defaultColor_displayName);
description = CSTRING(defaultColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
defaultValue = "1,0.88,0,0.7";
};
};
};
@ -53,13 +55,13 @@ class CfgVehicles {
displayName = CSTRING(leadColor_displayName);
description = CSTRING(leadColor_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
defaultValue = "1,0.88,0,0.95";
};
class color {
displayName = CSTRING(color_displayName);
description = CSTRING(color_description);
typeName = "STRING";
defaultValue = "0,0,0,0";
defaultValue = "1,0.88,0,0.7";
};
};
};

View File

@ -1,8 +1,13 @@
#include "script_component.hpp"
if (["STMapGestures"] call EFUNC(common,isModLoaded)) exitWith {
ACE_LOGWARNING("st_map_gestures is installed - exiting [remove st_map_gestures.pbo to allow ace version]");
};
if (!hasInterface) exitWith {};
["SettingsInitialized", {
if (!GVAR(enabled)) exitWith {};
[{
if (isNull (findDisplay 12)) exitWith {};

View File

@ -17,8 +17,6 @@
*/
#include "script_component.hpp"
private ["_defaultColor", "_defaultLeadColor"];
params ["_logic", "", "_activated"];
if (!_activated || !isServer) exitWith {};
@ -27,11 +25,19 @@ if (!_activated || !isServer) exitWith {};
[_logic, QGVAR(maxRange), "maxRange"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(interval), "interval"] call EFUNC(common,readSettingFromModule);
_defaultLeadColor = call compile ("[" + (_logic getVariable ["defaultLeadColor", ""]) + "]");
if (!([_defaultLeadColor] call FUNC(isValidColorArray))) exitWith {ERROR("defaultLeadColor is not a valid color array.")};
//For default fallback colors, setting to empty ("") will not force on clients
private _defaultLeadColor = _logic getVariable ["defaultLeadColor", ""];
if (_defaultLeadColor != "") then {
_defaultLeadColor = call compile ("[" + _defaultLeadColor + "]");
if (!([_defaultLeadColor] call FUNC(isValidColorArray))) exitWith {ERROR("defaultLeadColor is not a valid color array.")};
[QGVAR(defaultLeadColor), _defaultLeadColor, true, true] call EFUNC(common,setSetting);
};
_defaultColor = call compile ("[" + (_logic getVariable ["defaultColor", ""]) + "]");
if (!([_defaultColor] call FUNC(isValidColorArray))) exitWith {ERROR("defaultColor is not a valid color array.")};
private _defaultColor = _logic getVariable ["defaultColor", ""];
if (_defaultColor != "") then {
_defaultColor = call compile ("[" + _defaultColor + "]");
if (!([_defaultColor] call FUNC(isValidColorArray))) exitWith {ERROR("defaultColor is not a valid color array.")};
[QGVAR(defaultColor), _defaultColor, true, true] call EFUNC(common,setSetting);
};
[QGVAR(defaultLeadColor), _defaultLeadColor, false, true] call EFUNC(common,setSetting);
[QGVAR(defaultColor), _defaultColor, false, true] call EFUNC(common,setSetting);
ACE_LOGINFO("Map Gestures Module Initialized.");

View File

@ -21,33 +21,13 @@
<Portuguese>Distância max. entre os jogadores para mostrar o indicador de gesto no mapa [padrão: 7 metros]</Portuguese>
<Russian>Макс. дистанция между игроками для отображения жестов на карте [по-умолчанию: 7 метров]</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadAlpha_displayName">
<English>Lead Default Alpha</English>
<Portuguese>Transparência padrão do líder</Portuguese>
<Russian>Лид. прозрачность по-умолчанию</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadAlpha_description">
<English>Fallback Alpha value for group leaders.</English>
<Portuguese>Valor de transparência alternativo para líderes de grupo</Portuguese>
<Russian>Значение прозрачности для лидеров групп.</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultAlpha_displayName">
<English>Default Alpha</English>
<Portuguese>Transparência padrão</Portuguese>
<Russian>Прозрачность по-умолчанию</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultAlpha_descriptions">
<English>Fallback Alpha value.</English>
<Portuguese>Valor alternativo de transparência</Portuguese>
<Russian>Значение прозрачности по-умолчанию.</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadColor_displayName">
<English>Lead Default Color</English>
<Portuguese>Cor padrão para o líder</Portuguese>
<Russian>Лид. цвет по-умолчанию</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultLeadColor_description">
<English>Fallback Color value for group leaders.</English>
<English>Fallback Color value for group leaders when there is no group setting. [Module: leave blank to not force on clients]</English>
<Portuguese>Valor de cor alternativa para líderes de grupo</Portuguese>
<Russian>Значение цвета для лидеров групп.</Russian>
</Key>
@ -57,30 +37,10 @@
<Russian>Цвет по-умолчанию</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_defaultColor_description">
<English>Fallback Color value.</English>
<English>Fallback Color value when there is no group setting. [Module: leave blank to not force on clients]</English>
<Portuguese>Valor alternativo de cor</Portuguese>
<Russian>Значение цвета.</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_leadAlpha_displayName">
<English>Lead Alpha</English>
<Portuguese>Transparência do líder</Portuguese>
<Russian>Лид. прозрачность</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_leadAlpha_description">
<English>Alpha value for group leaders of groups synced with this module.</English>
<Portuguese>Valor de transparência para líderes de grupo sincronizados com este módulo.</Portuguese>
<Russian>Значение прозрачности для лидеров групп, которые [группы] синхронизированы с этим модулем.</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_alpha_displayName">
<English>Alpha</English>
<Portuguese>Transparência</Portuguese>
<Russian>Прозрачность</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_alpha_description">
<English>Alpha value for group members of groups synced with this module.</English>
<Portuguese>Valor de transparência para membros de grupo sincronizados com este módulo.</Portuguese>
<Russian>Значение прозрачности для членов групп, которые [группы] синхронизированы с этим модулем.</Russian>
</Key>
<Key ID="STR_ACE_map_gestures_leadColor_displayName">
<English>Lead Color</English>
<Portuguese>Cor do líder</Portuguese>

View File

@ -17,6 +17,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(moduleMedicalSettings));
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
@ -153,6 +154,7 @@ class CfgVehicles {
function = QUOTE(FUNC(moduleAdvancedMedicalSettings));
functionPriority = 10;
isGlobal = 2;
isSingular = 1;
isTriggerActivated = 0;
isDisposable = 0;
author = ECSTRING(common,ACETeam);
@ -274,6 +276,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(moduleReviveSettings));
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);

View File

@ -10,6 +10,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(module));
functionPriority = 1;
isGlobal = 0;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
class Arguments {

View File

@ -38,6 +38,7 @@ class CfgVehicles {
function = QFUNC(moduleMapFill);
scope = 2;
isGlobal = 0;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_microDAGR_ca.paa));
functionPriority = 0;
class Arguments {

View File

@ -52,6 +52,7 @@ class CfgVehicles {
function = QFUNC(moduleInit);
scope = 2;
isGlobal = 0;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_mk6_ca.paa));
functionPriority = 0;
class Arguments {

View File

@ -4,27 +4,32 @@
["InitSettingsFromModules", {
// TODO This is a basic and limited implementation that mimics some of the functionality from the A3 module framework, but not all of it.
// We have to execute this in the postInit XEH because on object init, the parameters of the modules are not yet available. They are if we execute it at the start of postInit execution.
private _uniqueModulesHandled = [];
{
[_x] call {
private ["_logic", "_logicType", "_config", "_isGlobal", "_isDisposable", "_isPersistent","_function"];
_logic = _this select 0;
_logicType = typeof _logic;
params ["_logic"];
private _logicType = typeof _logic;
_logic hideobject true;
if (_logic getvariable [QGVAR(initalized), false]) exitwith {};
_config = (configFile >> "CfgVehicles" >> _logicType);
private _config = (configFile >> "CfgVehicles" >> _logicType);
if !(isClass _config) exitwith {};
// isGlobal = 1;
_isGlobal = getNumber (_config >> "isGlobal") > 0;
_isDisposable = getNumber (_config >> "isDisposable") > 0;
_isPersistent = getNumber (_config >> "isPersistent") > 0 || getnumber (_config >> "isGlobal") > 1;
_function = getText (_config >> "function");
private _isGlobal = getNumber (_config >> "isGlobal") > 0;
private _isDisposable = getNumber (_config >> "isDisposable") > 0;
private _isPersistent = getNumber (_config >> "isPersistent") > 0 || getnumber (_config >> "isGlobal") > 1;
private _isSingular = getNumber (_config >> "isSingular") > 0;
private _function = getText (_config >> "function");
if (isnil _function) then {
_function = compile _function;
} else {
_function = missionNamespace getvariable _function;
};
if (_isSingular && {_logicType in _uniqueModulesHandled}) then { //ToDo: should this be an exit?
ACE_LOGWARNING_1("Module [%1] - More than 1 singular module placed", _logicType);
};
if (_isSingular) then {_uniqueModulesHandled pushBack _logicType;};
if (_isGlobal || isServer) then {
[_logic, (synchronizedObjects _logic), true] call _function;
@ -38,7 +43,7 @@
deleteVehicle _logic;
};
};
}foreach GVAR(moduleInitCollection);
} forEach GVAR(moduleInitCollection);
if (isServer) then {
GVAR(serverModulesRead) = true;

View File

@ -7,6 +7,7 @@ class CfgVehicles {
function = QFUNC(moduleNameTags);
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_NameTags_ca.paa));
class Arguments {
class showPlayerNames {

View File

@ -8,6 +8,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(moduleAllowConfigExport));
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
class Arguments {

View File

@ -25,6 +25,7 @@ class CfgVehicles {
function = QFUNC(moduleRepairSettings);
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(Common,ACETeam);
class Arguments {

View File

@ -7,6 +7,7 @@ class CfgVehicles {
function = QFUNC(moduleInit);
scope = 2;
isGlobal = 1;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_Sitting_ca.paa));
class Arguments {
class enable {

View File

@ -74,6 +74,7 @@ class CfgVehicles {
function = QFUNC(moduleInit);
scope = 2;
isGlobal = 0;
isSingular = 1;
icon = QUOTE(PATHTOF(UI\Icon_Module_VehicleLock_ca.paa));
functionPriority = 0;
class Arguments {

View File

@ -7,6 +7,7 @@ class CfgVehicles {
displayName = CSTRING(Module_DisplayName);
scope = 2;
isGlobal = 1;
isSingular = 1;
//icon = ""; // needs an icon
class Arguments {
class moduleViewDistanceEnabled {

View File

@ -8,6 +8,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(initModuleSettings));
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
class Arguments {

View File

@ -8,6 +8,7 @@ class CfgVehicles {
function = QUOTE(DFUNC(initModuleSettings));
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
class Arguments {

View File

@ -23,6 +23,7 @@ class CfgVehicles {
function = QFUNC(moduleZeusSettings);
functionPriority = 1;
isGlobal = 1;
isSingular = 1;
isTriggerActivated = 0;
author = "SilentSpike";
class Arguments {