Move collect children on a sepparate function

This commit is contained in:
Nicolás Badano 2015-03-02 17:53:30 -03:00
parent 472e2c5bff
commit 094be22a19
3 changed files with 60 additions and 37 deletions

View File

@ -5,6 +5,7 @@ ADDON = false;
PREP(addAction);
PREP(compileMenu);
PREP(compileMenuSelfAction);
PREP(collectActiveChildren);
PREP(keyDown);
PREP(keyDownSelfAction);
PREP(keyUp);

View File

@ -0,0 +1,58 @@
/*
* Author: CAA-Picard
* For a given action, collect all active children
*
* Argument:
* 0: Object <OBJECT>
* 1: Action data <ARRAY>
*
* Return value:
* Active children <ARRAY>
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_object,_parentAction);
private ["_activeChildren","_target","_player","_action"];
_activeChildren = [];
_target = _object;
_player = ACE_player;
// Collect children class actions
{
_action = _x;
if([_object, ACE_player] call (_action select 4)) then {
_activeChildren pushBack _action;
};
} forEach (_parentAction select 6);
// Collect children object actions
{
_action = _x;
// Check if the action is children of the selected menu
if ((count (_action select 8)) == (count (_parentAction select 8) + 1)) then {
// Compare parent path to see if it's a suitable child
private "_isChild";
_isChild = true;
{
if !(_x isEqualTo ((_action select 8) select _forEachIndex)) exitWith {
_isChild = false;
};
} forEach (_parentAction select 8);
if (_isChild) then {
if ([_target, ACE_player] call (_action select 4)) then {
_activeChildren pushBack _action;
};
};
};
} forEach GVAR(objectActions);
_activeChildren

View File

@ -95,42 +95,7 @@ if !(_menuInSelectedPath) exitWith {true};
// Collect all active children actions
private "_activeChildren";
_activeChildren = [];
// Collect children class actions
{
_target = _object;
_player = ACE_player;
_active = [_object, ACE_player] call (_x select 4);
if(_active) then {
_activeChildren pushBack _x;
};
} forEach (_actionData select 6);
// Collect children object actions
{
_actionItem = _x;
// Check if the action is children of the selected menu
if ((count (_actionItem select 8)) == (count _path)) then {
// Compare parent path to see if it's a suitable child
private "_isChild";
_isChild = true;
for "_i" from 0 to (count (_actionItem select 8)) - 2 do {
if !(((_actionItem select 8) select _i) isEqualTo (_path select (_i + 1))) exitWith {
_isChild = false;
};
};
if (_isChild) exitWith {
_target = _object;
_player = ACE_player;
_active = [_target, ACE_player] call (_actionItem select 4);
if (_active) then {
_activeChildren pushBack _actionItem;
};
};
};
} forEach GVAR(objectActions);
_activeChildren = [_object,_actionData] call FUNC(collectActiveChildren);
private ["_angleSpan","_angle"];
_angleSpan = _maxAngleSpan min (55 * ((count _activeChildren) - 1));
@ -139,7 +104,6 @@ if (_angleSpan >= 305) then {
};
_angle = _centerAngle - _angleSpan / 2;
{
_target = _object;
_player = ACE_player;