Skip to content

Commit 59cd305

Browse files
author
chiepomme
committed
Add Godot documentation
1 parent 1a60cb0 commit 59cd305

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

Images/godot.jpg

19.7 KB
Loading

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Zero allocation LINQ with Span and LINQ to SIMD, LINQ to Tree (FileSystem, GameO
1515

1616
I aimed to create not just an experimental library but a practical one. It's also designed to handle high-load requirements, such as those found in games.
1717

18-
You can install it from [NuGet/ZLinq](https://www.nuget.org/packages/ZLinq). For Unity usage, refer to the [Unity section](#unity).
18+
You can install it from [NuGet/ZLinq](https://www.nuget.org/packages/ZLinq). For Unity usage, refer to the [Unity section](#unity). For Godot usage, refer to the [Godot section](#godot).
1919

2020
```bash
2121
dotnet add package ZLinq
@@ -271,6 +271,57 @@ var foobars = root.Descendants().Where(x => x.tag == "foobar");
271271
var fooScripts = root.ChildrenAndSelf().OfComponent<FooScript>();
272272
```
273273

274+
Godot
275+
---
276+
The minimum supported Godot version will be `4.0.0`.
277+
You can install ZLinq.Godot package via NuGet.
278+
279+
```bash
280+
dotnet add package ZLinq.Godot
281+
```
282+
283+
In addition to the standard ZLinq, LINQ to Node functionality is available.
284+
285+
![](Images/godot.jpg)
286+
287+
```csharp
288+
using Godot;
289+
using ZLinq;
290+
291+
public partial class SampleScript : Node2D
292+
{
293+
public override void _Ready()
294+
{
295+
var origin = GetNode<Node2D>("Container/Origin");
296+
297+
GD.Print("Ancestors--------------"); // Container, Root, root (Root Window)
298+
foreach (var item in origin.Ancestors()) GD.Print(item.Name);
299+
300+
GD.Print("Children--------------"); // Sphere_A, Sphere_B, Group, Sphere_A, Sphere_B
301+
foreach (var item in origin.Children()) GD.Print(item.Name);
302+
303+
GD.Print("Descendants--------------"); // Sphere_A, Sphere_B, Group, P1, Group, Sphere_B, P2, Sphere_A, Sphere_B
304+
foreach (var item in origin.Descendants()) GD.Print(item.Name);
305+
306+
GD.Print("BeforeSelf--------------"); // C1, C2
307+
foreach (var item in origin.BeforeSelf()) GD.Print(item.Name);
308+
309+
GD.Print("AfterSelf--------------"); // C3, C4
310+
foreach (var item in origin.AfterSelf()) GD.Print(item.Name);
311+
}
312+
}
313+
314+
```
315+
316+
You can chain query(LINQ to Objects). Also, you can filter by node type using the `OfType()`.
317+
318+
```csharp
319+
// get ancestors under a Window
320+
var ancestors = root.Ancestors().TakeWhile(x => x is not Window);
321+
// get FooScript under self childer objects and self
322+
var fooScripts = root.ChildrenAndSelf().OfType(default(FooScript));
323+
```
324+
274325
License
275326
---
276327
This library is under MIT License.

0 commit comments

Comments
 (0)