Skip to content

Commit

Permalink
Update Ruffle support
Browse files Browse the repository at this point in the history
  • Loading branch information
n0samu committed Jun 17, 2023
1 parent d6547c5 commit b279c62
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
14 changes: 7 additions & 7 deletions example_ruffle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Waning this emulator is still a work in progress, and not 100% of apis have been implemented
so don't expect compatibility with all .swf files.
* Download latest nightly build (ruffle_web_latest.zip) from
http://ruffle-rs.s3-website-us-west-1.amazonaws.com/web/
* Download latest nightly selfhosted build from
https://ruffle.rs/#downloads
and extract to the emulators folder.
* in the examples folder save
Expand All @@ -20,21 +20,21 @@
</head>
<body>
<div id="container"></div>
<canvas id="canvas" style="width: 50%; height: 50%; display: block; margin: 0 auto;" width="756" height="391" moz-opaque=""></canvas>
<canvas id="canvas" style="width: 780px; height: 440px; display: block; margin: 0 auto;" moz-opaque=""></canvas>
</body>
<foot>
<script type="text/javascript" src="es6-promise.js"></script>
<script type="text/javascript" src="browserfs.min.js"></script>
<script type="text/javascript" src="loader.js"></script>
<script type="text/javascript">
const url = "/examples/end(www.albinoblacksheep.com).swf";
const file = url.slice(url.lastIndexOf("/"));
var emulator = new Emulator(
document.querySelector("#canvas"),
null,
new RuffleLoader(
RuffleLoader.emulatorJS("emulators/ruffle_web_latest/ruffle.js"),
RuffleLoader.mountFile("c", RuffleLoader.fetchFile(
"Game File",
"/examples/end(www.albinoblacksheep.com).swf")),
RuffleLoader.emulatorJS("emulators/ruffle/ruffle.js"),
RuffleLoader.mountFile(file, RuffleLoader.fetchFile("Game File", url)),
)
);
emulator.start({ waitAfterDownloading: true });
Expand Down
63 changes: 48 additions & 15 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ var Module = null;
} else if (module && module.indexOf("pce-") === 0) {
config_args.push(cfgr.model(modulecfg.driver),
cfgr.extraArgs(modulecfg.extra_args));
} else if (module && module.indexOf("ruffle-") !== 0) { // MAME
} else if (module && module.indexOf("ruffle-") === 0) {
modulecfg.config = modulecfg.config || {};
modulecfg.config.base = get_cors_url(game);
} else if (module) { // MAME
config_args.push(cfgr.driver(modulecfg.driver),
cfgr.extraArgs(modulecfg.extra_args));
if (emulator_start_item) {
Expand Down Expand Up @@ -454,6 +457,8 @@ var Module = null;
}

function get_ruffle_files(cfgr, metadata, modulecfg, filelist) {
window.RufflePlayer = window.RufflePlayer || {};
window.RufflePlayer.config = modulecfg.config;
var files = [];
var meta = dict_from_xml(metadata);
var game_files = files_with_ext_from_filelist(filelist, meta.emulator_ext);
Expand Down Expand Up @@ -615,37 +620,41 @@ var Module = null;

// NOTE: deliberately use cors.archive.org since this will 302 rewrite to iaXXXXX.us.archive.org/XX/items/...
// and need to keep that "artificial" extra domain-ish name to avoid CORS issues with IE/Safari (tracey@archive)
var get_cors_url = function(item, path) {
return '//cors.archive.org/cors/' + item + (path ? '/' + path : '');
}

var get_emulator_config_url = function (module) {
return '//cors.archive.org/cors/emularity_engine_v1/' + module + '.json';
return get_cors_url('emularity_engine_v1', module + '.json');
};

var get_other_emulator_config_url = function (module) {
return '//cors.archive.org/cors/emularity_config_v1/' + module + '.cfg';
return get_cors_url('emularity_config_v1', module + '.cfg');
};

var get_meta_url = function (game_path) {
var path = game_path.split('/');
return "//cors.archive.org/cors/"+ path[0] +"/"+ path[0] +"_meta.xml";
return get_cors_url(path[0], path[0] + "_meta.xml");
};

var get_files_url = function (game_path) {
var path = game_path.split('/');
return "//cors.archive.org/cors/"+ path[0] +"/"+ path[0] +"_files.xml";
return get_cors_url(path[0], path[0] +"_files.xml");
};

var get_zip_url = function (game_path, item_path) {
if (item_path) {
return "//cors.archive.org/cors/"+ item_path +"/"+ game_path;
return get_cors_url(item_path, game_path);
}
return "//cors.archive.org/cors/"+ game_path;
return get_cors_url(game_path);
};

var get_js_url = function (js_filename) {
return "//cors.archive.org/cors/emularity_engine_v1/"+ js_filename;
return get_cors_url('emularity_engine_v1', js_filename);
};

var get_bios_url = function (bios_filename) {
return "//cors.archive.org/cors/emularity_bios_v1/"+ bios_filename;
return get_cors_url('emularity_bios_v1', bios_filename);
};

function mountat (drive) {
Expand Down Expand Up @@ -1280,26 +1289,42 @@ var Module = null;
* RuffleRunner
*/
function RuffleRunner(canvas, game_data) {
if (!game_data.swf_file_name) {
let url = game_data.files[0].file.url;
game_data.swf_file_name = url.slice(url.lastIndexOf('/'));
}
// read game data from file system
let gamedata = game_data.fs.readFileSync(game_data.swf_file_name, null, flag_r);
this.ready = null;

window.RufflePlayer = window.RufflePlayer || {};
let ruffle = RufflePlayer.newest();
let player = ruffle.create_player();
let player = ruffle.createPlayer();
player.addEventListener('loadedmetadata', () => {
player.style.width = player.metadata.width + "px";
player.style.height = player.metadata.height + "px";
});
this._player = player;

// copy atributes of canvas to player div
for (let el of canvas.attributes){
player.setAttribute(el.localName, el.nodeValue);
}

canvas.parentElement.replaceChild(player, canvas);
player.play_swf_data(gamedata).then(() => {
this.ready(); // clear screen
player.play_button_clicked(); // autoplay
player.load({
data: gamedata,
swfFileName: game_data.swf_file_name.replace('/', ''),
splashScreen: false
}).then(() => {
this.ready(); // clear screen
});

}

RuffleRunner.prototype.requestFullScreen = function () {
this._player.enterFullscreen();
};

RuffleRunner.prototype.onReset = function (func) {
};

Expand All @@ -1310,6 +1335,14 @@ var Module = null;
this.ready = func;
};

RuffleRunner.prototype.mute = function() {
this._player.volume = 0;
}

RuffleRunner.prototype.unmute = function() {
this._player.volume = 1;
}

/**
* Emulator
*/
Expand Down Expand Up @@ -1859,7 +1892,7 @@ var Module = null;
splash.titleElt.style.textAlign = 'center';
splash.titleElt.style.font = "24px sans-serif";
}
splash.titleElt.textContent = " ";
splash.titleElt.textContent = " ";
splash.splashElt.appendChild(splash.titleElt);

var table = document.getElementById("emularity-progress-indicator");
Expand Down

0 comments on commit b279c62

Please sign in to comment.