Added common parseList function for module list parsing

This commit is contained in:
jonpas 2015-08-24 21:45:02 +02:00
parent 21aa4da4ad
commit ef2924623f
6 changed files with 80 additions and 87 deletions

View File

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

View File

@ -4,47 +4,36 @@
* 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>
*
* Return Value:
* None <NIL>
* None
*
* Example:
* ["text", "variable", value, true] call ace_common_fnc_assignObjectsInList
*
* Public: No
*/
#define DEBUG_MODE_FULL
#include "script_component.hpp"
private ["_splittedList", "_nilCheckPassedList"];
params ["_list", "_variable", "_setting", "_global"];
if (typeName _list == "STRING") then {
_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;
};
};
}foreach _splittedList;
_list = [] call compile format["[%1]",_nilCheckPassedList];
_list = [_list, true, true] call FUNC(parseList);
TRACE_1("Parsed",_list)
};
{
if (!isnil "_x") then {
if (!isNil "_x") then {
if (typeName _x == typeName objNull) then {
if (local _x) then {
_x setvariable [_variable, _setting, _global];
_x setVariable [_variable, _setting, _global];
TRACE_4("Set variable",_x,_variable,_setting,_global);
};
};
};
}foreach _list;
true
} count _list;

View File

@ -0,0 +1,61 @@
/*
* Author: 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
*/
#define DEBUG_MODE_FULL
#include "script_component.hpp"
private ["_splittedList", "_whitespaceList", "_nilCheckedList"];
params ["_list", ["_removeWhitespace", false], ["_checkNil", false]];
// Split using comma delimiter
_splittedList = [_list, ","] call BIS_fnc_splitString;
// Remove or Trim Whitespace
_whitespaceList = [];
{
if (_removeWhitespace) then {
_whitespaceList pushBack ([_x] call FUNC(stringRemoveWhiteSpace));
} else {
_whitespaceList pushBack ([_x] call CBA_fnc_trim);
};
nil
} count _splittedList;
_list = _whitespaceList;
// Check for object existence
_nilCheckedList = "";
if (_checkNil) then {
{
if !(isNil _x) then {
if (_nilCheckedList == "") then {
_nilCheckedList = _x;
} else {
_nilCheckedList = _nilCheckedList + "," + _x;
};
};
} count _list;
// Add Array characters and parse into array
_list = [] call compile format ["[%1]", _nilCheckedList];
};
TRACE_4("Lists",_splittedList,_whitespaceList,_nilCheckedList,_list);
_list

View File

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

View File

@ -1,57 +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"
params ["_list", "_trimWhitespace", "_checkNil"];
private ["_splittedList", "_listTrimmedWhitespace", "_nilCheckPassedList"];
// 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

@ -25,10 +25,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];
// Prepare with actions