/**
 * Staticka trida slouzici jako konfiguracni soubor pro ulozeni uzivatelskeho nastaveni
 */
using UnityEngine;
using System.Collections;
/**
 * Author:			Karel Zavrel
 * 
 * Thesis:			An interactive application for development of creativity
 * Application:		Little Builder
 */
static class ConfigFile {
	/**
	 * soukrome promenne:
	 * 	- prezdivka uzivatele
	 * 	- pomocna promenna pro kontrolu, zda byla ulozena data
	 * 	- index materialu pouziteho na hlavu figuriny
	 * 	- index materialu pouziteho na telo figuriny
	 * 	- index materialu pouziteho na nohy figuriny
	 */
	private static string avatarsName;
	private static bool dataSaved = false;
	private static int headIndex = 0, bodyIndex = 0, legsIndex = 0;
	/**
	 * funkce pro ulozeni uzivatelskych dat
	 */
	public static void saveData(){
		ConfigFile.dataSaved = true;
		PlayerPrefs.SetString ("Avatar's name", avatarsName);
		PlayerPrefs.SetInt ("Figurine's head index", headIndex);
		PlayerPrefs.SetInt ("Figurine's body index", bodyIndex);
		PlayerPrefs.SetInt ("Figurine's legs index", legsIndex);
		loadData ();
	}
	/**
	 * funkce pro nacteni uzivatelskych dat
	 */
	public static void loadData(){
		if (ConfigFile.dataSaved) {
			avatarsName = PlayerPrefs.GetString ("Avatar's name");
			headIndex = PlayerPrefs.GetInt ("Figurine's head index");
			bodyIndex = PlayerPrefs.GetInt ("Figurine's body index");
			legsIndex = PlayerPrefs.GetInt ("Figurine's legs index");
		} else {
			avatarsName = "Avatar";
			headIndex = 0;
			bodyIndex = 0;
			legsIndex = 0;
		}
	}
	/**
	 * funkce pro nacteni vychozich dat
	 */
	public static void loadInitialSettings(){
		ConfigFile.dataSaved = false;
		loadData ();
	}
	/**
	 * funkce pro nastaveni uzivatelovy prezdivky
	 */
	public static void setAvatarsName(string aName){
		avatarsName = aName;
	}
	/**
	 * funkce pro ziskani uzivatelovy prezdivky
	 */
	public static string getAvatarsName(){
		return avatarsName;
	}
	/**
	 * funkce pro ziskani indexu materialu pouziteho na hlavu figuriny
	 */
	public static int getHeadIndex(){
		return headIndex;
	}
	/**
	 * funkce pro ziskani indexu materialu pouziteho na telo figuriny
	 */
	public static int getBodyIndex(){
		return bodyIndex;
	}
	/**
	 * funkce pro ziskani indexu materialu pouziteho na nohy figuriny
	 */
	public static int getLegsIndex(){
		return legsIndex;
	}
	/**
	 * funkce pro ziskani indexu materialu pouziteho na nekterou ze tri casti figuriny
	 */
	public static int getIndex(bool toRight, string bodyPart){
		switch (bodyPart) {
			case "figurines_head":
				if (toRight) {
					headIndex = addToIndex (headIndex);
				} else {
					headIndex = subtractFromIndex (headIndex);
				}
				return headIndex;
				break;
			case "figurines_body":
				if (toRight) {
					bodyIndex = addToIndex (bodyIndex);
				} else {
					bodyIndex = subtractFromIndex (bodyIndex);
				}
				return bodyIndex;
				break;
			case "figurines_legs":
				if (toRight) {
					legsIndex = addToIndex (legsIndex);
				} else {
					legsIndex = subtractFromIndex (legsIndex);
				}
				return legsIndex;
				break;
			default:
				return 0;
				break;
		}
	}
	/**
	 * funkce pro navyseni indexu materialu
	 */
	private static int addToIndex(int index){
		if (index == 2) {
			index = 0;
		} else {
			index++;
		}
		return index;
	}
	/**
	 * funkce pro snizeni indexu materialu
	 */
	private static int subtractFromIndex(int index){
		if (index == 0) {
			index = 2;
		} else {
			index--;
		}
		return index;
	}
}