//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
$currentProject = "";

function exitDemo ()
{
	if ($runWithEditors)
	{
		toggleLevelEditor();
	}
	else
	{
		quit();
	}
}
function _initializeProject ()
{//echo("_initializeProject()");
	// Managed File Paths
	%dbFile = "/datablocks.cs";
	%persistFile = "../scripts/persistent.cs";
	%brushFile = "../scripts/brushes.cs";   
	%behaviorsDirectory = "../scripts/";   
	%userDatablockFile = "/datablocks.cs";
	%userGUIProfileFile = "../scripts/guiProfiles.cs";
	
	// Default font sizes.
	$UIGameFontSize = 16;
	$largeFont = 16;
	$smallFont = 10;
	
	// Initialize $mazeDimension here!
	$mazeDimension = 32;
	
	//---------------------------------------------------------------------------   
	// Project Resources
	//---------------------------------------------------------------------------
	// --  This MUST be done BEFORE datablocks and persistent objects are loaded.
	%resPath = expandFileName("resources");
	
	// Index resources.
	addResPath(%resPath);
	
	if (!isObject($dependentResourceGroup))
	{
		$dependentResourceGroup = new SimGroup();
	}
	
	%resList = getDirectoryList(%resPath, 0);
	%resCount = getFieldCount(%resList);
	
	for (%i = 0; %i < %resCount; %i++)
	{
		%resName = getField(%resList, %i);
		%resFile = %resPath @ "/" @ %resName;
		
		%resObject = ResourceObject::load(%resFile);
		if (!isObject(%resObject))
		{
			error(" % Game Resources : FAILED Loading Resource" SPC %resName);
			continue;
		}
		else
		{
			echo(" % Game Resources : Loaded Resource" SPC %resName);
		}
		
		// Create a dependentResourcegroup object
		%entry = new ScriptObject() { Name = %resName; };
		$dependentResourceGroup.add( %entry );
	}
	
	//---------------------------------------------------------------------------
	// Managed Datablocks
	//---------------------------------------------------------------------------
	if ( isFile( %dbFile ) || isFile( %dbFile @ ".dso" ) )
		exec( %dbFile );
	
	if( !isObject( $managedDatablockSet ) )   
		$managedDatablockSet = new SimSet();
	
	//---------------------------------------------------------------------------
	// Managed Persistent Objects
	//---------------------------------------------------------------------------
	if ( isFile( %persistFile ) || isFile( %persistFile @ ".dso" ) )
		exec( %persistFile );

	if( !isObject( $persistentObjectSet ) )   
		$persistentObjectSet = new SimSet();
	
	//---------------------------------------------------------------------------
	// Managed Brushes
	//---------------------------------------------------------------------------
	if ( isFile( %brushFile ) || isFile( %brushFile @ ".dso" ) )
		exec( %brushFile );
	
	if( !isObject( $brushSet ) )   
		$brushSet = new SimSet();
	
	//---------------------------------------------------------------------------
	// User Defined Datablocks
	//---------------------------------------------------------------------------
	addResPath( %userDatablockFile );   
	if( isFile( %userDatablockFile ) )
		exec( %userDatablockFile );
    
	//---------------------------------------------------------------------------
	// Behaviors
	//---------------------------------------------------------------------------
	addResPath(%behaviorsDirectory);
	
	// Compile all the cs files.
	%behaviorsSpec = %behaviorsDirectory @ "/*.cs";
	for (%file = findFirstFile(%behaviorsSpec); %file !$= ""; %file = findNextFile(%behaviorsSpec))
		compile(%file);
	
	// And exec all the dsos.
	%behaviorsSpec = %behaviorsDirectory @ "/*.cs.dso";
	for (%file = findFirstFile(%behaviorsSpec); %file !$= ""; %file = findNextFile(%behaviorsSpec))
		exec(strreplace(%file, ".cs.dso", ".cs"));
	
	//---------------------------------------------------------------------------
	// User Defined GUI Profiles
	//---------------------------------------------------------------------------
	addResPath( %userGUIProfileFile );   
	if( isFile( %userGUIProfileFile ) )
		exec( %userGUIProfileFile );
}
// Test function to see setup buttons gui profiles and text!
function showDebugSetupMenuGui ()
{//echo("showDebugSetupMenuGui()");
	// Spit out debug code to see what's going on with disappearing setup button text!
	echo("CustomGuiButtonProfile.fontType =" SPC CustomGuiButtonProfile.fontType);
	echo("CustomGuiButtonProfile.fontColor =" SPC CustomGuiButtonProfile.fontColor);
	echo("CustomGuiButtonProfile.fontColorHL =" SPC CustomGuiButtonProfile.fontColorHL);
			echo("");
	echo("OptionsAVOkButton.profile =" SPC OptionsAVOkButton.profile);
		echo("     |--->OptionsAVOkButton.text =" SPC OptionsAVOkButton.text);
	echo("OptionsAVApplyButton.profile =" SPC OptionsAVApplyButton.profile);
		echo("     |--->OptionsAVApplyButton.text =" SPC OptionsAVApplyButton.text);
	echo("OptionsAVDefaultsButton.profile =" SPC OptionsAVDefaultsButton.profile);
		echo("     |--->OptionsAVDefaultsButton.text =" SPC OptionsAVDefaultsButton.text);
	echo("OptionsAVCancelButton.profile =" SPC OptionsAVCancelButton.profile);
		echo("     |--->OptionsAVCancelButton.text =" SPC OptionsAVCancelButton.text);
			echo("");
	echo("OptionsGSRevertButton.profile =" SPC OptionsGSRevertButton.profile);
		echo("     |--->OptionsGSRevertButton.text =" SPC OptionsGSRevertButton.text);
	echo("OptionsGSOkButton.profile =" SPC OptionsGSOkButton.profile);
		echo("     |--->OptionsGSOkButton.text =" SPC OptionsGSOkButton.text);
	echo("OptionsGSCancelButton.profile =" SPC OptionsGSCancelButton.profile);
		echo("     |--->OptionsGSCancelButton.text =" SPC OptionsGSCancelButton.text);
			echo("");
	echo("OptionsKBDefaultsButton.profile =" SPC OptionsKBDefaultsButton.profile);
		echo("     |--->OptionsKBDefaultsButton.text =" SPC OptionsKBDefaultsButton.text);
	echo("SetDefaultXbox360HardbindsButton.profile =" SPC SetDefaultXbox360HardbindsButton.profile);
		echo("     |--->SetDefaultXbox360HardbindsButton.text =" SPC SetDefaultXbox360HardbindsButton.text);
	echo("OptionsKBCancelButton.profile =" SPC OptionsKBCancelButton.profile);
		echo("     |--->OptionsKBCancelButton.text =" SPC OptionsKBCancelButton.text);
	echo("OptionsKBApplyButton.profile =" SPC OptionsKBApplyButton.profile);
		echo("     |--->OptionsKBApplyButton.text =" SPC OptionsKBApplyButton.text);
}
function populateFonts ()
{//echo("populateFonts()");echo("$GameFont =" SPC $GameFont);
return;
    %sizes = "16 18";
    for (%i = 0; %i < getWordCount(%sizes); %i++) 
	{
        populateFontCacheRange($GameFont, getWord(%sizes, %i), 32, 126);
	}
    writeFontCache();
}