using UnityEngine;
using Enviro;
namespace HutongGames.PlayMaker.Actions
{
	[ActionCategory("ENVIRO")]
	[Tooltip("Changes the current time (Date).")]
	public class SetTimeDate : FsmStateAction
	{	
		[Tooltip("Set new second?")]
		public bool SetSeconds = true;
		[HasFloatSlider(0, 59)]
		public FsmInt Second;
		[Tooltip("Set new minute?")]
		public bool SetMinute = true;
		[HasFloatSlider(0, 59)]
		public FsmInt Minute;
		[Tooltip("Set new hour?")]
		public bool SetHour = true;
		[HasFloatSlider(0, 24)]
		public FsmInt Hour;
		[Tooltip("Set new day?")]
		public bool SetDay = true;
		[HasFloatSlider(0, 31)]
		public FsmInt Day;

		[Tooltip("Set new Month?")]
		public bool SetMonth = true;
		[HasFloatSlider(0, 12)]
		public FsmInt Month;
		[Tooltip("Set new year?")]
		public bool SetYear = true;
		public FsmInt Year;

		[Tooltip("Repeat every frame.")]
		public bool everyFrame;

		
		public override void OnEnter()
		{

			if( EnviroManager.instance.Time != null)
			{
			if (Second.Value != null && SetSeconds)
                EnviroManager.instance.Time.seconds = Second.Value;	
			if (Minute.Value != null && SetMinute)
                EnviroManager.instance.Time.minutes = Minute.Value;	
			if (Hour.Value != null && SetHour)
                EnviroManager.instance.Time.hours = Hour.Value;	
			if (Day.Value != null && SetDay)
                EnviroManager.instance.Time.days = Day.Value;
			if (Month.Value != null && SetMonth)
                EnviroManager.instance.Time.months = Month.Value;
			if (Year.Value != null && SetYear)
                EnviroManager.instance.Time.years = Year.Value;
			}

			if (!everyFrame)
			{
				Finish();
			}
		}

		public override void OnUpdate()
		{
			if( EnviroManager.instance.Time != null)
			{
			if (Second.Value != null && SetSeconds)
                EnviroManager.instance.Time.seconds = Second.Value;	
			if (Minute.Value != null && SetMinute)
                EnviroManager.instance.Time.minutes = Minute.Value;	
			if (Hour.Value != null && SetHour)
                EnviroManager.instance.Time.hours = Hour.Value;	
			if (Day.Value != null && SetDay)
                EnviroManager.instance.Time.days = Day.Value;
			if (Month.Value != null && SetMonth)
                EnviroManager.instance.Time.months = Month.Value;
			if (Year.Value != null && SetYear)
                EnviroManager.instance.Time.years = Year.Value;
			}
		}
	}
}