﻿/// <reference path="../../ajax/References.js" />
/// <reference path="XnaTestGame.js" />

/*****************************************************************************
This would be a typical "program start" file.

We would be referenced from a page (so we are a code beside file) 
that included the 2 bootstrap ajax js files (extensions and ContentLoader).

We start off by referencing References.js (the entire ajax API) and then any of our application files 
(or setup our own "references.js" file to load the API of our application.

Next we set the path from the page to ajax. 
We then add our application by name (which sets up our application's namespace for us too). 

//-----------------------------------------------------------------------------
Note: This file may also referenced back from our application files (so we depend on them, and them on us) as  
a namespace created in this way (using addApplication() or addNamespace() methods) will only register
with intellisense when done in an external file (which is processed entirely by the intellisense engine).

That is why we reference them (they include the addNamespace() method) so we get to see the application API
and they reference us (so our addApplication is executed and the namespace created.
//-----------------------------------------------------------------------------

We then proceed to write a standard main() starting point for our app.

In here we create our game instance, show it and start it's game loop. 

We can use intellisense to write the line:

    var game = new xnaTestApp.XnaTestGame();

but must change that to use the safe loading (as the entire api is dynamically loaded 
only when needed (lazy loading at class level). We change it slightly to this:

    var game = $new("xnaTestApp.XnaTestGame");
    
However, this factory method (which will download the class if it does not yet exist, then return an instance of it for you)
returns only a basic object type and we must "cast" this back to our game type, like this:

    game = xnaTestApp.XnaTestGame.parse(game);

Note: All objects in out API should support a static "parse" method to return the passed pointer back top the caller, 
cast as the correct type. We use Xml style comments to achieve this, like this:

xnaTestApp.XnaTestGame.parse = function(obj)
{///<returns type="xnaTestApp.XnaTestGame"/>
    return obj;
}


Finally we add our main method as an event listener (as a function pointer) of the window's "onload" event.

/*****************************************************************************/
ajax.path = "../ajax";
addApplication("xnaTestApp", "xnaTestApp");
//-----------------------------------------------------------------------------
// program - main entry point
function main()
{        
    var console = $new("ajax.windows.Console", document, "");
    ajax.debug.Output = console;
    console.show();     
    
    createGame();              
}

function createGame()
{
    var game = $new("xnaTestApp.XnaTestGame");// $new("xnaTestApp.XnaTestGame");
    //var game = $new("ajax.xna.Game", document);
    game = xnaTestApp.XnaTestGame.parse(game);
    game.showCentered();
    game.loop.start();        
}

// use the window load event to start us off.
$getEvent(window, window, "onload").addListener(main);

