using UnityEngine;
using System.Collections.Generic;

[System.Serializable]
public static class ItemDictionary {

    public static Dictionary<int, Item> items = new Dictionary<int, Item>();

    public static void Load() {
        items = new Dictionary<int, Item>();
        TextAsset csvItems = (TextAsset) Resources.Load ("csvItems");
       
		foreach (string line in csvItems.text.Split('\n')) {
            if (line.Contains("#")) continue;

            string type = line.Split(',')[2];
            Debug.Log("TYPE:" + type);
            Item i  = null;
            
            if (type == "1")
            {
                i = new Weapon(line);
            } else if (type == "2") {
                i = new Item(line);
            }
            else if (type == "3")
            {
                i = new Armor(line);
            }
            else if (type == "4")
            {
                i = new Item(line);
            }

//            Item i = new Item(line);
            ItemDictionary.items.Add(i.id, i); 
	    }
    }


    public static Item getItemById(int id) {
        if (ItemDictionary.items.ContainsKey(id))
        {
            return ItemDictionary.items[id];
        }
        else
        {
            Debug.Log("Item with id(" + id + ") not found.");
            return null;
        }
    }

}
