using Godot; using System.Collections.Generic; namespace Rokojori { public class Nodes { public static T GetSibling( Node node ) where T:Node { if ( node == null ) { return null; } var parent = node.GetParent(); if ( parent == null ) { return null; } return GetDirectChild( parent ); } public static T GetDirectChild( Node parent ) where T:Node { if ( parent == null ) { return null; } var numChildren = parent.GetChildCount(); for ( int i = 0; i < numChildren; i++ ) { var node = parent.GetChild( i ); if ( node is T ) { return (T) node; } } return null; } public static List GetDirectChildren( Node parent ) where T:Node { if ( parent == null ) { return null; } var list = new List(); var numChildren = parent.GetChildCount(); for ( int i = 0; i < numChildren; i++ ) { var node = parent.GetChild( i ); var script = node.GetScript(); RJLog.Log( "Node is", typeof(T), node.Name, node.GetType(), script.GetType(), ">>", ( node is T ) ); if ( ! ( node is T ) ) { continue; } list.Add( node as T ); } return list; } public static void ForEachDirectChild( Node parent, System.Action action ) where T:Node { if ( parent == null || action == null ) { return; } var numChildren = parent.GetChildCount(); for ( int i = 0; i < numChildren; i++ ) { var node = parent.GetChild( i ); if ( ! ( node is T ) ) { continue; } action( node as T ); } } static NodesWalker nodesWalker = new NodesWalker(); public static T GetAnyChild( Node parent ) where T:Node { return (T) nodesWalker.Find( parent, ( n )=> n is T, true ); } /* public static void Enable( Node n, bool affectProcess = true, bool affectPhysicsProcess = true, bool affectInput = true ) { SetState.SetStateOfNode( NodeStateType.Enabled, n, affectProcess, affectPhysicsProcess, affectInput ); } public static void Disable( Node n, bool affectProcess = true, bool affectPhysicsProcess = true, bool affectInput = true ) { SetState.SetStateOfNode( NodeStateType.Disabled, n, affectProcess, affectPhysicsProcess, affectInput ); } */ public static void Iterate( Node[] nodes, System.Action callback ) { for ( int i = 0; i < nodes.Length; i++ ) { nodesWalker.Iterate( nodes[ i ], callback ); } } } }