using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class CustomWorldInit : MonoBehaviour {

    [System.Serializable]
    public class TileSpawnData
    {
        public GameObject prefab;
        [Header("Config. coords are axial.")]
        public Int2 coordinates;
        public bool generate = true;
        public bool forceHeight = false;
        public float height = 0.1f;
        public bool forceAbundance = false;
        public float abundance = 0f;
        public bool constantTemp;
        public bool forceTemperature = false;
        public float temperature;
        public bool forceHumidity = false;
        public int humidity;
    }

    public World world;
    public TileSpawnData[] tileSpawnData;

	void Start () {
		foreach (var tsd in tileSpawnData)
        {
            var go = Instantiate(tsd.prefab);
            var tile = go.GetComponent<Tile>();
            if (tile == null) continue;
            
            var pos = HexGrid.Position(tsd.coordinates);
            tile.transform.SetParent(transform);
            tile.transform.localPosition = new Vector3(pos.x, 0, pos.y);
            world.grid.Add(tile);
            if (tsd.generate) tile.Generate(world.grid.Neighbors(tile).ToArray());
            if (tsd.forceHeight) tile.height = tsd.height;
            if (tsd.forceTemperature) tile.temperature = tsd.temperature;
            if (tsd.forceHumidity) tile.humidity = tsd.humidity;
            if (tsd.forceAbundance) tile.abundance = tsd.abundance;
            if (tsd.constantTemp) tile.temperatureConstant = true;

        }
	}
}
