#include "cTrooperEngineCore.hpp"

/*** Custom Header Files ***/
#include "../VideoEngine/cVideo.hpp"
#include "../AudioEngine/cAudio.hpp"
#include "../InputEngine/cInput.hpp"

#include "../TimingEngine/cTiming.hpp"

#include "../TextTypeEngine/cTextType.hpp"

#include "../MathEngine/cRandom.hpp"

#include "../EventEngine/cEventControl.hpp"

#include "../UtilityEngine/cUtility.hpp"

#include "../GUIEngine/cGUI.hpp"

using TrooperEngineCore::cTrooperEngineCore;

/*static*/ cTrooperEngineCore* cTrooperEngineCore::sp_inst = nullptr;

cTrooperEngineCore::cTrooperEngineCore()
{
}

cTrooperEngineCore::~cTrooperEngineCore()
{
	CleanUp();
	VideoEngine::cVideo::Delete();
	AudioEngine::cAudio::Delete();
	InputEngine::cInput::Delete();
	TimingEngine::cTiming::Delete();

	TextTypeEngine::cTextType::Delete();
	MathEngine::cRandom::Delete();
	EventEngine::cEventControl::Delete();
	SDL_Quit();
	UtilityEngine::cUtility::Inst().Message("SDL shut down!");
	UtilityEngine::cUtility::Delete();

	GUIEngine::cGUI::Delete();
}

///Functions
/*static*/ const char* cTrooperEngineCore::Version()
{
	return __TROOPERENGINE__VERSION;
}

/*static*/ cTrooperEngineCore& cTrooperEngineCore::Inst()
{
	if (sp_inst == nullptr)
	    sp_inst = new cTrooperEngineCore();
	return *sp_inst;
}

/*static*/ void cTrooperEngineCore::Delete()
{
	delete sp_inst;
	sp_inst = nullptr;
}

const bool cTrooperEngineCore::VideoInit()
{
	return VideoEngine::cVideo::Inst().Initialize();
}

const bool cTrooperEngineCore::AudioInit()
{
	return AudioEngine::cAudio::Inst().Initialize();
}

const bool cTrooperEngineCore::InputInit()
{
	return true;
}

const bool cTrooperEngineCore::JoystickInit()
{
    return InputEngine::cInput::Inst().Initialize();
}

const bool cTrooperEngineCore::TimerInit()
{
	return TimingEngine::cTiming::Inst().Initialize();
}

const bool cTrooperEngineCore::TextTypeInit()
{
	return TextTypeEngine::cTextType::Inst().Initialize();		
}

const bool cTrooperEngineCore::EventInit()
{
	return EventEngine::cEventControl::Inst().Initialize();
}

/* Print lib versions */
void cTrooperEngineCore::PrintSDLVersion() const
{
	UtilityEngine::cUtility::Inst().PrintVersion();
}

void cTrooperEngineCore::CleanUp()
{
	VideoEngine::cVideo::Inst().CleanUp();
	AudioEngine::cAudio::Inst().CleanUp();
	TimingEngine::cTiming::Inst().CleanUp();
	TextTypeEngine::cTextType::Inst().CleanUp();
	InputEngine::cInput::Inst().CleanUp();
	EventEngine::cEventControl::Inst().CleanUp();
}

///Gets
const bool cTrooperEngineCore::getVideo() const
{
	return VideoEngine::cVideo::Inst().IsInit();
}

const bool cTrooperEngineCore::getAudio() const
{
	return AudioEngine::cAudio::Inst().IsInit();
}

const bool cTrooperEngineCore::getInput() const
{
	return InputEngine::cInput::Inst().IsInit();
}

const bool cTrooperEngineCore::getJoystick() const
{
    return false;
}

const bool cTrooperEngineCore::getTimer() const
{
	return TimingEngine::cTiming::Inst().IsInit();
}

const bool cTrooperEngineCore::getText() const
{
	return TextTypeEngine::cTextType::Inst().IsInit();
}

const bool cTrooperEngineCore::getEvent() const
{
	return EventEngine::cEventControl::Inst().IsInit();
}

