/******************************************************************************
*	File		-	testbed.cpp
*	Author		-	Joey Pollack
*	Date		-	2021/09/15 (y/m/d)
*	Mod Date	-	2021/09/15 (y/m/d)
*	Description	-	Run a series of tests to verify engine functionality
******************************************************************************/

#include "testbed.h"
#include "scenes/simple_render_scene.h"
#include "scenes/physics_scene.h"

#include <core/core.h>
#include <utils/logger.h>
#include <graphics/graphics.h>
#include <LunariumConfig.h>

namespace lunarium
{
    TestBed::TestBed()
        : mpScene(nullptr)
    {

    }

    OpRes TestBed::Initialize()
    {
        // return OpRes::Fail("Tester::Initialize not implemented");

        mLogCat = Logger::RegisterCategory("TESTBED");

#if BUILD_NO_EDITOR
        Logger::Info(mLogCat, "NO EDITOR!");
#else
        Logger::Info(mLogCat, "EDITOR DETECTED!");
#endif

        mpScene = new SimpleRenderScene(mLogCat);
        // mpScene = new PhysicsScene(mLogCat);
        mpScene->OnLoad();
        

        return OpRes::OK();
    }
    
    void TestBed::Shutdown()
    {
        delete mpScene;
        mpScene = nullptr;
    }

    
    void TestBed::OnTick(double delta)
    {
        if (Core::Input().IsKeyDown(KeyCode::NUM_1))
        {
            if (!dynamic_cast<SimpleRenderScene*>(mpScene))
            {
                delete mpScene;
                mpScene = new SimpleRenderScene(mLogCat);
                mpScene->OnLoad();
            }
        }

        if (Core::Input().IsKeyDown(KeyCode::NUM_2))
        {
            if (!dynamic_cast<PhysicsScene*>(mpScene))
            {
                delete mpScene;
                mpScene = new PhysicsScene(mLogCat);
                mpScene->OnLoad();
            }
        }

        if (Core::Input().IsKeyDown(KeyCode::MOUSE_LEFT_BUTTON, true))
        {
            Logger::Trace(mLogCat, "Left mouse button pressed!");
        }

        mpScene->OnTick(delta);
    }
    
    void TestBed::OnRender(IGraphics* g)
    {
        mpScene->OnRender(g);
    }

    
    void TestBed::OnKeyPress(InputManager::KeyPress kp)
    {
        Logger::Trace(mLogCat, "Key Press Event: %s", kp.Key.Name.c_str());
    }
    
}


