rokojori_action_library/Runtime/Godot/GDGlue.cs

109 lines
1.7 KiB
C#

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