using UnityEngine;
using GadgetCore.API;
using GadgetCore.Util;

namespace SpacePlanet
{
  [Gadget("SpacePlanet")]
  public class SpacePlanet : Gadget<SpacePlanet>
  {
    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)");
      }

      Config.Save();
    }

    public override string GetModDescription()
    {
      return "A mod that adds a space planet.";
    }

    protected override void Initialize()
    {
      Logger.Log("SpacePlanet v" + Info.Mod.Version);
      Core.logger = Logger;


      Texture2D texturePlanetPrevIcon = GadgetCoreAPI.LoadTexture2D("planetSpacePrev.png");
      Texture2D texturePlanetIcon = GadgetCoreAPI.LoadTexture2D("planetSpace.png");
      Texture2D texturePortalSign = GadgetCoreAPI.LoadTexture2D("signSpace.png");

      //Texture2D textureBG= GadgetCoreAPI.LoadTexture2D("bgSpace.png");
      //Texture2D textureParalex0 = GadgetCoreAPI.LoadTexture2D("bSpacebg0.png");
      //Texture2D textureParalex1 = GadgetCoreAPI.LoadTexture2D("bSpacebg1.png");
      //Texture2D textureParalex2 = GadgetCoreAPI.LoadTexture2D("bSpacebg2.png");
      //Texture2D textureParalex3 = GadgetCoreAPI.LoadTexture2D("bSpacebg3.png");
      //Texture2D textureEntrance = GadgetCoreAPI.LoadTexture2D("entranceSpace.png");
      //Texture2D textureSmallSide = GadgetCoreAPI.LoadTexture2D("sideSmallSpace.png");
      //Texture2D textureBigSide = GadgetCoreAPI.LoadTexture2D("sideBigSpace.png");
      //
      //Texture2D textureMid0 = GadgetCoreAPI.LoadTexture2D("midSpaceChunk0.png");
      //Texture2D textureMid1 = GadgetCoreAPI.LoadTexture2D("midSpaceChunk1.png");


      Texture2D textureSpaceOre = GadgetCoreAPI.LoadTexture2D("spaceOre.png");
      Texture2D textureSpaceOreBig = GadgetCoreAPI.LoadTexture2D("spaceOreBig.png");

      PlanetInfo spacePlanet = new PlanetInfo(PlanetType.SPECIAL, "Space", new GadgetCore.Util.Tuple<int, int>[] { new GadgetCore.Util.Tuple<int, int>(0, 100) });
      spacePlanet.SetPortalInfo(texturePortalSign, texturePlanetPrevIcon, texturePlanetIcon);
      //spacePlanet.SetBackgroundInfo(textureBG, textureParalex0, textureParalex1, textureParalex2, textureParalex3);
      //spacePlanet.SetTerrainInfo(textureEntrance, textureBG, textureMid0, textureMid1, textureBigSide, textureSmallSide);

      spacePlanet.OnGenerateWorld += SpaceWorldGenerator.StartGenarateWorld;
      spacePlanet.OnGenerateTown += SpaceWorldGenerator.GenarateTown;

      spacePlanet.Register("Space");

      spacePlanet.PortalUses = 10;

      Core.spacePlanetId = spacePlanet.GetID();

      //PlanetRegistry.SetVanillaExitPortalWeight(0, spacePlanet.GetID(), 1000);

      ObjectInfo objectSpaceOre = new ObjectInfo(ObjectType.ORE, new Item(1, 1, 0, 0, 0, new int[3], new int[3]), 0, textureSpaceOre).Register("spaceore");
      Core.objectSpaceOre = objectSpaceOre;

      ObjectInfo objectSpaceOreBig = new ObjectInfo(ObjectType.ORE, new Item(1, 1, 0, 0, 0, new int[3], new int[3]), 0, textureSpaceOreBig).Register("spaceorebig");
      Core.objectSpaceOreBig = objectSpaceOreBig;

      GameObject enemy = GadgetCoreAPI.GetEntityResource("");

      new EntityInfo(EntityType.COMMON, enemy, new int[0]).Register("");

      ((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).AddCraftPerformer(CraftMenuInfo.CreateSimpleCraftPerformer(
    Tuple.Create(new int[] { 11, 11, 11 }, new Item(11, 2, 0, 0, 0, new int[3], new int[3]), 2)
));
    }
  }
}
