using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum SoundEffects{
	ATTACK,
	HIT,
	KILLED
}

public enum HudSoundEffects{
	SELECT,
	TAP
}

public class AudioController : MonoBehaviour {

	[System.Serializable]
	public struct PlayerSFX{
		public string playerName;
		public AudioClip[] attackClip;
		public AudioClip[] hitClip;
		public AudioClip[] killedClip;
	}

	public AudioClip tapAudioClip;
	public AudioClip selectAudioClip;
		
	public static AudioController instance;

	public PlayerSFX[] playerSFX;

	private AudioSource myAudioSource;

	void Awake(){
		if(instance)
			Destroy (gameObject);
		else
			instance = this;
		DontDestroyOnLoad (gameObject);
		myAudioSource = GetComponent<AudioSource> ();
	}

	public static void PlayHudSound(HudSoundEffects sound){
		switch (sound) {
		case HudSoundEffects.SELECT:{
				instance.myAudioSource.PlayOneShot (instance.selectAudioClip);
		}
		break;
		case HudSoundEffects.TAP:{
				instance.myAudioSource.PlayOneShot (instance.tapAudioClip);
			}
			break;
		}
	}

	public static void PlayPlayerSound (PlayerNames playerName, SoundEffects soundEffect){
		PlayerSFX player = instance.playerSFX [(int)playerName];

		switch (soundEffect) {

		case SoundEffects.ATTACK:
			{
				instance.myAudioSource.PlayOneShot (player.attackClip[Random.Range(0,player.attackClip.Length)]);
			}
			break;
		case SoundEffects.HIT:
			{
				instance.myAudioSource.PlayOneShot (player.hitClip[Random.Range(0,player.hitClip.Length)]);
			}
			break;
		case SoundEffects.KILLED:
			{
				instance.myAudioSource.PlayOneShot (player.killedClip[Random.Range(0,player.killedClip.Length)]);
			}
			break;

		}
	}
}
