@@ -173,6 +173,11 @@ var Module = null;
173173 cfgr = NP2Loader ;
174174 get_files = get_np2_files ;
175175 }
176+ else if ( module && module . indexOf ( "ruffle-" ) === 0 ) {
177+ emulator_logo = images . ruffle ;
178+ cfgr = RuffleLoader ;
179+ get_files = get_ruffle_files ;
180+ }
176181 else if ( module && module . indexOf ( "xmil-" ) === 0 ) {
177182 emulator_logo = images . xmil ;
178183 cfgr = NP2Loader ;
@@ -253,7 +258,7 @@ var Module = null;
253258 } else if ( module && module . indexOf ( "pce-" ) === 0 ) {
254259 config_args . push ( cfgr . model ( modulecfg . driver ) ,
255260 cfgr . extraArgs ( modulecfg . extra_args ) ) ;
256- } else if ( module ) { // MAME
261+ } else if ( module && module . indexOf ( "ruffle-" ) !== 0 ) { // MAME
257262 config_args . push ( cfgr . driver ( modulecfg . driver ) ,
258263 cfgr . extraArgs ( modulecfg . extra_args ) ) ;
259264 if ( emulator_start_item ) {
@@ -398,6 +403,7 @@ var Module = null;
398403 files . push ( cfgr . mountFile ( '/' + filename ,
399404 cfgr . fetchFile ( title , url ) ) ) ;
400405 } ) ;
406+
401407 Object . keys ( peripherals ) . forEach ( function ( periph ) {
402408 files . push ( cfgr . peripheral ( periph , // we're not pushing a 'file' here,
403409 peripherals [ periph ] ) ) ; // but that's ok
@@ -439,29 +445,21 @@ var Module = null;
439445 get_other_emulator_config_url ( module ) ) ) ) ;
440446 return files ;
441447 }
442-
443- function get_ruffle_files ( cfgr , metadata , modulecfg , filelist ) {
444- var default_drive = 'c'
445- var files = [ ]
446- var meta = dict_from_xml ( metadata )
447-
448- games_files = files_with_ext_from_filelist ( filelist , meta . emulator_ext ) ;
449-
450- for ( let file in games_files ) {
451- if ( file ) {
452- var title = 'Downloading Game File' ;
453-
454- // Get IA Download Links
455- var url = ( filename . includes ( '/' ) ) ? get_zip_url ( file )
456- : get_zip_url ( file , get_item_name ( game ) )
457-
458- files . push (
459- cfgr . mountFile ( default_drive , cfgr . fetchFile ( title , url ) ) // Mount game file
460- )
461- break ; // only allow one .swf file to be loaded
462- }
463- }
464- return files ;
448+
449+ function get_ruffle_files ( cfgr , metadata , modulecfg , filelist ) {
450+ var files = [ ] ;
451+ var meta = dict_from_xml ( metadata ) ;
452+ var game_files = files_with_ext_from_filelist ( filelist , meta . emulator_ext ) ;
453+
454+ if ( game_files . length > 0 ) {
455+ var file = game_files [ 0 ] ; // only allow one .swf file to be loaded
456+ var title = 'Downloading Game File' ;
457+ var url = ( file . name . includes ( '/' ) ) ? get_zip_url ( file . name )
458+ : get_zip_url ( file . name , get_item_name ( game ) ) ;
459+ files . push ( cfgr . mountFile ( '/' + file . name , cfgr . fetchFile ( title , url ) ) ) ;
460+ files . push ( cfgr . swf_file_name ( '/' + file . name ) ) ;
461+ }
462+ return files ;
465463 }
466464
467465 function get_pce_files ( cfgr , metadata , modulecfg , filelist ) {
@@ -907,13 +905,17 @@ var Module = null;
907905 * RuffleLoader
908906 */
909907 function RuffleLoader ( ) {
910- var config = Array . prototype . reduce . call ( arguments , extend )
911- config . runner = RuffleRunner
912- return config
908+ var config = Array . prototype . reduce . call ( arguments , extend ) ;
909+ config . runner = RuffleRunner ;
910+ return config ;
913911 }
914-
912+
915913 RuffleLoader . __proto__ = BaseLoader ;
916914
915+ RuffleLoader . swf_file_name = function ( file_name ) {
916+ return { swf_file_name : file_name } ;
917+ } ;
918+
917919 /**
918920 * NP2Loader
919921 *
@@ -1270,36 +1272,36 @@ var Module = null;
12701272 /*
12711273 * RuffleRunner
12721274 */
1273- RuffleRunner = function ( canvas , game_data ) {
1274- // read game data from file system
1275- let gamedata = game_data . fs . readFileSync ( "/c" , null , flag_r )
1276- this . ready = { }
1277-
1278- window . RufflePlayer = window . RufflePlayer || { } ;
1279- let ruffle = window . RufflePlayer . newest ( ) ;
1280- let player = ruffle . create_player ( ) ;
1281-
1282- // copy atributes of canvas to player div
1283- for ( let el of canvas . attributes ) {
1284- player . setAttribute ( el . localName , el . nodeValue )
1285- }
1275+ function RuffleRunner ( canvas , game_data ) {
1276+ // read game data from file system
1277+ let gamedata = game_data . fs . readFileSync ( game_data . swf_file_name , null , flag_r ) ;
1278+ this . ready = null ;
1279+
1280+ window . RufflePlayer = window . RufflePlayer || { } ;
1281+ let ruffle = RufflePlayer . newest ( ) ;
1282+ let player = ruffle . create_player ( ) ;
1283+
1284+ // copy atributes of canvas to player div
1285+ for ( let el of canvas . attributes ) {
1286+ player . setAttribute ( el . localName , el . nodeValue ) ;
1287+ }
12861288
1287- canvas . parentElement . replaceChild ( player , canvas ) ;
1288- player . play_swf_data ( gamedata ) . then ( ( ) => {
1289- this . ready ( ) ; // clear screen
1290- player . play_button_clicked ( ) ; // autoplay
1291- } )
1292- }
1289+ canvas . parentElement . replaceChild ( player , canvas ) ;
1290+ player . play_swf_data ( gamedata ) . then ( ( ) => {
1291+ this . ready ( ) ; // clear screen
1292+ player . play_button_clicked ( ) ; // autoplay
1293+ } ) ;
1294+ }
12931295
1294- RuffleRunner . prototype . onReset = function ( func ) {
1295- }
1296+ RuffleRunner . prototype . onReset = function ( func ) {
1297+ } ;
12961298
1297- RuffleRunner . prototype . start = function ( func ) {
1298- }
1299+ RuffleRunner . prototype . start = function ( func ) {
1300+ } ;
12991301
1300- RuffleRunner . prototype . onStarted = function ( func ) {
1301- this . ready = func ;
1302- }
1302+ RuffleRunner . prototype . onStarted = function ( func ) {
1303+ this . ready = func ;
1304+ } ;
13031305
13041306 /**
13051307 * Emulator
@@ -2177,3 +2179,7 @@ var Module = null;
21772179// legacy
21782180var JSMESS = JSMESS || { } ;
21792181JSMESS . ready = function ( f ) { f ( ) ; } ;
2182+
2183+ // Local Variables:
2184+ // js-indent-level: 2
2185+ // End:
0 commit comments