aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-08 16:07:02 -0800
committerJose Antonio Marquez2012-03-08 16:07:02 -0800
commit4bdb951f2dab6d132ed28ab17888cc819ed811ee (patch)
tree4fa0ac486431b1fb39383c3bb3a01a230a73f422 /js
parent85f21e020ac281e8e545df1cf269034de99a00b1 (diff)
downloadninja-4bdb951f2dab6d132ed28ab17888cc819ed811ee.tar.gz
Adding I/O functionality to RDGE
Added webGL/Canvas file I/O for Ninja, it also created routine for saving data for runtime, however, the runtime RDGE library needs an update for runtime to work, so right now I/O will only work for Ninja.
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js64
-rw-r--r--js/io/system/ninjalibrary.json2
-rw-r--r--js/mediators/io-mediator.js79
3 files changed, 82 insertions, 63 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 05c7d6c0..46fefd90 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -208,49 +208,29 @@ exports.HTMLDocument = Montage.create(TextDocument, {
208 var elt = this.documentRoot; 208 var elt = this.documentRoot;
209 if (elt) 209 if (elt)
210 { 210 {
211// FOR JOSE: The following commented out lines are what the runtime 211 var nWorlds= value.length;
212// version should execute. 212 for (var i=0; i<nWorlds; i++) {
213// var loadForRuntime = true; 213 var importStr = value[i];
214// if (loadForRuntime) 214 var startIndex = importStr.indexOf("id: ");
215// { 215 if (startIndex >= 0) {
216// var cdm = new CanvasDataManager(); 216 var endIndex = importStr.indexOf("\n", startIndex);
217// cdm.loadGLData(elt, value ); 217 if (endIndex > 0) {
218// } 218 var id = importStr.substring( startIndex+4, endIndex);
219// else 219 if (id) {
220 { 220 var canvas = this.findCanvasWithID(id, elt);
221 var nWorlds= value.length; 221 if (canvas) {
222 for (var i=0; i<nWorlds; i++) 222 if (!canvas.elementModel) {
223 { 223 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
224 var importStr = value[i]; 224 }
225 var startIndex = importStr.indexOf( "id: " ); 225 if (canvas.elementModel) {
226 if (startIndex >= 0) 226 if (canvas.elementModel.shapeModel.GLWorld) {
227 { 227 canvas.elementModel.shapeModel.GLWorld.clearTree();
228 var endIndex = importStr.indexOf( "\n", startIndex );
229 if (endIndex > 0)
230 {
231 var id = importStr.substring( startIndex+4, endIndex );
232 if (id)
233 {
234 var canvas = this.findCanvasWithID( id, elt );
235 if (canvas)
236 {
237 if (!canvas.elementModel)
238 {
239 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
240 }
241
242 if (canvas.elementModel)
243 {
244 if (canvas.elementModel.shapeModel.GLWorld)
245 canvas.elementModel.shapeModel.GLWorld.clearTree();
246
247 var index = importStr.indexOf( "webGL: " );
248 var useWebGL = (index >= 0)
249 var world = new GLWorld( canvas, useWebGL );
250 world.import( importStr );
251
252 this.buildShapeModel( canvas.elementModel, world );
253 } 228 }
229 var index = importStr.indexOf( "webGL: " );
230 var useWebGL = (index >= 0)
231 var world = new GLWorld(canvas, useWebGL);
232 world.import( importStr );
233 this.buildShapeModel(canvas.elementModel, world);
254 } 234 }
255 } 235 }
256 } 236 }
diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json
index a61c30d1..00ee7ed2 100644
--- a/js/io/system/ninjalibrary.json
+++ b/js/io/system/ninjalibrary.json
@@ -1,6 +1,6 @@
1{ 1{
2 "libraries": [ 2 "libraries": [
3 {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.6.0.0"}, 3 {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.6.0.0"},
4 {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.0.1"} 4 {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.1.0"}
5 ] 5 ]
6} \ No newline at end of file 6} \ No newline at end of file
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index dcafb38d..c22d95be 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -152,17 +152,7 @@ exports.IoMediator = Montage.create(Component, {
152 // 152 //
153 switch (file.mode) { 153 switch (file.mode) {
154 case 'html': 154 case 'html':
155 //Copy webGL library if needed 155
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 156
167 //TODO: Add check for Monatage library to copy 157 //TODO: Add check for Monatage library to copy
168 158
@@ -357,15 +347,33 @@ exports.IoMediator = Montage.create(Component, {
357 } 347 }
358 } 348 }
359 //Checking for webGL elements in document 349 //Checking for webGL elements in document
360 if (template.webgl && template.webgl.length) { 350 if (template.webgl && template.webgl.length > 0) {
351 var rdgeDirName, rdgeVersion;
352 //Copy webGL library if needed
353 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
354 //Checking for RDGE library to be available
355 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
356 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
357 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
358 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, rdgeDirName);
359 } else {
360 //TODO: Error handle no available library to copy
361 }
362 }
361 // 363 //
362 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); 364 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag;
363 // 365 //
364 for (var i in scripts) { 366 for (var i in scripts) {
365 if (scripts[i].getAttribute) { 367 if (scripts[i].getAttribute) {
366 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll 368 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
367 matchingtags.push(scripts[i]); 369 matchingtags.push(scripts[i]);
368 } 370 }
371 if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) {
372 webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
373 }
374 if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) {
375 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
376 }
369 } 377 }
370 } 378 }
371 // 379 //
@@ -378,13 +386,46 @@ exports.IoMediator = Montage.create(Component, {
378 } 386 }
379 } 387 }
380 // 388 //
389 if (!webgllibtag) {
390 webgllibtag = template.document.content.document.createElement('script');
391 webgllibtag.setAttribute('type', 'text/javascript');
392 webgllibtag.setAttribute('src', rdgeDirName+'/CanvasDataManager.js');
393 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
394 template.document.content.document.head.appendChild(webgllibtag);
395 }
396 //
381 if (!webgltag) { 397 if (!webgltag) {
382 webgltag = template.document.content.document.createElement('script'); 398 webgltag = template.document.content.document.createElement('script');
383 webgltag.setAttribute('data-ninja-webgl', 'true'); 399 webgltag.setAttribute('data-ninja-webgl', 'true');
384 template.document.content.document.head.appendChild(webgltag); 400 template.document.content.document.head.appendChild(webgltag);
385 } 401 }
402 //
403 if (!webgljstag) {
404 webgljstag = template.document.content.document.createElement('script');
405 webgljstag.setAttribute('type', 'text/javascript');
406 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
407 template.document.content.document.head.appendChild(webgljstag);
408 }
409 //TODO: Decide if this should be over-writter or only written on creation
410 webgljstag.innerHTML = "\
411//Loading webGL/canvas data on window load\n\
412window.addEventListener('load', initWebGl, false);\n\
413function initWebGl (e) {\n\
414 window.removeEventListener('load', initWebGl, false);\n\
415 var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace(\"(\", \"\")).replace(\")\", \"\"));\n\
416 if (ninjaWebGlData && ninjaWebGlData.data) {\n\
417 for (var n=0; ninjaWebGlData.data[n]; n++) {\n\
418 ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]);\n\
419 }\n\
420 }\n\
421 //Creating data manager\n\
422 cvsDataMngr = new CanvasDataManager();\n\
423 //Loading data to canvas(es)\n\
424 cvsDataMngr.loadGLData(document.body, ninjaWebGlData, '"+rdgeDirName+"');\n\
425}\
426 ";
386 //TODO: Add version and other data for RDGE 427 //TODO: Add version and other data for RDGE
387 json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; 428 json = '\n({\n\t"version": "'+rdgeVersion+'",\n\t"data": [';
388 //Looping through data to create escaped array 429 //Looping through data to create escaped array
389 for (var j=0; template.webgl[j]; j++) { 430 for (var j=0; template.webgl[j]; j++) {
390 if (j === 0) { 431 if (j === 0) {
@@ -398,18 +439,16 @@ exports.IoMediator = Montage.create(Component, {
398 //Setting string in tag 439 //Setting string in tag
399 webgltag.innerHTML = json;