Merge pull request #2257 from jonpas/parseList

Parse List Common Function
This commit is contained in:
Glowbal 2015-10-18 12:14:18 +02:00
commit 76efdbcc1c
12 changed files with 120 additions and 220 deletions

View File

@ -133,6 +133,7 @@ PREP(numberToDigitsString);
PREP(numberToString);
PREP(onAnswerRequest);
PREP(owned);
PREP(parseList);
PREP(player);
PREP(playerSide);
PREP(positionToASL);

View File

@ -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

View File

@ -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

View File

@ -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",""];
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);
};

View File

@ -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
@ -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);
};

View File

@ -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

View File

@ -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
};

View File

@ -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

View File

@ -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
};

View File

@ -5,7 +5,6 @@ ADDON = false;
PREP(addSlideActions);
PREP(autoTransition);
PREP(createSlideshow);
PREP(makeList);
PREP(moduleInit);
GVAR(slideshows) = 0;

View File

@ -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 <STRING>
* 1: Trim Whitespace <BOOL>
* 2: Check Nil <BOOL>
*
* Return Value:
* Parsed List <ARRAY>
*
* 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

View File

@ -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