namespace GodotHelpers;
using System;
using System.Linq;
using Godot;
public static class MyNodeExtensions
{
public static void FreeDeferred(this Node node) => node.CallDeferred(GodotObject.MethodName.Free);
///
/// Checks if given Property exists on Base
///
/// Current GodotObject
/// Property Name
/// bool true if given property exists on Base
public static bool HasProperty(this GodotObject Base, string PropertyName)
{
/*
Returns the object's property list as an Godot.Collections.Array of dictionaries.
Each Godot.Collections.Dictionary contains the following entries:
- name is the property's name, as a string;
- class_name is an empty StringName, unless the property is Variant.Type.Object and it inherits from a class;
- type is the property's type, as an int (see Variant.Type);
- hint is how the property is meant to be edited (see PropertyHint);
- hint_string depends on the hint (see PropertyHint);
- usage is a combination of PropertyUsageFlags.
*/
foreach (var Property in Base.GetPropertyListEx())
{
if (Property.Name == PropertyName)
{
return true;
}
}
return false;
}
public static (Node node, Resource resource, NodePath remaining) GetNodeAndResourceEx(this Node self, NodePath path)
{
var result = self.GetNodeAndResource(path);
return ((Node)result[0], (Resource)result[1], (NodePath)result[2]);
}
public static void QueueFreeChildren(this Node node) => node.GetChildren().ToList().ForEach(item => item.QueueFree());
public static void QueueFreeChildren(this Node node, Func predicate) => node.GetChildren().Where(predicate).ToList().ForEach(item => item.QueueFree());
}