NPCs/Implementation/Base/PatrolPath.cs
namespace Opium.AI;

/// <summary>
/// A patrol path component. Used by AI, will give them info about a set of positions they can navigate to.
/// </summary>
public class PatrolPath : Component, Component.ExecuteInEditor
{
	[Property] private List<Vector3> Nodes { get; set; } = new();

	public int Count => Nodes.Count;

	protected override void DrawGizmos()
	{
		for ( int i = 0; i < Nodes.Count; i++ )
		{
			Gizmo.Draw.Color = Color.White;
			Gizmo.Draw.LineSphere( Nodes[i], 1f );

			var nodePos = Nodes[i];

			if ( Gizmo.IsSelected )
			{
				using ( Gizmo.Scope( $"node{i}", nodePos ) )
				{
					Gizmo.Control.Position( $"node{i}/position", nodePos, out nodePos );
					Nodes[i] = nodePos;
				}
			}

			var next = Nodes[0];

			if ( i < Nodes.Count - 1 )
				next = Nodes[i + 1];

			Gizmo.Draw.Color = Color.Green;
			Gizmo.Draw.Line( nodePos, next );
		}
	}

	public Vector3 this[int i]
	{
		get { return Nodes[i]; }
		set { Nodes[i] = value; }
	}
}