#pragma once
#include "Ground.h"
#include "Surface.h"
#include "Structs.h"
#include "Lines.h"
#include "Rectangle.h"

Ground::Ground(Graphics & gfx, Logger & logger) noexcept
{
    // Init 2 surfaces
    /*Surface *yueyueSurface = new Surface();
    yueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\yueyue.jpg");
    float yueyueSlot = yueyueSurface->GetCurrSlot();

    Surface *ethanSurface = new Surface();
    ethanSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Ethan.png");
    float ethanSlot = ethanSurface->GetCurrSlot();

    Surface* ethanAndYueyueSurface = new Surface();
    ethanAndYueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Ethan_and_yueyue.png");
    float ethanAndYueyueSlot = ethanAndYueyueSurface->GetCurrSlot();*/

    Surface* grass = new Surface();
    grass->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Grass.jpeg");
    float grassSlot = grass->GetCurrSlot();

    // Draw grass ground
    for (int i = 0; i < 2; i+=2 )
        for (int j = 0; j < 2; j+= 2)
        {

            StructVertexWithTexture vertices[24] = {

                // back surface
                // left top back
                { XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // right top back
                { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // left bottom back
                { XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // right bottom back
                { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },

                // left surface
                // left top front
                {  XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // left top back
                {  XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // left bottom front
                {  XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // left bottom back
                {  XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },

                // right surface
                // right top back
                { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // right top front
                { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // right bottom back
                { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // right bottom front
                { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },

                // top surface
                // left top front
                { XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // right top front
                { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // left top back
                { XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // right top back
                { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },

                // front surface
                // right top front
                { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // left top front
                { XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // right bottom front
                { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // left bottom front
                { XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },

                // bottom surface
                // left bottom back
                { XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
                // right bottom back
                { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
                // left bottom front
                { XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
                // right bottom front
                { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
            };

            shapes.push_back(std::make_unique<Box>(gfx, vertices, logger));

        }

    XMFLOAT3 black = XMFLOAT3(1.0f, 1.0f, 1.0f);
    StructVertexWithColor vertices[22];
    // Draw horizon lines
    for (int i = 0; i < 11; i++)
    {
        vertices[i*2] = { XMFLOAT3(-10.0f, 1.01f, -10.0f + i*2), black };
        vertices[i*2 + 1] = { XMFLOAT3(10.0f, 1.01f, -10.0f + i * 2), black };
    }

    shapes.push_back(std::make_unique<Lines>(gfx, vertices, 22, logger));

    // Draw vertical lines
    for (int i = 0; i < 11; i++)
    {
        vertices[i * 2] = { XMFLOAT3(-10.0f + i * 2, 1.01f, -10.0f), black };
        vertices[i * 2 + 1] = { XMFLOAT3(-10.0f + i * 2, 1.01f, 10.0f), black };
    }

    shapes.push_back(std::make_unique<Lines>(gfx, vertices, 22, logger));

    // Draw horizon lines using Rectangle
    //XMFLOAT3 black = XMFLOAT3(1.0f, 1.0f, 1.0f);
    //float width = 0.02f;

    //for (int i = 0; i < 21; i++)
    //{
    //    StructVertexWithColor vertices[4];
    //    vertices[0] = { XMFLOAT3(-10.0f, 1.01f, -10.0f - width + i), black };
    //    vertices[1] = { XMFLOAT3(-10.0f, 1.01f, -10.0f + width + i), black };
    //    vertices[2] = { XMFLOAT3(10.0f, 1.01f, -10.0f - width + i), black };
    //    vertices[3] = { XMFLOAT3(10.0f, 1.01f, -10.0f + width + i), black };

    //    shapes.push_back(std::make_unique<class Rectangle>(gfx, vertices, logger));
    //}

    //// Draw vertical lines using Rectangle
    //for (int i = 0; i < 21; i++)
    //{
    //    StructVertexWithColor vertices[4];
    //    vertices[0] = { XMFLOAT3(-10.0f + width + i, 1.01f, -10.0f), black };
    //    vertices[1] = { XMFLOAT3(-10.0f - width + i, 1.01f, -10.0f), black };
    //    vertices[2] = { XMFLOAT3(-10.0f + width + i, 1.01f, 10.0f), black };
    //    vertices[3] = { XMFLOAT3(-10.0f - width + i, 1.01f, 10.0f), black };

    //    shapes.push_back(std::make_unique<class Rectangle>(gfx, vertices, logger));
    //}
};
