/******************************************************************************
*	File		-	tester.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 "tester.h"
#include "scenes/simpleRenderScene.h"
#include "scenes/physicsScene.h"

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

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

    }

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

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

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

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

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

    
    void Tester::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::Log(mLogCat, LogLevel::INFO_VERBOSE, "Left mouse button pressed!");
        }

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

    
    void Tester::OnKeyPress(InputManager::KeyPress kp)
    {
        Logger::Log(mLogCat, LogLevel::INFO_VERBOSE, "Key Press Event: %s", kp.Key.Name.c_str());
    }
    
}


