1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-16 02:59:10 +00:00

Add: [Emscripten] Support for bootstrapping

This commit is contained in:
glx22
2023-07-06 18:20:33 +02:00
committed by Loïc Guilloux
parent 3d1c4a8589
commit 4eddec9e79
4 changed files with 120 additions and 29 deletions

View File

@@ -30,24 +30,6 @@ Module.preRun.push(function() {
Module.addRunDependency('syncfs');
FS.syncfs(true, function (err) {
/* FS.mkdir() tends to fail if parent folders do not exist. */
if (!FS.analyzePath(content_download_dir).exists) {
FS.mkdir(content_download_dir);
}
if (!FS.analyzePath(content_download_dir + '/baseset').exists) {
FS.mkdir(content_download_dir + '/baseset');
}
/* Check if the OpenGFX baseset is already downloaded. */
if (!FS.analyzePath(content_download_dir + '/baseset/opengfx-0.6.0.tar').exists) {
window.openttd_downloaded_opengfx = true;
FS.createPreloadedFile(content_download_dir + '/baseset', 'opengfx-0.6.0.tar', 'https://binaries.openttd.org/installer/emscripten/opengfx-0.6.0.tar', true, true);
} else {
/* Fake dependency increase, so the counter is stable. */
Module.addRunDependency('opengfx');
Module.removeRunDependency('opengfx');
}
Module.removeRunDependency('syncfs');
});
@@ -74,6 +56,23 @@ Module.preRun.push(function() {
window.openttd_syncfs(Module.onAbort);
}
window.openttd_bootstrap = function(current, total) {
Module.onBootstrap(current, total);
}
window.openttd_bootstrap_failed = function() {
Module.onBootstrapFailed();
}
window.openttd_bootstrap_reload = function() {
window.openttd_syncfs(function() {
Module.onBootstrapReload();
setTimeout(function() {
location.reload();
}, 1000);
});
}
window.openttd_server_list = function() {
add_server = Module.cwrap("em_openttd_add_server", null, ["string"]);
@@ -125,11 +124,3 @@ Module.preRun.push(function() {
return ret;
}
});
Module.postRun.push(function() {
/* Check if we downloaded OpenGFX; if so, sync the virtual FS back to the
* IDBFS so OpenGFX is stored persistent. */
if (window['openttd_downloaded_opengfx']) {
FS.syncfs(false, function (err) { });
}
});

View File

@@ -75,7 +75,6 @@
}
#message {
color: #101010;
height: 54px;
padding: 4px 4px;
}
@@ -144,6 +143,8 @@
})(),
setStatus: function(text) {
if (document.getElementById("canvas").style.display == "none") return;
var m = text.match(/^([^(]+)\((\d+(\.\d+)?)\/(\d+)\)$/);
if (m) {
@@ -171,6 +172,27 @@
document.getElementById("message").innerHTML = "Preparing game ...";
},
onBootstrap: function(current, total) {
document.getElementById("canvas").style.display = "none";
document.getElementById("title").innerHTML = "Missing base graphics";
document.getElementById("message").innerHTML = "OpenTTD is downloading base graphics.<br/><br/>" + current + " / " + total + " bytes downloaded.";
},
onBootstrapFailed: function(current, total) {
document.getElementById("canvas").style.display = "none";
document.getElementById("title").innerHTML = "Missing base graphics";
document.getElementById("message").innerHTML = "Failed to download base graphics.<br/>The game cannot start without base graphics.<br/><br/>Please check your Internet connection and/or the console log.<br/>Reload your browser to try again.";
},
onBootstrapReload: function() {
document.getElementById("canvas").style.display = "none";
document.getElementById("title").innerHTML = "Missing base graphics";
document.getElementById("message").innerHTML = "Downloading base graphics done.<br/><br/>Your browser will reload to start the game.";
},
onExit: function() {
document.getElementById("canvas").style.display = "none";