using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class SymbolManager : MonoBehaviour {

	public SpellController spellController; 
	public GameObject rune;
	
	private int curAmt;
	private Image[] runeSprites;

	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void Init(){
		runeSprites = new Image[12];
		curAmt = 0;  
	}

	public void UpdateAmt(){ 

		int nexAmt = spellController.GetMaxRuneCount();
		for(int i=0; i<curAmt; ++i){
			runeSprites[i].rectTransform.anchoredPosition = new Vector3(GetOffset(i,nexAmt), 0);
		}
		for(int i=curAmt; i<nexAmt; ++i){
			runeSprites[i] = Instantiate(rune).GetComponent<Image>();
			runeSprites[i].transform.SetParent(this.transform,false);
			runeSprites[i].rectTransform.localScale = Vector3.one;

			runeSprites[i].rectTransform.anchoredPosition = new Vector3(GetOffset(i,nexAmt), 0);

		}
		curAmt = nexAmt;
	}

	private float GetOffset(int dex, int maxdex){
		float tmd = dex+1, tmp = maxdex+1;
		tmp/=2; 
		return (50f*(tmd-tmp));
	}

	public void UpdateRune(){ 
		for(int i=0;i<curAmt; ++i){ 
			runeSprites[i].gameObject.GetComponent<RuneSprite>().UpdateSprite(spellController.GetRuneNo(i));
		}
	}
}
