/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
// namespace for the Ninja Canvas Runtime
var NinjaCvsRt = NinjaCvsRt || {};
///////////////////////////////////////////////////////////////////////
//Loading webGL/canvas data
NinjaCvsRt.initWebGl = function (rootElement, directory) {
var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', ''));
if (ninjaWebGlData && ninjaWebGlData.data) {
for (var n=0; ninjaWebGlData.data[n]; n++) {
ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]);
}
}
//Creating data manager
cvsDataMngr = new NinjaCvsRt.CanvasDataManager();
//Loading data to canvas(es)
cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory);
};
///////////////////////////////////////////////////////////////////////
// Class ShapeRuntime
// Manages runtime shape display
///////////////////////////////////////////////////////////////////////
NinjaCvsRt.CanvasDataManager = function ()
{
this.loadGLData = function(root, valueArray, assetPath )
{
if (assetPath)
this._assetPath = assetPath.slice();
var value = valueArray;
var nWorlds = value.length;
for (var i=0; i<nWorlds; i++)
{
var importStr = value[i];
// there should be some version information in
// the form of 'v0.0;' Pull that off. (the trailing ';' should
// be in the first 24 characters).
var index = importStr.indexOf( ';' );
if ((importStr[0] === 'v') && (index < 24))
{
// JSON format. pull off the version info
importStr = importStr.substr( index+1 );
var jObj = JSON.parse( importStr );
var id = jObj.id;
if (id)
{
var canvas = this.findCanvasWithID( id, root );
if (canvas)
{
new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath );
}
}
}
}
};
this.findCanvasWithID = function( id, elt )
{
var cid = elt.getAttribute( "data-RDGE-id" );
if (cid == id) return elt;
if (elt.children)
{
var nKids = elt.children.length;
for (var i=0; i<nKids; i++)
{
var child = elt.children[i];
var foundElt = this.findCanvasWithID( id, child );
if (foundElt) return foundElt;
}
}
};
};
///////////////////////////////////////////////////////////////////////
// Class GLRuntime
// Manages runtime fora WebGL canvas
///////////////////////////////////////////////////////////////////////
NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath )
{
///////////////////////////////////////////////////////////////////////
// Instance variables
///////////////////////////////////////////////////////////////////////
this._canvas = canvas;
this._context = null;
//
|