// Project Lab - NHTV Igad

#include "UnrealProject.h"


IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UnrealProject, "UnrealProject" );

DEFINE_LOG_CATEGORY(FRANK);
DEFINE_LOG_CATEGORY(JAN);
DEFINE_LOG_CATEGORY(TED);
DEFINE_LOG_CATEGORY(YOSHI);
DEFINE_LOG_CATEGORY(GUUS);
DEFINE_LOG_CATEGORY(RAUL);

#include <algorithm>
using namespace std;

void Output::WriteOut(char name, char type, const string& message)
{
	WriteWOut(wchar_t(name), wchar_t(type), (convert_cstring_type<wchar_t, char>(message.data())));
}
void Output::WriteWOut(wchar_t name, wchar_t type, const wstring& message)
{
	// Retrieve the line number and file name
	wstring content = message;
	const size_t end = content.find(L']');
	if (end == wstring::npos)
		return;
	
	wstring path_content = content.substr(0, end + 1);
	const size_t seperator = path_content.find_last_of(L':');
	wstring path = path_content.substr(1, seperator - 1);
	replace(path.begin(), path.end(), L'\\', L'/');
	const size_t slash = path.find_last_of(L'/');
	if (slash != wstring::npos) path = path.substr(slash + 1, path.size());
	wstring line = path_content.substr(seperator + 1, end - seperator - 1);

	content = L"(" + path + L":" + line + L") " + content.substr(end + 1, content.size());
	
	// Log to the proper output
	if (type == L'L')
	{
		switch (name)
		{
		case L'F': UE_LOG(FRANK, Log, TEXT("%s"), content.data()); break;
		case L'J': UE_LOG(JAN, Log, TEXT("%s"), content.data()); break;
		case L'T': UE_LOG(TED, Log, TEXT("%s"), content.data()); break;
		case L'Y': UE_LOG(YOSHI, Log, TEXT("%s"), content.data()); break;
		case L'G': UE_LOG(GUUS, Log, TEXT("%s"), content.data()); break;
		case L'R': UE_LOG(RAUL, Log, TEXT("%s"), content.data()); break;
		}
	}
	if (type == L'W')
	{
		switch (name)
		{
		case L'F': UE_LOG(FRANK, Warning, TEXT("%s"), content.data()); break;
		case L'J': UE_LOG(JAN, Warning, TEXT("%s"), content.data()); break;
		case L'T': UE_LOG(TED, Warning, TEXT("%s"), content.data()); break;
		case L'Y': UE_LOG(YOSHI, Warning, TEXT("%s"), content.data()); break;
		case L'G': UE_LOG(GUUS, Warning, TEXT("%s"), content.data()); break;
		case L'R': UE_LOG(RAUL, Warning, TEXT("%s"), content.data()); break;
		}
	}
	if (type == L'E')
	{
		switch (name)
		{
		case L'F': UE_LOG(FRANK, Error, TEXT("%s"), content.data()); break;
		case L'J': UE_LOG(JAN, Error, TEXT("%s"), content.data()); break;
		case L'T': UE_LOG(TED, Error, TEXT("%s"), content.data()); break;
		case L'Y': UE_LOG(YOSHI, Error, TEXT("%s"), content.data()); break;
		case L'G': UE_LOG(GUUS, Error, TEXT("%s"), content.data()); break;
		case L'R': UE_LOG(RAUL, Error, TEXT("%s"), content.data()); break;
		}
	}
}