-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayExtendsAlias.cs
239 lines (222 loc) · 7.99 KB
/
ArrayExtendsAlias.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
using System;
using System.Runtime.CompilerServices;
using System.Linq;
using GDC = Godot.Collections;
namespace Godot.CollectionsExtens.Array.Alias;
/// <summary>
/// We recommend using this library if you need to convert gdscript code to C# quickly.
/// </summary>
public static partial class ArrayExtensAlias
{
/// <summary>
/// Appends another array at the end of this array.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_item"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AppendArray<[MustBeVariant] T>(this GDC::Array<T> p_arr, GDC::Array<T> p_item)
{
p_arr.AddRange(p_item);
}
/// <summary>
/// Removes the first occurrence of a specific object from the Array<T>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_item"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Erase<[MustBeVariant] T>(this GDC::Array<T> p_arr, T p_item)
{
p_arr.Remove(p_item);
}
/// <summary>
/// Filters a sequence of values based on a predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_predicate"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GDC::Array<T> Filter<[MustBeVariant] T>(
this GDC::Array<T> p_arr, Func<T, bool> p_predicate)
{
return (GDC::Array<T>)p_arr.Where(p_predicate);
}
/// <summary>
/// Filters a sequence of values based on a predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_predicate"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GDC::Array<T> Filter<[MustBeVariant] T>(
this GDC::Array<T> p_arr, Func<T, int, bool> p_predicate)
{
return (GDC::Array<T>)p_arr.Where(p_predicate);
}
/// <summary>
/// Returns the zero-based index of the first occurrence of a value in the Array<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Find<[MustBeVariant] T>(this GDC::Array<T> p_arr, T item)
{
return p_arr.IndexOf(item);
}
/// <summary>
/// Returns the zero-based index of the first occurrence of a value in the List<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <param name="index"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Find<[MustBeVariant] T>(this GDC::Array<T> p_arr, T item, int index)
{
return p_arr.IndexOf(item, index);
}
/// <summary>
/// Determines whether an element is in the Array<T>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Has<[MustBeVariant] T>(this GDC::Array<T> p_arr, T item)
{
return p_arr.Contains(item);
}
/// <summary>
/// Returns a hashed 32-bit integer value representing the array and its contents.
/// Note: Arrays with equal hash values are not guaranteed to be the same,
/// as a result of hash collisions. On the countrary, arrays with different hash values are guaranteed to be different.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Hash<[MustBeVariant] T>(this GDC::Array<T> p_arr)
{
return GD.Hash(p_arr);
}
/// <summary>
/// Returns true if the array is empty ([]).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsEmpty<[MustBeVariant] T>(this GDC::Array<T> p_arr)
{
return p_arr.Count == 0;
}
/// <summary>
/// Projects each element of a sequence into a new form.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_selector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GDC::Array<TResult> Map<[MustBeVariant] T, [MustBeVariant] TResult>(
this GDC::Array<T> p_arr, Func<T, TResult> p_selector)
{
return (GDC::Array<TResult>)p_arr.Select(p_selector);
}
/// <summary>
/// Projects each element of a sequence into a new form.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_selector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GDC::Array<TResult> Map<[MustBeVariant] T, [MustBeVariant] TResult>(
this GDC::Array<T> p_arr, Func<T, int, TResult> p_selector)
{
return (GDC::Array<TResult>)p_arr.Select(p_selector);
}
/// <summary>
/// Applies an accumulator function over a sequence.
/// The specified seed value is used as the initial accumulator value,
/// and the specified function is used to select the result value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_func"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Reduce<[MustBeVariant] T>(this GDC::Array<T> p_arr, Func<T, T, T> p_func)
{
return p_arr.Aggregate(p_func);
}
/// <summary>
/// Applies an accumulator function over a sequence.
/// The specified seed value is used as the initial accumulator value,
/// and the specified function is used to select the result value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TAccumulate"></typeparam>
/// <param name="p_arr"></param>
/// <param name="seed"></param>
/// <param name="p_func"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TAccumulate Reduce<[MustBeVariant] T, [MustBeVariant] TAccumulate>(
this GDC::Array<T> p_arr, TAccumulate seed, Func<TAccumulate, T, TAccumulate> p_func)
{
return p_arr.Aggregate(seed, p_func);
}
/// <summary>
/// Applies an accumulator function over a sequence.
/// The specified seed value is used as the initial accumulator value,
/// and the specified function is used to select the result value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TAccumulate"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="seed"></param>
/// <param name="p_func"></param>
/// <param name="resultSelector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TResult Reduce<[MustBeVariant] T, [MustBeVariant] TAccumulate, [MustBeVariant] TResult>(
this GDC::Array<T> p_arr, TAccumulate seed, Func<TAccumulate, T, TAccumulate> p_func, Func<TAccumulate, TResult> resultSelector)
{
return p_arr.Aggregate(seed, p_func, resultSelector);
}
/// <summary>
/// Returns the zero-based index of the last occurrence of a value in the Array<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <param name="index"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RFind<[MustBeVariant] T>(this GDC::Array p_arr, T item, int index)
{
return p_arr.LastIndexOf(Variant.From(item), index);
}
/// <summary>
/// Gets the number of elements contained in the Array<T>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Size<[MustBeVariant] T>(this GDC::Array<T> p_arr)
{
return p_arr.Count;
}
}