using Godot;
using Newlon;

public partial class AudioSlider : HSlider
{
	enum TYPE
	{
		SFX,
		MUSIC
	}

	[Export] private TYPE affects;
	public override void _Ready()
	{
		DragEnded += OnDragEnded;
		if (affects == TYPE.SFX)
		{
			SetValueNoSignal(Utility.SFX);
		}
		else
		{
			SetValueNoSignal(Utility.Music);
		}
	}

	private void OnDragEnded(bool hasChanged)
	{
		if (hasChanged)
		{
			if (affects == TYPE.SFX)
			{
				Utility.SFX = Value;
				AudioServer.SetBusVolumeDb(2, Mathf.LinearToDb((float)Value));
			}
			else
			{
				Utility.Music = Value;
				AudioServer.SetBusVolumeDb(1, Mathf.LinearToDb((float)Value));
			}
		}
	}

}
