using Sandbox;

namespace VeloX;


public abstract partial class VeloXBase : Component
{
	[Sync] public WaterState WaterState { get; set; }
	[Sync] public bool IsEngineOnFire { get; set; }
	[Property, Sync] public EngineState EngineState { get; set; }

	[Property] public Vector3 AngularDrag { get; set; } = new( -0.1f, -0.1f, -3 );
	[Property] public float Mass { get; set; } = 900;
	[Property, Group( "Components" )] public Rigidbody Body { get; protected set; }
	[Property, Group( "Components" )] public Collider Collider { get; protected set; }

	[Sync( SyncFlags.Interpolate )] public Angles SteerAngle { get; set; }

	public Vector3 LocalVelocity;
	public float ForwardSpeed;
	public float TotalSpeed;

	protected override void OnFixedUpdate()
	{
		if ( IsProxy )
			return;

		LocalVelocity = WorldTransform.PointToLocal( WorldPosition + Body.Velocity );
		ForwardSpeed = LocalVelocity.x;
		TotalSpeed = LocalVelocity.Length;
		Body.PhysicsBody.Mass = Mass;

		FixedUpdate();
	}

	protected virtual void FixedUpdate()
	{

		UpdateInput();
		PhysicsSimulate();
	}

}
