diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index ff06c1c3e3..e1cc807bdc 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -133,6 +133,7 @@ PREP(numberToDigitsString); PREP(numberToString); PREP(onAnswerRequest); PREP(owned); +PREP(parseList); PREP(player); PREP(playerSide); PREP(positionToASL); diff --git a/addons/common/functions/fnc_assignObjectsInList.sqf b/addons/common/functions/fnc_assignObjectsInList.sqf index 6bbb31d2dc..a09447a43a 100644 --- a/addons/common/functions/fnc_assignObjectsInList.sqf +++ b/addons/common/functions/fnc_assignObjectsInList.sqf @@ -4,50 +4,41 @@ * Used by moduleAssign* within various parts of the ACE3 project. * * Arguments: - * 0: list - * 1: variableName - * 2: value + * 0: List + * 1: Variable Name + * 2: Value * 3: Global + * 4: Vehicle (default: false) * * Return Value: - * None + * None + * + * Example: + * ["text", "variable", value, true] call ace_common_fnc_assignObjectsInList * * Public: No */ #include "script_component.hpp" -params ["_list", "_variable", "_setting", "_global"]; +params ["_list", "_variable", "_setting", "_global", ["_vehicle", false]]; if (typeName _list == "STRING") then { - private ["_splittedList", "_nilCheckPassedList"]; - - _splittedList = [_list, ","] call BIS_fnc_splitString; - _nilCheckPassedList = ""; - - { - _x = [_x] call FUNC(stringRemoveWhiteSpace); - if !(isNil _x) then { - if (_nilCheckPassedList == "") then { - _nilCheckPassedList = _x; - } else { - _nilCheckPassedList = _nilCheckPassedList + ","+ _x; - }; - }; - false - } count _splittedList; - - _list = [] call compile format["[%1]",_nilCheckPassedList]; + _list = [_list, true, true] call FUNC(parseList); + TRACE_1("Parsed",_list) }; { if (!isNil "_x") then { if (typeName _x == typeName objNull) then { if (local _x) then { - _x setvariable [_variable, _setting, _global]; + if (_vehicle) then { + (vehicle _x) setVariable [_variable, _setting, _global]; + TRACE_6("Set variable vehicle",_x,vehicle _x,typeOf (vehicle _x),_variable,_setting,_global); + } else { + _x setVariable [_variable, _setting, _global]; + TRACE_5("Set variable",_x,typeOf _x,_variable,_setting,_global); + }; }; }; }; - false } count _list; - -true diff --git a/addons/common/functions/fnc_parseList.sqf b/addons/common/functions/fnc_parseList.sqf new file mode 100644 index 0000000000..ef7eaae92a --- /dev/null +++ b/addons/common/functions/fnc_parseList.sqf @@ -0,0 +1,59 @@ +/* + * Author: Glowbal, Jonpas + * Makes a list from a string using comma as a delimiter, optionally trim or remove whitespace and check each for object existence. + * + * Arguments: + * 0: List + * 1: Remove or Trim Whitespace (default: false (trim)) + * 2: Check Nil (default: false) + * + * Return Value: + * Parsed List + * + * Example: + * ["text", true, false] call ace_common_fnc_parseList + * + * Public: No + */ +#include "script_component.hpp" + +params ["_list", ["_removeWhitespace", false], ["_checkNil", false]]; + +private ["_whitespaceList", "_nilCheckedList"]; + +// Split using comma delimiter +_list = _list splitString ","; +TRACE_1("Splitted List",_list); + + +// Remove or Trim Whitespace +_whitespaceList = []; +{ + if (_removeWhitespace) then { + _whitespaceList pushBack ([_x] call FUNC(stringRemoveWhiteSpace)); + } else { + _whitespaceList pushBack ([_x] call CBA_fnc_trim); + }; + nil +} count _list; + +_list = _whitespaceList; +TRACE_1("Whitespace List",_list); + + +// Check for object existence +if (_checkNil) then { + _nilCheckedList = []; + { + if !(isNil _x) then { + _nilCheckedList pushBack (missionNamespace getVariable _x); + }; + nil + } count _list; + + _list = _nilCheckedList; +}; + +TRACE_1("Final List",_list); + +_list diff --git a/addons/medical/functions/fnc_moduleAssignMedicRoles.sqf b/addons/medical/functions/fnc_moduleAssignMedicRoles.sqf index e295c55a2e..92814ed052 100644 --- a/addons/medical/functions/fnc_moduleAssignMedicRoles.sqf +++ b/addons/medical/functions/fnc_moduleAssignMedicRoles.sqf @@ -1,61 +1,26 @@ /* * Author: Glowbal - * Assign a medical role to a unit + * Assign a medical role to a unit. * * Arguments: - * 0: The module logic - * 1: units - * 2: activated + * 0: The module logic + * 1: Synchronized units + * 2: Activated * * Return Value: * None * * Public: No */ - #include "script_component.hpp" -private ["_setting", "_objects", "_list", "_splittedList", "_nilCheckPassedList", "_parsedList"]; -params [["_logic", objNull, [objNull]]]; +params ["_logic"]; if (!isNull _logic) then { - _list = _logic getvariable ["EnableList",""]; + private ["_list", "_setting"]; + _list = _logic getVariable ["EnableList", ""]; + _setting = _logic getVariable ["role", 0]; - _splittedList = [_list, ","] call BIS_fnc_splitString; - _nilCheckPassedList = ""; - { - _x = [_x] call EFUNC(common,stringRemoveWhiteSpace); - if !(isnil _x) then { - if (_nilCheckPassedList == "") then { - _nilCheckPassedList = _x; - } else { - _nilCheckPassedList = _nilCheckPassedList + ","+ _x; - }; - }; - } foreach _splittedList; - - _list = "[" + _nilCheckPassedList + "]"; - _parsedList = [] call compile _list; - _setting = _logic getvariable ["role",0]; - _objects = synchronizedObjects _logic; - if (!(_objects isEqualTo []) && _parsedList isEqualTo []) then { - { - if (!isnil "_x") then { - if (typeName _x == typeName objNull) then { - if (local _x) then { - _x setvariable [QGVAR(medicClass), _setting, true]; - }; - }; - }; - } foreach _objects; - }; - { - if (!isnil "_x") then { - if (typeName _x == typeName objNull) then { - if (local _x) then { - _x setvariable [QGVAR(medicClass), _setting, true]; - }; - }; - }; - } foreach _parsedList; - }; + [_list, QGVAR(medicClass), _setting, true] call EFUNC(common,assignObjectsInList); + [synchronizedObjects _logic, QGVAR(medicClass), _setting, true] call EFUNC(common,assignObjectsInList); +}; diff --git a/addons/medical/functions/fnc_moduleAssignMedicalVehicle.sqf b/addons/medical/functions/fnc_moduleAssignMedicalVehicle.sqf index 8481aaf293..2bc6d3a332 100644 --- a/addons/medical/functions/fnc_moduleAssignMedicalVehicle.sqf +++ b/addons/medical/functions/fnc_moduleAssignMedicalVehicle.sqf @@ -1,11 +1,11 @@ /* * Author: Glowbal - * Assign vehicle as a medical vehicle + * Assign vehicle as a medical vehicle. * * Arguments: - * 0: The module logic - * 1: units - * 2: activated + * 0: The module logic + * 1: Synchronized units + * 2: Activated * * Return Value: * None @@ -14,50 +14,13 @@ */ #include "script_component.hpp" -private ["_setting", "_objects", "_list", "_splittedList", "_nilCheckPassedList", "_parsedList", "_xVehicle"]; -params [["_logic", objNull, [objNull]]]; +params ["_logic"]; if (!isNull _logic) then { - _list = _logic getvariable ["EnableList",""]; + private ["_list", "_setting"]; + _list = _logic getVariable ["EnableList", ""]; + _setting = _logic getVariable ["enabled", 0]; - _splittedList = [_list, ","] call BIS_fnc_splitString; - _nilCheckPassedList = ""; - { - _x = [_x] call EFUNC(common,stringRemoveWhiteSpace); - if !(isnil _x) then { - if (_nilCheckPassedList == "") then { - _nilCheckPassedList = _x; - } else { - _nilCheckPassedList = _nilCheckPassedList + ","+ _x; - }; - }; - } foreach _splittedList; - - _list = "[" + _nilCheckPassedList + "]"; - _parsedList = [] call compile _list; - _setting = _logic getvariable ["enabled", 0]; - _objects = synchronizedObjects _logic; - if (!(_objects isEqualTo []) && _parsedList isEqualTo []) then { - { - if (!isnil "_x") then { - if (typeName _x == typeName objNull) then { - if (local _x) then { - _xVehicle = vehicle _x; - TRACE_3("setting medical vehicle", _x, _xVehicle, (typeOf _xVehicle)); - _xVehicle setvariable [QGVAR(medicClass), _setting, true]; - }; - }; - }; - } foreach _objects; - }; - { - if (!isnil "_x") then { - if (typeName _x == typeName objNull) then { - if (local _x) then { - TRACE_2("setting medical vehicle", _x, (typeOf _x)); - _x setvariable [QGVAR(medicClass), _setting, true]; - }; - }; - }; - } foreach _parsedList; + [_list, QGVAR(medicClass), _setting, true] call EFUNC(common,assignObjectsInList); + [synchronizedObjects _logic, QGVAR(medicClass), _setting, true, true] call EFUNC(common,assignObjectsInList); }; diff --git a/addons/repair/functions/fnc_moduleAddSpareParts.sqf b/addons/repair/functions/fnc_moduleAddSpareParts.sqf index 46689951a7..cceb62e10c 100644 --- a/addons/repair/functions/fnc_moduleAddSpareParts.sqf +++ b/addons/repair/functions/fnc_moduleAddSpareParts.sqf @@ -11,51 +11,35 @@ * None * * Example: - * function = "ace_repair_fnc_moduleAssignRepairVehicle" + * function = "ace_repair_fnc_moduleAddSpareParts" * * Public: No */ -#define DEBUG_MODE_FULL #include "script_component.hpp" params ["_logic"]; if (!isNull _logic) then { - private ["_list", "_part", "_amount", "_nilCheckPassedList"]; - // Module settings + private ["_list", "_part", "_amount"]; _list = _logic getVariable ["List", ""]; _part = _logic getVariable ["Part", 0]; _amount = _logic getVariable ["Amount", 1]; // Parse list - _nilCheckPassedList = ""; - { - _x = [_x] call EFUNC(common,stringRemoveWhiteSpace); - if !(isnil _x) then { - if (_nilCheckPassedList == "") then { - _nilCheckPassedList = _x; - } else { - _nilCheckPassedList = _nilCheckPassedList + "," + _x; - }; - }; - } forEach ([_list, ","] call BIS_fnc_splitString); - _list = "[" + _nilCheckPassedList + "]"; - _list = [] call compile _list; + _list = [_list, true, true] call EFUNC(common,parseList); // Add synchronized objects to list { _list pushBack _x; - } forEach (synchronizedObjects _logic); + nil + } count (synchronizedObjects _logic); if (_list isEqualTo []) exitWith {}; - TRACE_3("module info parsed",_list,_part,_amount); + TRACE_3("Module info parsed",_list,_part,_amount); + // Add spare parts { - if (!isNil "_x" && {typeName _x == typeName objNull}) then { - [_x, _amount, _part, true] call FUNC(addSpareParts); - }; - } forEach _list; + [_x, _amount, _part, true] call FUNC(addSpareParts); + } count _list; }; - -true diff --git a/addons/repair/functions/fnc_moduleAssignEngineer.sqf b/addons/repair/functions/fnc_moduleAssignEngineer.sqf index 9fb9ed8431..240a8c3b62 100644 --- a/addons/repair/functions/fnc_moduleAssignEngineer.sqf +++ b/addons/repair/functions/fnc_moduleAssignEngineer.sqf @@ -21,11 +21,9 @@ params ["_logic"]; if (!isNull _logic) then { private ["_list", "_setting"]; - _list = _logic getVariable ["EnableList",""]; - _setting = _logic getVariable ["role",0]; + _list = _logic getVariable ["EnableList", ""]; + _setting = _logic getVariable ["role", 0]; [_list, "ACE_IsEngineer", _setting, true] call EFUNC(common,assignObjectsInList); [synchronizedObjects _logic, "ACE_IsEngineer", _setting, true] call EFUNC(common,assignObjectsInList); - }; - -true +}; diff --git a/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf b/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf index 00cb847866..7150d0226b 100644 --- a/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf +++ b/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf @@ -21,11 +21,9 @@ params ["_logic"]; if (!isNull _logic) then { private ["_list", "_setting"]; - _list = _logic getVariable ["EnableList",""]; - _setting = _logic getVariable ["role",0]; + _list = _logic getVariable ["EnableList", ""]; + _setting = _logic getVariable ["role", 0]; [_list, "ACE_isRepairFacility", _setting, true] call EFUNC(common,assignObjectsInList); [synchronizedObjects _logic, "ACE_isRepairFacility", _setting, true] call EFUNC(common,assignObjectsInList); }; - -true diff --git a/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf b/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf index 69d2a2c52f..647b5fe52c 100644 --- a/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf +++ b/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf @@ -21,11 +21,9 @@ params ["_logic"]; if (!isNull _logic) then { private ["_list", "_setting"]; - _list = _logic getVariable ["EnableList",""]; - _setting = _logic getVariable ["role",0]; + _list = _logic getVariable ["EnableList", ""]; + _setting = _logic getVariable ["role", 0]; [_list, "ACE_isRepairVehicle", _setting, true] call EFUNC(common,assignObjectsInList); [synchronizedObjects _logic, "ACE_isRepairVehicle", _setting, true] call EFUNC(common,assignObjectsInList); - }; - -true +}; diff --git a/addons/slideshow/XEH_preInit.sqf b/addons/slideshow/XEH_preInit.sqf index 0f9e270896..152c02ec77 100644 --- a/addons/slideshow/XEH_preInit.sqf +++ b/addons/slideshow/XEH_preInit.sqf @@ -5,7 +5,6 @@ ADDON = false; PREP(addSlideActions); PREP(autoTransition); PREP(createSlideshow); -PREP(makeList); PREP(moduleInit); GVAR(slideshows) = 0; diff --git a/addons/slideshow/functions/fnc_makeList.sqf b/addons/slideshow/functions/fnc_makeList.sqf deleted file mode 100644 index e550e462a7..0000000000 --- a/addons/slideshow/functions/fnc_makeList.sqf +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Author: Jonpas - * Makes a list from a string using comma as a delimiter, optionally remove whitespace and check each for object existence. - * - * Arguments: - * 0: Text - * 1: Trim Whitespace - * 2: Check Nil - * - * Return Value: - * Parsed List - * - * Example: - * ["text", true, false] call ace_slideshow_fnc_makeList - * - * Public: No - */ -#include "script_component.hpp" - -private ["_splittedList", "_listTrimmedWhitespace", "_nilCheckPassedList"]; -params ["_list", "_trimWhitespace", "_checkNil"]; - -// Split using comma delimiter -_splittedList = [_list, ","] call BIS_fnc_splitString; - -// Remove whitespace -_listTrimmedWhitespace = []; -if (_trimWhitespace) then { - { - _listTrimmedWhitespace pushBack ([_x] call CBA_fnc_trim); - nil - } count _splittedList; - _list = _listTrimmedWhitespace; -}; - -// Check for object existence -_nilCheckPassedList = ""; -if (_checkNil) then { - { - if !(isNil _x) then { - if (_nilCheckPassedList == "") then { - _nilCheckPassedList = _x; - } else { - _nilCheckPassedList = _nilCheckPassedList + "," + _x; - }; - }; - } count _list; - - // Add Array characters and parse into array - _list = "[" + _nilCheckPassedList + "]"; - _list = [] call compile _list; -}; - -TRACE_4("Lists",_splittedList,_listTrimmedWhitespace,_nilCheckPassedList,_list); - -_list // return diff --git a/addons/slideshow/functions/fnc_moduleInit.sqf b/addons/slideshow/functions/fnc_moduleInit.sqf index f09dab678d..9c99d15a11 100644 --- a/addons/slideshow/functions/fnc_moduleInit.sqf +++ b/addons/slideshow/functions/fnc_moduleInit.sqf @@ -24,10 +24,10 @@ if !(_activated) exitWith {}; if (isNull _logic) exitWith {}; // Extract variables from logic -_objects = [_logic getVariable ["Objects", ""], true, true] call FUNC(makeList); -_controllers = [_logic getVariable ["Controllers", ""], true, true] call FUNC(makeList); -_images = [_logic getVariable ["Images", ""], true, false] call FUNC(makeList); -_names = [_logic getVariable ["Names", ""], true, false] call FUNC(makeList); +_objects = [_logic getVariable ["Objects", ""], true, true] call EFUNC(common,parseList); +_controllers = [_logic getVariable ["Controllers", ""], true, true] call EFUNC(common,parseList); +_images = [_logic getVariable ["Images", ""], false, false] call EFUNC(common,parseList); +_names = [_logic getVariable ["Names", ""], false, false] call EFUNC(common,parseList); _duration = _logic getVariable ["Duration", 0]; // Objects synced to the module