rj-action-library/Runtime/Actions/ActionList.cs

69 lines
1.5 KiB
C#

using Godot;
namespace Rokojori
{
/** <summary for="class ActionList">
<title>
Executes multiple actions (RJAction) at once.
</title>
<description>
The ActionList, which is an RJAction itself, executes all actions stored in the member 'actions' and also child nodes
that extend RJAction, when 'triggerDirectChildren' is checked.
</description>
</summary>
*/
[GlobalClass, Icon("res://Scripts/Rokojori/Rokojori-Action-Library/Icons/RJActionList.svg") ]
public partial class ActionList : RJAction
{
/** <summary for="field actions">Actions to execute</summary>*/
[Export]
public RJAction[] actions;
/** <summary for="field triggerDirectChildren">Whether to execute RJAction child nodes</summary>*/
[Export]
public bool triggerDirectChildren = true;
public override void _OnTrigger()
{
if ( actions != null )
{
for ( int i = 0; i < actions.Length; i++ )
{
Actions.Trigger( actions[ i ] );
}
}
if ( ! triggerDirectChildren )
{
return;
}
Nodes.ForEachDirectChild<RJAction>( this, a => Actions.Trigger( a ) );
/*
var childCount = GetChildCount();
for ( int i = 0; i < childCount; i++ )
{
var action = GetChild( i ) as RJAction;
if ( action == null )
{
continue;
}
Actions.Trigger( action );
}
*/
}
}
}