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,6 +360,31 @@ 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' ) ;
@@ -498,8 +523,14 @@ var base64Encode = function(ui8array) {
498523 return out ;
499524}
500525
526+ function startGame ( )
527+ {
528+ Module [ "removeRunDependency" ] ( "dragonruby_init" ) ;
529+ }
530+
531+
501532var Module = {
502- noInitialRun : true ,
533+ noInitialRun : false ,
503534 preInit : [ ] ,
504535 clickedToPlay : false ,
505536 clickToPlayListener : function ( ) {
@@ -510,32 +541,50 @@ var Module = {
510541 div . removeEventListener ( 'click' , Module . clickToPlayListener ) ;
511542 document . body . removeChild ( div ) ;
512543 }
513- if ( window . parent . window . gtk . starting ) {
514- window . parent . window . gtk . starting ( ) ;
515- }
516- Module [ "callMain" ] ( ) ; // go go go!
544+ // if (window.parent.window.gtk.starting) {
545+ // window.parent.window.gtk.starting();
546+ // }
547+
548+ startGame ( ) ; // go go go!
517549 } ,
518550 startClickToPlay : function ( ) {
519551 var base64 = base64Encode ( FS . readFile ( GDragonRubyIcon , { } ) ) ;
520552 var div = document . createElement ( 'div' ) ;
553+ var leftPx = ( ( window . innerWidth - 640 ) / 2 ) ;
554+ var leftPerc = Math . floor ( ( leftPx / window . innerWidth ) * 100 ) ;
521555 div . id = 'clicktoplaydiv' ;
556+ div . style . width = '360px' ;
557+ div . style . height = '360px' ;
522558 div . style . backgroundColor = 'rgb(40, 44, 52)' ;
523-
559+ div . style . position = 'absolute' ;
560+ div . style . top = '50%' ;
561+ div . style . left = '50%' ;
562+ div . style . transform = 'translate(-50%, -50%)' ;
524563
525564 var img = new Image ( ) ;
526565 img . onload = function ( ) { // once we know its size, scale it, keeping aspect ratio.
527- img . style . width = '128px' ;
528- img . style . height = '101px' ;
566+ var pct = 30 ;
567+ var w = img . naturalWidth ;
568+ var h = img . naturalHeight ;
569+ if ( ! w || ! h || ( w == h ) ) {
570+ img . style . width = '' + pct + '%' ;
571+ img . style . height = '' + pct + '%' ;
572+ } else if ( w > h ) {
573+ img . style . width = '' + pct + '%' ;
574+ } else {
575+ img . style . height = '' + pct + '%' ;
576+ }
529577 img . style . display = 'block' ;
530578 }
531579
532580 img . style . display = 'none' ;
533- img . style . width = '128px ' ;
534- img . style . height = '101px ' ;
581+ img . style . width = 'auto ' ;
582+ img . style . height = 'auto ' ;
535583 img . style . margin = 0 ;
536584 img . style . position = 'absolute' ;
537- img . style . top = '10px' ;
538- img . style . left = '176px' ;
585+ img . style . top = '50%' ;
586+ img . style . left = '50%' ;
587+ img . style . transform = 'translate(-50%, -50%)' ;
539588 img . src = 'data:image/png;base64,' + base64 ;
540589 div . appendChild ( img ) ;
541590
@@ -553,7 +602,7 @@ var Module = {
553602 div . appendChild ( p ) ;
554603
555604 p = document . createElement ( 'p' ) ;
556- p . innerHTML = 'Click here to begin , or press Ctrl+S<br/>in the code editor to the left.' ;
605+ p . innerHTML = 'Click the run button , or press Ctrl+S<br/>in the code editor to the left.' ;
557606 p . style [ 'font-family' ] = "monospace" ;
558607 p . style . textAlign = 'center' ;
559608 p . style . backgroundColor = 'rgb(40, 44, 52)' ;
@@ -568,25 +617,10 @@ var Module = {
568617 window . gtk . play = Module . clickToPlayListener ;
569618 } ,
570619 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- } ) ;
620+ // this prevents the game from running. We'll remove the dependency when
621+ // we have downloaded everything and the user has clicked-through to play.
622+ Module [ "addRunDependency" ] ( "dragonruby_init" ) ;
623+ prepareFilesystem ( ) ; // will get data, async.
590624 } ,
591625 postRun : [ ] ,
592626 print : ( function ( ) {
@@ -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