11var GDragonRubyGameId = 'dragonruby-sandbox' ;
22var GDragonRubyGameTitle = 'DragonRuby Sandbox' ;
33var GDragonRubyDevTitle = 'DragonRuby' ;
4- var GDragonRubyGameVersion = '2 .0' ;
4+ var GDragonRubyGameVersion = '3 .0' ;
55var GDragonRubyIcon = '/metadata/icon.png' ;
66
77function syncDataFiles ( dbname , baseurl )
@@ -360,27 +360,56 @@ function syncDataFiles(dbname, baseurl)
360360 return retval ;
361361}
362362
363+ var prepareFilesystem = function ( )
364+ {
365+ // Download the game data and set up the filesystem!
366+ // set up a persistent store for save games, etc.
367+ FS . mkdir ( '/persistent' ) ;
368+ FS . mount ( IDBFS , { } , '/persistent' ) ;
369+ FS . syncfs ( true , function ( err ) {
370+ if ( err ) {
371+ console . log ( "WARNING: Failed to populate persistent store. Save games likely lost?" ) ;
372+ } else {
373+ console . log ( "Read in from persistent store." ) ;
374+ }
375+
376+ loadDataFiles ( GDragonRubyGameId , 'gamedata/' , function ( ) {
377+ console . log ( "Game data is sync'd to MEMFS. Starting click-to-play()..." ) ;
378+ //Module.setStatus("Ready!");
379+ //setTimeout(function() { Module.setStatus(""); statusElement.style.display='none'; }, 1000);
380+ Module . setStatus ( "" ) ;
381+ statusElement . style . display = 'none' ;
382+ Module . startClickToPlay ( ) ;
383+ } ) ;
384+ } ) ;
385+ }
386+
387+
363388var statusElement = document . getElementById ( 'status' ) ;
364389var progressElement = document . getElementById ( 'progress' ) ;
365390var canvasElement = document . getElementById ( 'canvas' ) ;
366391
367- canvasElement . style . width = '480px' ;
368- canvasElement . style . height = '270px' ;
392+ canvasElement . style . width = '100%' ;
393+ canvasElement . style . height = '100%' ;
394+ document . getElementById ( 'borderdiv' ) . style . border = '0px' ;
369395
370- statusElement . style . display = 'none' ;
371- progressElement . style . display = 'none' ;
372- document . getElementById ( 'progressdiv' ) . style . display = 'none' ;
396+ // statusElement.style.display = 'none';
397+ // progressElement.style.display = 'none';
398+ // document.getElementById('progressdiv').style.display = 'none';
373399document . getElementById ( 'output' ) . style . display = 'none' ;
374- document . getElementById ( 'game-input' ) . style . display = "none"
375400
376- if ( ! window . parent . window . gtk ) {
377- window . parent . window . gtk = { } ;
378- }
401+ // if (!window.parent.window.gtk) {
402+ // window.parent.window.gtk = {};
403+ // }
379404
380405window . parent . window . gtk . saveMain = function ( text ) {
381406 FS . writeFile ( 'app/main.rb' , text ) ;
382407 window . gtk . play ( ) ;
383408}
409+ // window.parent.window.gtk.saveMain = function(text) {
410+ // FS.writeFile('app/main.rb', text);
411+ // window.gtk.play();
412+ // }
384413
385414
386415var loadDataFiles = function ( dbname , baseurl , onsuccess ) {
@@ -498,8 +527,14 @@ var base64Encode = function(ui8array) {
498527 return out ;
499528}
500529
530+ function startGame ( )
531+ {
532+ Module [ "removeRunDependency" ] ( "dragonruby_init" ) ;
533+ }
534+
535+
501536var Module = {
502- noInitialRun : true ,
537+ noInitialRun : false ,
503538 preInit : [ ] ,
504539 clickedToPlay : false ,
505540 clickToPlayListener : function ( ) {
@@ -510,32 +545,50 @@ var Module = {
510545 div . removeEventListener ( 'click' , Module . clickToPlayListener ) ;
511546 document . body . removeChild ( div ) ;
512547 }
513- if ( window . parent . window . gtk . starting ) {
514- window . parent . window . gtk . starting ( ) ;
515- }
516- Module [ "callMain" ] ( ) ; // go go go!
548+ // if (window.parent.window.gtk.starting) {
549+ // window.parent.window.gtk.starting();
550+ // }
551+
552+ startGame ( ) ; // go go go!
517553 } ,
518554 startClickToPlay : function ( ) {
519555 var base64 = base64Encode ( FS . readFile ( GDragonRubyIcon , { } ) ) ;
520556 var div = document . createElement ( 'div' ) ;
557+ var leftPx = ( ( window . innerWidth - 640 ) / 2 ) ;
558+ var leftPerc = Math . floor ( ( leftPx / window . innerWidth ) * 100 ) ;
521559 div . id = 'clicktoplaydiv' ;
560+ div . style . width = '360px' ;
561+ div . style . height = '360px' ;
522562 div . style . backgroundColor = 'rgb(40, 44, 52)' ;
523-
563+ div . style . position = 'absolute' ;
564+ div . style . top = '50%' ;
565+ div . style . left = '50%' ;
566+ div . style . transform = 'translate(-50%, -50%)' ;
524567
525568 var img = new Image ( ) ;
526569 img . onload = function ( ) { // once we know its size, scale it, keeping aspect ratio.
527- img . style . width = '128px' ;
528- img . style . height = '101px' ;
570+ var pct = 30 ;
571+ var w = img . naturalWidth ;
572+ var h = img . naturalHeight ;
573+ if ( ! w || ! h || ( w == h ) ) {
574+ img . style . width = '' + pct + '%' ;
575+ img . style . height = '' + pct + '%' ;
576+ } else if ( w > h ) {
577+ img . style . width = '' + pct + '%' ;
578+ } else {
579+ img . style . height = '' + pct + '%' ;
580+ }
529581 img . style . display = 'block' ;
530582 }
531583
532584 img . style . display = 'none' ;
533- img . style . width = '128px ' ;
534- img . style . height = '101px ' ;
585+ img . style . width = 'auto ' ;
586+ img . style . height = 'auto ' ;
535587 img . style . margin = 0 ;
536588 img . style . position = 'absolute' ;
537- img . style . top = '10px' ;
538- img . style . left = '176px' ;
589+ img . style . top = '25%' ;
590+ img . style . left = '50%' ;
591+ img . style . transform = 'translate(-50%, -50%)' ;
539592 img . src = 'data:image/png;base64,' + base64 ;
540593 div . appendChild ( img ) ;
541594
@@ -553,40 +606,26 @@ var Module = {
553606 div . appendChild ( p ) ;
554607
555608 p = document . createElement ( 'p' ) ;
556- p . innerHTML = 'Click here to begin , or press Ctrl+S<br/>in the code editor to the left.' ;
609+ p . innerHTML = 'Click the run button , or press Ctrl+S<br/>in the code editor to the left.' ;
557610 p . style [ 'font-family' ] = "monospace" ;
611+ p . style [ 'font-size' ] = "14px" ;
558612 p . style . textAlign = 'center' ;
559613 p . style . backgroundColor = 'rgb(40, 44, 52)' ;
560614 p . style . color = '#FFFFFF' ;
561615 p . style . width = '100%' ;
562616 p . style . position = 'absolute' ;
563- p . style . top = '70 %' ;
617+ p . style . top = '60 %' ;
564618 div . appendChild ( p ) ;
565619
566620 document . body . appendChild ( div ) ;
567621 div . addEventListener ( 'click' , Module . clickToPlayListener ) ;
568622 window . gtk . play = Module . clickToPlayListener ;
569623 } ,
570624 preRun : function ( ) {
571- // set up a persistent store for save games, etc.
572- FS . mkdir ( '/persistent' ) ;
573- FS . mount ( IDBFS , { } , '/persistent' ) ;
574- FS . syncfs ( true , function ( err ) {
575- if ( err ) {
576- console . log ( "WARNING: Failed to populate persistent store. Save games likely lost?" ) ;
577- } else {
578- console . log ( "Read in from persistent store." ) ;
579- }
580-
581- loadDataFiles ( GDragonRubyGameId , 'gamedata/' , function ( ) {
582- console . log ( "Game data is sync'd to MEMFS. Starting click-to-play()..." ) ;
583- //Module.setStatus("Ready!");
584- //setTimeout(function() { Module.setStatus(""); statusElement.style.display='none'; }, 1000);
585- Module . setStatus ( "" ) ;
586- statusElement . style . display = 'none' ;
587- Module . startClickToPlay ( ) ;
588- } ) ;
589- } ) ;
625+ // this prevents the game from running. We'll remove the dependency when
626+ // we have downloaded everything and the user has clicked-through to play.
627+ Module [ "addRunDependency" ] ( "dragonruby_init" ) ;
628+ prepareFilesystem ( ) ; // will get data, async.
590629 } ,
591630 postRun : [ ] ,
592631 print : ( function ( ) {
@@ -624,11 +663,6 @@ var Module = {
624663 canvas . addEventListener ( "click" , function ( ) {
625664 document . getElementById ( 'toplevel' ) . click ( ) ;
626665 document . getElementById ( 'toplevel' ) . focus ( ) ;
627- document . getElementById ( 'game-input' ) . style . display = "inline"
628- document . getElementById ( 'game-input' ) . focus ( ) ;
629- document . getElementById ( 'game-input' ) . blur ( ) ;
630- document . getElementById ( 'game-input' ) . style . display = "none"
631- window . scrollTo ( 0 , 0 ) ;
632666 canvas . focus ( ) ;
633667 } ) ;
634668
@@ -668,36 +702,26 @@ window.onerror = function(event) {
668702 } ;
669703} ;
670704
705+ // sanity check this before downloading anything heavy.
671706var hasWebAssembly = false ;
672707if ( typeof WebAssembly === "object" && typeof WebAssembly . Memory === "function" ) {
673708 hasWebAssembly = true ;
674709}
675710//console.log("Do we have WebAssembly? " + ((hasWebAssembly) ? "YES" : "NO"));
711+ if ( ! hasWebAssembly ) {
712+ Module . setStatus ( "Your browser doesn't have WebAssembly support. Please upgrade." ) ;
713+ } else {
714+ var buildtype = "wasm" ;
715+ var module = "dragonruby-" + buildtype + ".js" ;
716+ window . gtk = { } ;
717+ window . gtk . module = Module ;
676718
677- var buildtype = hasWebAssembly ? "wasm" : "asmjs" ;
678- var module = "dragonruby-" + buildtype + ".js" ;
679- window . gtk = { } ;
680- window . gtk . module = Module ;
681-
682- //console.log("Our main module is: " + module);
719+ //console.log("Our main module is: " + module);
683720
684- var script = document . createElement ( 'script' ) ;
685- script . src = module ;
686- if ( hasWebAssembly ) {
721+ var script = document . createElement ( 'script' ) ;
722+ script . src = module ;
687723 script . async = true ;
688- } else {
689- script . async = false ; // !!! FIXME: can this be async?
690- ( function ( ) {
691- var memoryInitializer = module + '.mem' ;
692- if ( typeof Module [ 'locateFile' ] === 'function' ) {
693- memoryInitializer = Module [ 'locateFile' ] ( memoryInitializer ) ;
694- } else if ( Module [ 'memoryInitializerPrefixURL' ] ) {
695- memoryInitializer = Module [ 'memoryInitializerPrefixURL' ] + memoryInitializer ;
696- }
697- var meminitXHR = Module [ 'memoryInitializerRequest' ] = new XMLHttpRequest ( ) ;
698- meminitXHR . open ( 'GET' , memoryInitializer , true ) ;
699- meminitXHR . responseType = 'arraybuffer' ;
700- meminitXHR . send ( null ) ;
701- } ) ( ) ;
724+ document . body . appendChild ( script ) ;
702725}
703- document . body . appendChild ( script ) ;
726+
727+ // end of dragonruby-html5-loader.js ...
0 commit comments