From 7924d643e53a1371836f3e3ec65e706d315f53e9 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 25 Feb 2022 01:10:02 +0100 Subject: Add `includeInternal` to C# NodeExtensions and fix get_child documentation Node methods in C# extended to use generics now have the optional parameter `includeInternal` like their non-generic equivalents. Also, fixed a typo in the `Node.get_child` documentation. --- .../GodotSharp/Core/Extensions/NodeExtensions.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs index 1dc21b6303..e9d8b98344 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs @@ -93,8 +93,12 @@ namespace Godot /// Negative indices access the children from the last one. /// To access a child node via its name, use . /// - /// + /// /// Child index. + /// + /// If , internal children are skipped (see internal + /// parameter in ). + /// /// /// Thrown when the given the fetched node can't be casted to the given type . /// @@ -102,9 +106,9 @@ namespace Godot /// /// The child at the given index . /// - public T GetChild(int idx) where T : class + public T GetChild(int idx, bool includeInternal = false) where T : class { - return (T)(object)GetChild(idx); + return (T)(object)GetChild(idx, includeInternal); } /// @@ -113,15 +117,19 @@ namespace Godot /// Negative indices access the children from the last one. /// To access a child node via its name, use . /// - /// + /// /// Child index. + /// + /// If , internal children are skipped (see internal + /// parameter in ). + /// /// The type to cast to. Should be a descendant of . /// /// The child at the given index , or if not found. /// - public T GetChildOrNull(int idx) where T : class + public T GetChildOrNull(int idx, bool includeInternal = false) where T : class { - return GetChild(idx) as T; + return GetChild(idx, includeInternal) as T; } /// -- cgit v1.2.3 From 665621aa1b6b3555ec3aceaad3c6e216cdd8cfdc Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 25 Feb 2022 01:08:09 +0100 Subject: Avoid printing an error in GetChildOrNull `GetChildOrNull` won't print an error when the given index is out of range, similar to how the LINQ `ElementAtOrDefault` method works. --- .../mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs index e9d8b98344..df0e839866 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs @@ -129,7 +129,8 @@ namespace Godot /// public T GetChildOrNull(int idx, bool includeInternal = false) where T : class { - return GetChild(idx, includeInternal) as T; + int count = GetChildCount(includeInternal); + return idx >= -count && idx < count ? GetChild(idx, includeInternal) as T : null; } /// -- cgit v1.2.3