aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-04-02 16:28:39 -0700
committerJohn Mayhew2012-04-02 16:28:39 -0700
commitb4155fb4c33675a8a7cd37473513718043fdf0ba (patch)
tree3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/mediators/io-mediator.js
parent5ba9aeac94c86049423fd5d4b37b277263939c13 (diff)
parentc6de22bf42be90b403491b5f87b1818d9020310c (diff)
downloadninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts: js/helper-classes/RDGE/rdge-compiled.js js/helper-classes/RDGE/runtime/GLRuntime.js js/helper-classes/RDGE/src/core/script/MeshManager.js js/helper-classes/RDGE/src/core/script/engine.js js/helper-classes/RDGE/src/core/script/fx/ssao.js js/helper-classes/RDGE/src/core/script/init_state.js js/helper-classes/RDGE/src/core/script/run_state.js js/helper-classes/RDGE/src/core/script/scenegraphNodes.js js/helper-classes/RDGE/src/core/script/utilities.js js/helper-classes/RDGE/src/tools/compile-rdge-core.bat js/helper-classes/RDGE/src/tools/compile-rdge-core.sh js/helper-classes/RDGE/src/tools/rdge-compiled.js js/lib/drawing/world.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/linear-gradient-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-blur-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/relief-tunnel-material.js js/lib/rdge/materials/square-tunnel-material.js js/lib/rdge/materials/star-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/tunnel-material.js js/lib/rdge/materials/twist-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/uber-material.js js/lib/rdge/materials/water-material.js js/lib/rdge/materials/z-invert-material.js js/preloader/Preloader.js
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js219
1 files changed, 190 insertions, 29 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index dcafb38d..1efbb8bb 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -6,10 +6,11 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 FileIo = require("js/io/system/fileio").FileIo, 11 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo; 12 ProjectIo = require("js/io/system/projectio").ProjectIo,
13 TemplateCreator = require("node_modules/tools/template-creator").TemplateCreator;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14// 15//
15exports.IoMediator = Montage.create(Component, { 16exports.IoMediator = Montage.create(Component, {
@@ -152,17 +153,7 @@ exports.IoMediator = Montage.create(Component, {
152 // 153 //
153 switch (file.mode) { 154 switch (file.mode) {
154 case 'html': 155 case 'html':
155 //Copy webGL library if needed 156
156 if (file.webgl && file.webgl.length > 0) {
157 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
158 //Checking for RDGE library to be available
159 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
160 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase());
161 } else {
162 //TODO: Error handle no available library to copy
163 }
164 }
165 }
166 157
167 //TODO: Add check for Monatage library to copy 158 //TODO: Add check for Monatage library to copy
168 159
@@ -357,15 +348,50 @@ exports.IoMediator = Montage.create(Component, {
357 } 348 }
358 } 349 }
359 //Checking for webGL elements in document 350 //Checking for webGL elements in document
360 if (template.webgl && template.webgl.length) { 351 if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix
352 var rdgeDirName, rdgeVersion;
353 //Copy webGL library if needed
354 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
355 //Checking for RDGE library to be available
356 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
357 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
358 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
359 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, rdgeDirName, hackRename.bind(this));
360 //TODO: Remove, this is copying the library into a static name
361 function hackRename (status) {
362 if (status) {
363 setTimeout(function () {
364 this.application.ninja.coreIoApi.copyDirectory({sourceUri: template.document.root+rdgeDirName, destUri: template.document.root+'assets'});
365 }.bind(this), 3000);
366 }
367 }
368 } else {
369 //TODO: Error handle no available library to copy
370 }
371 }
361 // 372 //
362 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); 373 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag;
363 // 374 //
364 for (var i in scripts) { 375 for (var i in scripts) {
365 if (scripts[i].getAttribute) { 376 if (scripts[i].getAttribute) {
366 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll 377 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
367 matchingtags.push(scripts[i]); 378 matchingtags.push(scripts[i]);
368 } 379 }
380 if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) {
381 webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
382 }
383 if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) {
384 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
385 }
386 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
387 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
388 }
389 if (scripts[i].getAttribute('type') !== 'text/montage-serialization') {
390 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
391 }
392 if (scripts[i].getAttribute('data-mjs-lib') !== null) {
393 mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
394 }
369 } 395 }
370 } 396 }
371 // 397 //
@@ -378,13 +404,47 @@ exports.IoMediator = Montage.create(Component, {
378 } 404 }
379 } 405 }
380 // 406 //
407 if (!webglrdgetag) {
408 webglrdgetag = template.document.content.document.createElement('script');
409 webglrdgetag.setAttribute('type', 'text/javascript');
410 webglrdgetag.setAttribute('src', rdgeDirName+'/rdge-compiled.js');
411 webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true');
412 template.document.content.document.head.appendChild(webglrdgetag);
413 }
414 //
415 if (!webgllibtag) {
416 webgllibtag = template.document.content.document.createElement('script');
417 webgllibtag.setAttribute('type', 'text/javascript');
418 webgllibtag.setAttribute('src', rdgeDirName+'/canvas-runtime.js');
419 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
420 template.document.content.document.head.appendChild(webgllibtag);
421 }
422 //
381 if (!webgltag) { 423 if (!webgltag) {
382 webgltag = template.document.content.document.createElement('script'); 424 webgltag = template.document.content.document.createElement('script');
383 webgltag.setAttribute('data-ninja-webgl', 'true'); 425 webgltag.setAttribute('data-ninja-webgl', 'true');
384 template.document.content.document.head.appendChild(webgltag); 426 template.document.content.document.head.appendChild(webgltag);
385 } 427 }
386 //TODO: Add version and other data for RDGE 428 //TODO: Remove this tag and place inside JS file
387 json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; 429 if (!webgljstag) {
430 webgljstag = template.document.content.document.createElement('script');
431 webgljstag.setAttribute('type', 'text/javascript');
432 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
433 template.document.content.document.head.appendChild(webgljstag);
434 }
435 //TODO: Decide if this should be over-writter or only written on creation
436 var rootElement = 'document.body'; //TODO: Set actual root element
437 webgljstag.innerHTML = "\
438//Loading webGL/canvas data on window load\n\
439window.addEventListener('load', loadWebGL, false);\n\
440function loadWebGL (e) {\n\
441 window.removeEventListener('load', loadWebGL, false);\n\
442 //Calling method to initialize all webGL/canvas(es)\n\
443 initWebGl("+rootElement+", '"+rdgeDirName+"/');\n\
444}\
445 ";
446 //TODO: This data should be saved to a JSON file eventually
447 json = '\n({\n\t"version": "'+rdgeVersion+'",\n\t"directory": "'+rdgeDirName+'/",\n\t"data": [';
388 //Looping through data to create escaped array 448 //Looping through data to create escaped array
389 for (var j=0; template.webgl[j]; j++) { 449 for (var j=0; template.webgl[j]; j++) {
390 if (j === 0) { 450 if (j === 0) {
@@ -398,18 +458,71 @@ exports.IoMediator = Montage.create(Component, {
398 //Setting string in tag 458 //Setting string in tag
399 webgltag.innerHTML = json; 459 webgltag.innerHTML = json;
400 } 460 }
461
462
463
464
465
466
467
468 //
469 var mjsCounter = 0, mjsComponents = [], temp = TemplateCreator.create();
470 //
471 for (var m in template.mjs) {
472 mjsComponents.push(template.mjs[m]);
473 mjsCounter++;
474 }
475 //
476 if (template.mjs && mjsCounter > 0) {
477 var mjsDirName, mjsVersion,
478 mjscode = temp.initWithHeadAndBodyElements(template.document.content.document.documentElement.head, template.document.content.document.documentElement.body, mjsComponents)._ownerSerialization;
479 //Copy Montage library if needed
480 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
481 //Checking for Montage library to be available
482 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
483 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
484 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
485 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, mjsDirName);
486 //TODO: Fix to allow no overwrite and nested locations
487 var packjson = this.application.ninja.coreIoApi.createFile({uri: template.document.root+'package.json', contents: '{"mappings": {"montage": "'+mjsDirName+'/"}}'});
488 } else {
489 //TODO: Error handle no available library to copy
490 }
491 }
492 //
493 if (!mjslibtag) {
494 mjslibtag = template.document.content.document.createElement('script');
495 mjslibtag.setAttribute('type', 'text/javascript');
496 mjslibtag.setAttribute('src', mjsDirName+'/montage.js');
497 mjslibtag.setAttribute('data-mjs-lib', 'true');
498 template.document.content.document.head.appendChild(mjslibtag);
499 }
500 //
501 if (!mjstag) {
502 mjstag = template.document.content.document.createElement('script');
503 mjstag.setAttribute('type', 'text/montage-serialization');
504 template.document.content.document.head