using Godot; using System.Text; using System; using System.Collections.Generic; using Rokojori.Extensions; namespace Rokojori; [RokojoriActionCoreExport] public class GDGlue { public static void ForEach( List array, Action callback ) { foreach ( var item in array ) { callback( item ); } } public static void AddRange( List array, List other ) { foreach ( var item in other ) { array.Add( item ); } } public static int FindIndex( List array, Predicate callback ) { var index = 0; foreach ( var item in array ) { if ( callback( item ) ) { return index; } index++; } return -1; } public static T Find( List array, Predicate callback ) { foreach ( var item in array ) { if ( callback( item ) ) { return item; } } return default(T); } #if ROKOJORI_ACTION_CORE_GD public static List GetRangeOf( List array, int index, int count ) { GDGlue.InsertGDScript( "return array.slice( index, index + count )" ); } #endif public static void CommentToGD() {} public static void InsertGDScript( string gdScript ) {} #if ROKOJORI_ACTION_CORE_GD public static Null ReturnNull() { GDGlue.InsertGDScript( "return null" ); } #endif public static int IndexOf( List array, T item ) { #if ROKOJORI_ACTION_CORE_GD GDGlue.InsertGDScript( "return array.find( item )" ); #else return 0; #endif } [RokojoriActionCoreGenericAsString] public static T NullOrDefault() { #if ROKOJORI_ACTION_CORE_GD GDGlue.InsertGDScript( "return null" ); #else return default(T); #endif } }