using Sandbox;
using System;

namespace VeloX;

[Group( "VeloX" )]
[Title( "VeloX - Car" )]
public partial class VeloXCar : VeloXBase
{
	protected override void OnAwake()
	{
		base.OnAwake();

		StreamPlayer = new( Stream );
	}
	protected override void OnStart()
	{
		base.OnStart();

		if ( !IsProxy )
		{
			UpdateGearList();
			UpdatePowerDistribution();
		}
	}

	protected override void OnUpdate()
	{
		base.OnUpdate();
		if ( StreamPlayer is not null )
		{

			StreamPlayer.Throttle = Throttle;
			StreamPlayer.RPMPercent = RPMPercent;
			StreamPlayer.EngineState = EngineState;
			StreamPlayer.IsRedlining = IsRedlining;

			if ( Driver.IsValid() && Driver.IsProxy )
				StreamPlayer.Update( Time.Delta, Scene.Camera.WorldPosition );
			else
				StreamPlayer.Update( Time.Delta, WorldPosition );
		}

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

		base.OnFixedUpdate();

		var dt = Time.Delta;
		EngineThink( dt );
		WheelThink( dt );
		UpdateSteering( dt );

		Brake = Math.Clamp( frontBrake + rearBrake + (Input.Down( "Jump" ) ? 1 : 0), 0, 1 );
	}

}
