//-----------------------------------------------------------------------------------------
//
// Script preprocessor definitions
//
//-----------------------------------------------------------------------------------------

//Dev mode
//options: RELEASE, DEBUG, TESTING, TESTERPROFILE, DSOMAKER, DEBUGSAVE, DEBUGGRID
#define RELEASE
//#define DEBUG
//#define DEBUGGRID
//#define TESTING
//#define TESTERPROFILE
//#define DEBUGRIDMOVE
//#define DEBUGSAVE

// Output a console log
#ifdef DEBUG
setLogMode(6);
#endif

//Pro korektni provedeni preprocesorovych definic (vzdy prekompiluje cs soubory)
#ifndef RELEASE
setIgnoreDSOs();
#endif

//Language
//options: LANG_EN, LANG_CZ, LANG_PL, LANG_ES, LANG_FR, LANG_RU, LANG_PT, LANG_DE
#define LANG_EN

//Platform
//options: DESKTOP, IPAD, IPHONEIPOD
//#define IPAD
#define DESKTOP
//#define IPHONEIPOD
//#define IPHONEONDESKTOP

//Distribution
//options: APPSTORE, BFG, RETAIL
#define BFG

//Content
//options: LITE, FULL, PROMOSURVEY
//#define LITE
//#define FULL
#define PROMOSURVEY


//fonty z fnt + ulozeni objektu
//#define USEFNT

$GAME:PATH:IMAGES = $GAME:PATH:IMAGES = "~/data/images/";
$GAME:PATH:FONTSUFFIX = "";
$GAME:HD = 0;

//Platform specifics
//Klicove vracene hodnoty: iPad X Y, iPadMini X Y, iPhone X Y, iPod X Y, simulator
#ifdef IPAD || IPHONEIPOD

$DEVICETYPE = GetDeviceType();
echo("\nDevice type: "@ $DEVICETYPE @" \n");
%deviceSubType = getWord($DEVICETYPE, 1);
//iPad1 a iPad2 a iPadMini1
if(getWord($DEVICETYPE, 0) !$= "iPhone" && getWord($DEVICETYPE, 0) !$="simulator") //PV: tohle muze byt i iPod Touch!
{
    if(%deviceSubType $= "1" || %deviceSubType $= "2")
        $GAME:PATH:IMAGES = "~/data/images-satur/";
    //iPad3 a iPad4
    else
    {
        $GAME:HD = 1; //pouzito v engine!
        $GAME:PATH:FONTSUFFIX = "-hd";
        $GAME:PATH:IMAGES = "~/data/images-hd/";
    }
	if(%deviceSubType $= "1" || %deviceSubType $= "2")
    	$GAME:PATH:IMAGES = "~/data/images-satur/";
	//iPad3 a iPad4
	else
	{
		$GAME:HD = 1; //pouzito v engine!
    	$GAME:PATH:FONTSUFFIX = "-hd";
    	$GAME:PATH:IMAGES = "~/data/images-hd/";
	}
}

//PV: Tohle je jen DEBUG, ne?
else
{
	$GAME:PATH:IMAGES = "~/data/images-iphone/";
}
#endif

#ifdef IPHONEONDESKTOP
	$GAME:PATH:IMAGES = "~/data/images-iphone/";
#endif


// Timestamp the initialization process start
#ifdef DEBUG
$Debug::loadStartTime = getRealTime();
#endif


//Vytvor mi z CSek DSocka dle akt. nastaveni vsech preproc. maker
//TODO i dalsi CS  i jine (T2D apod.) soubory z game, common a scripts
/*
function compileAllcs()
{
    $GAME:PATH = "game/";
	%b = findFirstFile($GAME:PATH @"*.cs");
	while(%b !$= "")
	{
		compile(%b);
		%b = findNextFile($GAME:PATH @"*.cs");
	}
    echo("COMPILING");
}

compileAllcs();
*/


#ifdef IPAD || IPHONEIPOD

