using UnityEngine;
using System.Collections.Generic;

namespace com.deeperbeige.whiteout
{
    public class MeshParams //: MonoBehaviour
    {
        private const int DEFAULT_GRANULARITY = 50;
        private const float DEFAULT_GRID_SIZE = 28f;
        private const float DEFAULT_ATTENUATION_RADIUS = 0.4f;
        private const float DEFAULT_ATTENUATION_SIGMA = 3f;

        public static MeshParams EASY = new MeshParams (DEFAULT_GRANULARITY, DEFAULT_GRANULARITY,
                                                        DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE, 
                                                        1, 
                                                        DEFAULT_ATTENUATION_RADIUS, DEFAULT_ATTENUATION_SIGMA,
                                                        0.3f, 0.35f);

        public static MeshParams MEDIUM = new MeshParams (DEFAULT_GRANULARITY, DEFAULT_GRANULARITY,
                                                          DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE,
                                                          7, 
                                                          DEFAULT_ATTENUATION_RADIUS, DEFAULT_ATTENUATION_SIGMA,
                                                          0.2f, 0.3f);

        public static MeshParams HARD = new MeshParams (DEFAULT_GRANULARITY, DEFAULT_GRANULARITY,
                                                        DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE, 
                                                        30, 
                                                        DEFAULT_ATTENUATION_RADIUS, DEFAULT_ATTENUATION_SIGMA,
                                                        0.1f, 0.15f);

        RandomLevel randomLevel;
        public int gridGranularityX = DEFAULT_GRANULARITY;
        public int gridGranularityZ = DEFAULT_GRANULARITY;
        public float width = DEFAULT_GRID_SIZE;
        public float depth = DEFAULT_GRID_SIZE;
        public int bumps = 12;
        public float attenuationRadius = DEFAULT_ATTENUATION_RADIUS;
        public float attenuationSigma = DEFAULT_ATTENUATION_SIGMA;
        public float bellCurveSigmaMin = 0.2f;
        public float bellCurveSigmaMax = 0.3f;
        private int prevGridGranularityX;
        private int prevGridGranularityZ;
        private float prevWidth;
        private float prevDepth;
        private int prevBumps;
        private float prevAttenuationRadius;
        private float prevAttenuationSigma;
        private float prevBellCurveSigmaMin;
        private float prevBellCurveSigmaMax;
       
        public MeshParams ()
        {
        }

        public MeshParams (int gridGranularityX, int gridGranularityZ, float width, float depth, int bumps, 
                           float attenuationRadius, float attenuationSigma,
                           float bellCurveSigmaMin, float bellCurveSigmaMax)
        {
            this.gridGranularityX = gridGranularityX;
            this.gridGranularityZ = gridGranularityZ;
            this.width = width;
            this.depth = depth;
            this.bumps = bumps;
            this.attenuationRadius = attenuationRadius;
            this.attenuationSigma = attenuationSigma;
            this.bellCurveSigmaMin = bellCurveSigmaMin;
            this.bellCurveSigmaMax = bellCurveSigmaMax;
        }

        
        /// Just for dev testing of optimal parameters
        /// Make this a MonoBehaviour and add to scene to activate
        private void Start ()
        {
            // start up random level
            CreateLandscape ();
        }
        
        public void CreateLandscape ()
        {
            randomLevel = new RandomLevel (this);
            randomLevel.addToGame ();
        }

        /// Just for dev testing of optimal parameters
        /// Make this a MonoBehaviour and add to scene to activate
        private void Update ()
        {
            if (gridGranularityX == prevGridGranularityX &&
                gridGranularityZ == prevGridGranularityZ &&
                width == prevWidth &&
                depth == prevDepth &&
                bumps == prevBumps &&
                attenuationRadius == prevAttenuationRadius &&
                attenuationSigma == prevAttenuationSigma &&
                bellCurveSigmaMin == prevBellCurveSigmaMin &&
                bellCurveSigmaMax == prevBellCurveSigmaMax) {
                return;
            }
            prevGridGranularityX = gridGranularityX;
            prevGridGranularityZ = gridGranularityZ;
            prevWidth = width;
            prevDepth = depth;
            prevBumps = bumps;
            prevAttenuationRadius = attenuationRadius;
            prevAttenuationSigma = attenuationSigma;
            prevBellCurveSigmaMin = bellCurveSigmaMin;
            prevBellCurveSigmaMax = bellCurveSigmaMax;
            if (null != randomLevel) {
                randomLevel.removeFromGame ();
            }
            
            CreateLandscape ();
        }
    }
}
