//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------

function onStart()
{
}

function onExit()
{
   echo("Thanks for playing Aspectus.");
}

// Defaults that command line arguments may overwrite.
$logModeSpecified = false;

function parseArgs()
{
   for (%i = 1; %i < $Game::argc; %i++)
   {
      // Grab the argument.
      %arg = $Game::argv[%i];
      // Grab the next argument for those args that require parameters.
      %nextArg = $Game::argv[%i + 1];
      // Check if there is another argument.
      %hasNextArg = $Game::argc - %i > 1;

      // Handle the argument.
      switch$ (%arg)
      {
         // Set the console logging mode.
         case "-log":
            $argUsed[%i]++;
            if (%hasNextArg)
            {
               if (%nextArg != 0)
                  %nextArg += 4;

               setLogMode(%nextArg);
               $logModeSpecified = true;
               $argUsed[%i + 1]++;
               %i++;
            }
            else
               error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");

         // Save a journal of this run of the engine.
         case "-jSave":
            $argUsed[%i]++;
            if (%hasNextArg)
            {
               echo("Saving event log to journal: " @ %nextArg);
               saveJournal(%nextArg);
               $argUsed[%i + 1]++;
               %i++;
            }
            else
               error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
      }
   }
   
   return true;
}

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

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

// Output a console log
if(!$logModeSpecified) setLogMode(2);

loadPath( "common" );

loadPath( "game" );

if( parseArgs() )
{
   onStart();

   // Initialized
   echo("\nAspectus 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\nAspectus will now shutdown because it cannot properly function", "Ok", "MIStop" );
      quit();
   }

   _initializeProject();

   // Startup the project
   initializeProject();
}
else
   quit();