//	AppSettingsExample.cpp - Example of how to implement the unimplemented
//							 AppSettings bits.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#include "AppSettings.h"
#include "Application.h"
#include "DebugHeaders.h"

#include "TitleScreen.h"
#include "TimeAttack.h"
#include "Challenge.h"

#include "drawing/GLImmediateDrawer.h"
#include "drawing/GLESDrawer.h"
#include "TonesGlobalData.h"
#include "TonesSounder.h"
#include "ToneFactory.h"

#include "tones/ReverseTone.h"
#include "tones/DropperTone.h"
#include "tones/FastTone.h"
#include "tones/SlowTone.h"
#include "tones/MedTone.h"

#include <sstream>

using namespace std;

//------------------------------------------------------------------------------
wstring AppSettings::applicationName = L"Tones";
wstring AppSettings::applicationVersion = L"0.53";

//------------------------------------------------------------------------------
void AppSettings::initialise(CmdLineParams& cmdLine,
							 Application *app,
							 KeyManager& keyManager,
							 wstring& helpText)
{
	//Register your interest in any command line arguments.

	//Setup the dimensions of the drawing area.
	setDrawingDimensions(1280, 720, AlterRatio);

	//Register all possible GameStates.
	app->registerGameState(L"TitleScreen", &TitleScreen::creator, true);
	app->registerGameState(L"Challenge", &Challenge::creator);
	app->registerGameState(L"TimeAttack", &TimeAttack::creator);

	//Setup some default key mappings.
	// - Player 1 movement.
	keyManager.addMapping(L"P1Up", L"CursorUp", true);
	keyManager.addMapping(L"P1Left", L"CursorLeft", true);
	keyManager.addMapping(L"P1Right", L"CursorRight", true);
	keyManager.addMapping(L"P1Down", L"CursorDown", true);

	// - General.
	keyManager.addMapping(L"Escape", L"Escape", true);
	keyManager.addMapping(L"Action", L"Space", true);
	keyManager.addMapping(L"Action", L"z", true);

	//Fill out helpText.

	//Set LoadingScreen colours.
	setLoadingColours(ThreeFloats(1.0f),
					  ThreeFloats(0.85f),
					  ThreeFloats(0.0f),
					  //ThreeFloats(0.265625f, 0.25f, 0.6640625f),
					  ThreeFloats(1.0f));

	//Setup ToneFactory.
	DebugStatement("Application: Setting up ToneFactory...");
	ToneFactory::getInstance().registerNormalToneCreator(L"FastTone",
														 shared_ptr<ToneCreator>(NiallNew FastCreator()));
	ToneFactory::getInstance().registerNormalToneCreator(L"MedTone",
														 shared_ptr<ToneCreator>(NiallNew MedCreator()));
	ToneFactory::getInstance().registerNormalToneCreator(L"SlowTone",
														 shared_ptr<ToneCreator>(NiallNew SlowCreator()));
	ToneFactory::getInstance().registerSpecialToneCreator(L"ReverseTone",
														  shared_ptr<ToneCreator>(NiallNew ReverseCreator()));
	ToneFactory::getInstance().registerSpecialToneCreator(L"DropperTone",
														  shared_ptr<ToneCreator>(NiallNew DropperCreator()));
	DebugStatement("Application: ...ToneFactory setup complete.");
}

//------------------------------------------------------------------------------
DrawerPtr AppSettings::getDrawer(const std::wstring& drawerType)
{
	if(drawerType == L"GLImmediateDrawer")
		return DrawerPtr(new GLImmediateDrawer());
	else
	{
		if(GLESDrawer::isSupported())
			return DrawerPtr(new GLESDrawer());
		else
		{
			DebugStatement(L"GLESDrawer not supported. Falling back to GLImmediateDrawer");
			return DrawerPtr(new GLImmediateDrawer());
		}
	}
}

//------------------------------------------------------------------------------
SounderPtr AppSettings::getSounder()
{
	return SounderPtr(new TonesSounder());
}

//------------------------------------------------------------------------------
GlobalDataPtr AppSettings::getGlobalData()
{
	return GlobalDataPtr(new TonesGlobalData());
}