/// Player Initialization Procedure
///
function onStart()
{

    // System version printout
    echo("\niTorque 2D (" @ getT2DVersion() @ ") initializing...");

    // Locate the cached font directory
    //$Gui::fontCacheDirectory = expandFilename("data/fonts");

    // Load preferences.
    exec("scripts/system/properties.cs");

    // Load up helper modules and system
    exec("scripts/system/xml.cs");
    exec("scripts/system/system.cs");

    _defaultGameconfigurationData();

    _loadGameConfigurationData();

    switch$($platform)
    {
        case "iphone":
            $pref::iOS::DeviceType = $iOS::constant::iPhone;
        case "iphone4":
            $pref::iOS::DeviceType = $iOS::constant::iPhone4;
        case "ipad":
            $pref::iOS::DeviceType = $iOS::constant::iPad;
        case "ipad3":
            $pref::iOS::DeviceType = $iOS::constant::iPad3;
    }

    // Initialize the core systems (canvas, t2dSceneGraph, OpenAL, etc
    if( !isFunction( "initializeSystem" ) )
    {
        messageBox( "Game Startup Error", "'initializeSystem' function could not be found." @
                   "\nThis could indicate a bad or corrupt scripts/system directory for your game." @
                   "\n\nThe Game will now shutdown because it cannot properly function", "Ok", "MIStop" );
        quit();
    }

    initializeSystem();
    //echo("INITSYSTEM");

    // Initialize project management for game and editor
    if( !isFunction( "initializeProject" ) || !isFunction( "_initializeProject" ) )
    {
        messageBox( "Game Startup Error", "'initializeGame'  or '_initializeProject' functions could not be found." @
                   "\nThis could indicate a system directory for your game." @
                   "\n\nThe Game will now shutdown because it cannot properly function", "Ok", "MIStop" );
        quit();
    }

    // Responsible for loading behaviors, datablocks, brushes, etc
    _initializeProject();
    //echo("_INITPROJECT");

    // Load up the in-game gui.
    // Size and orientation will be set in initializeGame()
    //exec("gui/mainScreen.gui");

    // Startup the game project
    initializeProject();
    //echo("INITPROJECT");

}

#endif


function onExit()
{
    if($platform $= "windows" || $platform $= "macos")
        _saveGameConfigurationData();
}

function onResolutionChange()
{
	//echo("BUGGER, thou just changed our resolution to" SPC getRes());

	%res = getRes();
	$GAME:MATCH_EFFECT_LINE_WIDTH_1 = mRound(3/1024 * %res.x);
#ifdef IPHONEIPOD || IPHONEONDESKTOP
	$GAME:MATCH_EFFECT_LINE_WIDTH_2 = mRound(3/640 * %res.x);
#else
	$GAME:MATCH_EFFECT_LINE_WIDTH_2 = mRound(3/1024 * %res.x);
#endif
}

//---------------------------------------------------------------------------------------------
// Load the paths we need access to
//---------------------------------------------------------------------------------------------
function loadPath( %path )
{
   setModPaths( getModPaths() @ ";" @ %path );
   exec(%path @ "/main.cs");

}

//---------------------------------------------
// Do some bootstrap voodoo to get the game to
// the initializeProject phase of loading and
// pass off to the user
//---------------------------------------------

#ifdef DESKTOP
loadPath( "common" );
#endif

loadPath( "game" );

onStart();


#ifdef DESKTOP
// Initialized
echo("\nTorque Game Builder (" @ getT2DVersion() @ ") initialized...");
/*
if( !isFunction( "initializeProject" ) || !isFunction( "_initializeProject" ) )
{
   messageBox( "Game Startup Error", "'initializeProject' function could not be found." @
               "\nThis could indicate a bad or corrupt common directory for your game." @
               "\n\nThe Game will now shutdown because it cannot properly function", "Ok", "MIStop" );
   quit();
}
*/
//_initializeProject();

// Startup the project
initializeProject();

#endif

