Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse List Common Function #2257

Merged
merged 12 commits into from
Oct 18, 2015
1 change: 1 addition & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ PREP(numberToDigitsString);
PREP(numberToString);
PREP(onAnswerRequest);
PREP(owned);
PREP(parseList);
PREP(player);
PREP(playerSide);
PREP(positionToASL);
Expand Down
45 changes: 18 additions & 27 deletions addons/common/functions/fnc_assignObjectsInList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,41 @@
* Used by moduleAssign* within various parts of the ACE3 project.
*
* Arguments:
* 0: list <STRING>
* 1: variableName <STRING>
* 2: value <ANY>
* 0: List <STRING>
* 1: Variable Name <STRING>
* 2: Value <ANY>
* 3: Global <BOOL>
* 4: Vehicle <BOOL> (default: false)
*
* Return Value:
* None <NIL>
* 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
59 changes: 59 additions & 0 deletions addons/common/functions/fnc_parseList.sqf
Original file line number Diff line number Diff line change
@@ -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 <STRING>
* 1: Remove or Trim Whitespace <BOOL> (default: false (trim))
* 2: Check Nil <BOOL> (default: false)
*
* Return Value:
* Parsed List <ARRAY>
*
* 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
57 changes: 11 additions & 46 deletions addons/medical/functions/fnc_moduleAssignMedicRoles.sqf
Original file line number Diff line number Diff line change
@@ -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 <LOGIC>
* 1: units <ARRAY>
* 2: activated <BOOL>
* 0: The module logic <OBJECT>
* 1: Synchronized units <ARRAY>
* 2: Activated <BOOL>
*
* 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",""];

_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;
private ["_list", "_setting"];
_list = _logic getVariable ["EnableList", ""];
_setting = _logic getVariable ["role", 0];

_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);
};
57 changes: 10 additions & 47 deletions addons/medical/functions/fnc_moduleAssignMedicalVehicle.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Author: Glowbal
* Assign vehicle as a medical vehicle
* Assign vehicle as a medical vehicle.
*
* Arguments:
* 0: The module logic <LOGIC>
* 1: units <ARRAY>
* 2: activated <BOOL>
* 0: The module logic <OBJECT>
* 1: Synchronized units <ARRAY>
* 2: Activated <BOOL>
*
* Return Value:
* None
Expand All @@ -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);
};
34 changes: 9 additions & 25 deletions addons/repair/functions/fnc_moduleAddSpareParts.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions addons/repair/functions/fnc_moduleAssignEngineer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
6 changes: 2 additions & 4 deletions addons/repair/functions/fnc_moduleAssignRepairFacility.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
1 change: 0 additions & 1 deletion addons/slideshow/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ADDON = false;
PREP(addSlideActions);
PREP(autoTransition);
PREP(createSlideshow);
PREP(makeList);
PREP(moduleInit);

GVAR(slideshows) = 0;
Expand Down
Loading