2022-11-27 19:37:16 -08:00
|
|
|
using Godot;
|
2023-06-13 02:55:30 -07:00
|
|
|
using GodotUtilities;
|
2022-11-27 19:37:16 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.Extensions;
|
|
|
|
|
|
|
|
public static class Node2DExtensions
|
2022-11-27 19:37:16 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
public static void RayCast(this Node2D node, Vector2 ray)
|
2022-11-27 19:37:16 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
//var spaceState = node.GetWorld2d().DirectSpaceState;
|
|
|
|
//var result = spaceState.IntersectRay();
|
2022-11-27 19:37:16 -08:00
|
|
|
}
|
2023-06-13 02:55:30 -07:00
|
|
|
|
|
|
|
public static Node CloneOnWorld(this Node2D node)
|
|
|
|
{
|
|
|
|
return CloneOnWorld<Node2D>(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static T CloneOnWorld<T>(this Node2D node) where T : Node2D
|
|
|
|
{
|
|
|
|
var world = node.GetAncestor<Scenes.Map>();
|
|
|
|
if (world is null)
|
|
|
|
{
|
|
|
|
throw new System.NullReferenceException("World does not exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
//var parent = new Node2D();
|
|
|
|
//world.AddChild(parent);
|
|
|
|
//parent.GlobalPosition = node.GlobalPosition;
|
|
|
|
var clone = node.Duplicate() as T;
|
|
|
|
world.AddChild(clone);
|
|
|
|
clone.GlobalPosition = node.GlobalPosition;
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Node AtPosition(this Node2D node, Vector2 position)
|
|
|
|
{
|
|
|
|
node.GlobalPosition = position;
|
|
|
|
return node;
|
|
|
|
}
|
2023-08-16 21:02:37 -07:00
|
|
|
|
|
|
|
public static float DistanceTo(this Node2D node, Node2D other)
|
|
|
|
{
|
|
|
|
return node.GlobalPosition.DistanceTo(other.GlobalPosition);
|
|
|
|
}
|
2022-11-27 19:37:16 -08:00
|
|
|
}
|