using UnityEngine;
using GadgetCore.API;

namespace First
{
  [Gadget("First")]
  public class First : Gadget<First>
  {
    public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
    public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.

    protected override void LoadConfig()
    {
      Config.Load();

      string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");

      if (fileVersion != CONFIG_VERSION)
      {
        Config.Reset();
        Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
      }

      // Do stuff with `Config`

      Config.Save();
    }

    public override string GetModDescription()
    {
      return "This is a new description."; // TODO: Change this
    }

    protected override void Initialize()
    {
      Logger.Log("First v" + Info.Mod.Version);

      Material copy = new Material((Material)Resources.Load("mat/planet0"));
      copy.mainTexture = GadgetCoreAPI.LoadTexture2D("charBG.png");
      GadgetCoreAPI.AddCustomResource("mat/planet0", copy);

      //int id = ItemUtil.CreateDefaultItem("iCore.png", "Water Core");
      //Core.itemID = id;
      Core.itemWaterCoreId = ItemUtil.CreateDefaultItem("iWaterCore.png", "Water Core");
      Core.itemAirCoreId = ItemUtil.CreateDefaultItem("iAirCore.png", "Air Core");
      Core.itemFireCoreId = ItemUtil.CreateDefaultItem("iFireCore.png", "Fire Core");
      Core.itemEarthCoreId = ItemUtil.CreateDefaultItem("iEarthCore.png", "Earth Core");

      //Core.itemGreenLampId = ItemUtil.CreatePlacableItem("cGreenLamp.png", "iGreenLamp.png", 2401, "Green Lamp", "Green Lamp Object", "Green Lamp");
      Core.itemGreenLampId = ItemUtil.CreatePlacableLightItem("cGreenLamp.png", "iGreenLamp.png", "Green Light", new Color(0.1f, 0.6f, 0, 1));
      Core.itemYellowLampId = ItemUtil.CreatePlacableLightItem("cYellowLamp.png", "iYellowLamp.png", "Yellow Light", new Color(0.9f, 0.75f, 0, 1));
      Core.itemOrangeLampId = ItemUtil.CreatePlacableLightItem("cOrangeLamp.png", "iOrangeLamp.png", "Orange Light", new Color(0.7f, 0.15f, 0, 1));
      Core.itemPurpleLampId = ItemUtil.CreatePlacableLightItem("cPurpleLamp.png", "iPurpleLamp.png", "Purple Light", new Color(0.5f, 0, 0.6f, 1));
      Core.itemWhiteLampId = ItemUtil.CreatePlacableLightItem("cWhiteLamp.png", "iWhiteLamp.png", "White Light", new Color(0.8f, 0.8f, 0.8f, 1));

      Core.itemID = ItemUtil.CreatePlacableItem("cPlatform.png", "iPlatform.png", 2501, "Platform", "Platform Object", "Platform");

      PlanetInfo scrapYardPlanetInfo = new PlanetInfo(PlanetType.SPECIAL, "Scrap Yard", new GadgetCore.Util.Tuple<int, int>[0]).Register("Scrap Yard");
      PlanetRegistry.SetVanillaExitPortalWeight(0, scrapYardPlanetInfo.GetID(), 1000);
    }
  }
}
