using UnityEngine;
using System.Collections;

public class DemonConfigurator : MonoBehaviour {




	[System.Serializable]
	public struct SpriteSetup
	{
		public Sprite Front_L;
		public Sprite Front_R;
		public Sprite Back_L;
		public Sprite Back_R;
		public Sprite Side;
	}

	public SpriteRenderer FrontHead;
	public SpriteRenderer LeftHead;
	public SpriteRenderer RighHead;
	public SpriteRenderer BackHead;

	public SpriteRenderer FrontBody;
	public SpriteRenderer LeftBody;
	public SpriteRenderer RighBody;
	public SpriteRenderer BackBody;

	public SpriteRenderer FrontLegs;
	public SpriteRenderer LeftLegs;
	public SpriteRenderer RighLegs;
	public SpriteRenderer BackLegs;

	public SpriteRenderer FrontArmL;
	public SpriteRenderer FrontArmR;
	public SpriteRenderer LeftArm;
	public SpriteRenderer RighArm;
	public SpriteRenderer BackArmL;
	public SpriteRenderer BackArmR;

	public SpriteSetup[] Heads;
	public SpriteSetup[] Bodies;
	public SpriteSetup[] Arms;
	public SpriteSetup[] Legs;

	public void SetHead(int index)
	{
		FrontHead.sprite = Heads [index].Front_L;
		BackHead.sprite = Heads [index].Back_L;
		LeftHead.sprite = Heads [index].Side;
		RighHead.sprite = Heads [index].Side;
	}

	public void SetBody(int index)
	{
		FrontBody.sprite = Bodies [index].Front_L;
		BackBody.sprite = Bodies [index].Back_L;
		LeftBody.sprite = Bodies [index].Side;
		RighBody.sprite = Bodies [index].Side;
	}

	public void SetArms(int index)
	{
		FrontArmL.sprite = Arms [index].Front_L;
		FrontArmR.sprite = Arms [index].Front_R;

		BackArmL.sprite = Arms [index].Front_L;
     	BackArmR.sprite = Arms [index].Front_R;

		LeftArm.sprite = Arms [index].Side;
		RighArm.sprite = Arms [index].Side;
	}

	public void SetLegs(int index)
	{
		FrontLegs.sprite = Legs [index].Front_L;
		BackLegs.sprite = Legs [index].Back_L;
		LeftLegs.sprite = Legs [index].Side;
		RighLegs.sprite = Legs [index].Side;
	}

	public void SetColor(Color newColor, float variance = 0f)
	{
		SpriteRenderer[] allSprites = GetComponentsInChildren<SpriteRenderer> (true);
		foreach (SpriteRenderer sr in allSprites)
		{
			sr.color = newColor + new Color(Random.Range(-variance, variance),
			                                Random.Range(-variance, variance),
			                                Random.Range(-variance, variance));
		}
	}
}
