﻿
// Makinom 2 schematic nodes for Footstepper.
// Version: 1.0.1

using UnityEngine;
using GamingIsLove.Footsteps;
using System.Collections.Generic;

namespace GamingIsLove.Makinom.Schematics.Nodes
{
	[EditorHelp("FS Change Mode", "Changes the mode of a 'Footstepper' component.", "")]
	[NodeInfo("Movement/Footstepper")]
	public class FSChangeModeNode : BaseSchematicNode
	{
		[EditorHelp("Mode", "Select in which mode will be used:\n" +
			"- Enabled: Uses both audio clips and prefabs from footstep sources.\n" +
			"- Disabled: Isn't used at all.\n" +
			"- Only Audio: Only uses audio clips from footstep sources.\n" +
			"- Only Prefab: Only uses prefabs from footstep sources.\n", "")]
		public FootstepperMode mode = FootstepperMode.Enabled;

		[EditorHelp("Change Non-Player", "Change the non-player mode of a 'Makinom Player Footstepper.", "")]
		public bool changeNonPlayerMode = false;

		[EditorSeparator]
		[EditorTitleLabel("Game Object")]
		public SchematicObjectSelection usedObject = new SchematicObjectSelection();

		public FSChangeModeNode()
		{

		}

		public override void Execute(Schematic schematic)
		{
			if(this.changeNonPlayerMode)
			{
				List<MakinomPlayerFootstepper> list = this.usedObject.GetAllComponents<MakinomPlayerFootstepper>(schematic, ComponentScope.AllInChildren);
				for(int i = 0; i < list.Count; i++)
				{
					if(list[i] != null)
					{
						list[i].nonPlayerMode = this.mode;
					}
				}
			}
			else
			{
				List<Footstepper> list = this.usedObject.GetAllComponents<Footstepper>(schematic, ComponentScope.AllInChildren);
				for(int i = 0; i < list.Count; i++)
				{
					if(list[i] != null)
					{
						list[i].mode = this.mode;
					}
				}
			}
			schematic.NodeFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.usedObject.ToString() + ": " + this.mode +
				(this.changeNonPlayerMode ? " (Non-Player)" : "");
		}
	}

	[EditorHelp("FS Change Effect Tag", "Changes the effect tag of a 'Footstepper' component.", "")]
	[NodeInfo("Movement/Footstepper")]
	public class FSChangeEffectTagNode : BaseSchematicNode
	{
		[EditorHelp("Effect Tag", "The effect tag that will be used.", "")]
		public StringValue<SchematicObjectSelection> effectTag = new StringValue<SchematicObjectSelection>();

		[EditorSeparator]
		[EditorTitleLabel("Game Object")]
		public SchematicObjectSelection usedObject = new SchematicObjectSelection();

		public FSChangeEffectTagNode()
		{

		}

		public override void Execute(Schematic schematic)
		{
			string tag = this.effectTag.GetValue(schematic);
			List<Footstepper> list = this.usedObject.GetAllComponents<Footstepper>(schematic, ComponentScope.AllInChildren);
			for(int i = 0; i < list.Count; i++)
			{
				if(list[i] != null)
				{
					list[i].effectTag = tag;
				}
			}
			schematic.NodeFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.usedObject.ToString() + ": " + this.effectTag.ToString();
		}
	}

	[EditorHelp("FS Play Footstep", "Tries playing a footstep on a 'Footstepper' component.", "")]
	[NodeInfo("Movement/Footstepper")]
	public class FSPlayFootstepNode : BaseSchematicNode
	{
		[EditorHelp("Foot Index", "The index of the foot that will be used.", "")]
		public int index = 0;

		[EditorHelp("Volume (0-1)", "The volume used to play the footstep.", "")]
		[EditorLimit(0.0f, 1.0f)]
		public float volume = 1;

		[EditorHelp("Footstep Type", "Select the type of footstep that will be played.", "")]
		public FootstepType type = FootstepType.Walk;

		[EditorHelp("Custom Name", "The name of the custom footstep effect that will be used.")]
		[EditorCondition("type", FootstepType.Custom)]
		[EditorEndCondition]
		public StringValue<SchematicObjectSelection> customName = new StringValue<SchematicObjectSelection>();

		[EditorSeparator]
		[EditorTitleLabel("Game Object")]
		public SchematicObjectSelection usedObject = new SchematicObjectSelection();

		public FSPlayFootstepNode()
		{

		}

		public override void Execute(Schematic schematic)
		{
			List<Footstepper> list = this.usedObject.GetAllComponents<Footstepper>(schematic, ComponentScope.AllInChildren);
			for(int i = 0; i < list.Count; i++)
			{
				if(list[i] != null)
				{
					list[i].PlayFootstep(list[i].GetFoot(this.index), this.index, this.volume, this.type, this.customName.GetValue(schematic));
				}
			}
			schematic.NodeFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.usedObject.ToString() + ": " + this.type;
		}
	}
}
