using UnityEngine;
using GadgetCore.API;

namespace First
{
  public static class ItemUtil
  {
    public static int CreatePlacableItem(string tileImgPath, string itemImgPath, int tileId, string itemName, string tileName, string name)
    {

      Texture2D texture2D = GadgetCoreAPI.LoadTexture2D(tileImgPath, false);
      Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);
      GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + tileId));
      //gameObject.transform.localScale = new Vector3(0.3333f, 0.3333f);

      gameObject.layer = 11;

      BoxCollider collider = gameObject.AddComponent<BoxCollider>();
      //collider.transform.localScale = new Vector3(3, 3);



      ItemInfo itemInfo = new ItemInfo(0, name, "", texture2D2, 500, default(EquipStats), null, null, null, null);
      itemInfo.Register(name, -1, false);
      new TileInfo(TileType.SOLID, texture2D, gameObject, itemInfo).Register(name, -1, false);
      return itemInfo.GetID();
    }

    public static int CreatePlacableLightItem(string tileImgPath, string itemImgPath, string name, Color color)
    {

      Texture2D texture2D = GadgetCoreAPI.LoadTexture2D(tileImgPath, false);
      Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);

      GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + 2401));
      try
      {
        gameObject.GetComponentInChildren<Light>().color = color;
      }
      catch { }

      ItemInfo itemInfo = new ItemInfo(0, name, "", texture2D2, 500, default(EquipStats), null, null, null, null);
      itemInfo.Register(name, -1, false);
      new TileInfo(TileType.NONSOLID, texture2D, gameObject, itemInfo).Register(name, -1, false);
      return itemInfo.GetID();
    }

    public static int CreateDefaultItem(string itemImgPath, string name, int value = 20)
    {
      Texture2D texture2D2 = GadgetCoreAPI.LoadTexture2D(itemImgPath, false);
      ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", texture2D2, value, default(EquipStats), null, null, null, null);
      itemInfo.Register(name, -1, false);
      return itemInfo.GetID();
    }
  }
}
