mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-19 22:02:57 +01:00
Load emscripten data via a ZIP file
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
0.4.22 (in development)
|
0.4.22 (in development)
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
- Change: [#23803] Lightning strikes and thunder happen at the same frequency independently of the game speed.
|
- Change: [#23803] Lightning strikes and thunder happen at the same frequency independently of the game speed.
|
||||||
|
- Change: [#24135] Compress Emscripten js/wasm files.
|
||||||
- Fix: [#21919] Non-recolourable cars still show colour picker.
|
- Fix: [#21919] Non-recolourable cars still show colour picker.
|
||||||
- Fix: [#23108] Missing pieces on Hypercoaster and Hyper-Twister, even with the ‘all drawable track pieces’ cheat enabled.
|
- Fix: [#23108] Missing pieces on Hypercoaster and Hyper-Twister, even with the ‘all drawable track pieces’ cheat enabled.
|
||||||
- Fix: [#24013] Failure to load a scenario preview image (minimap) could lead to an uncaught exception error message.
|
- Fix: [#24013] Failure to load a scenario preview image (minimap) could lead to an uncaught exception error message.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>OpenRCT2</title>
|
<title>OpenRCT2</title>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js" crossorigin=anonymous></script>
|
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js" crossorigin=anonymous></script>
|
||||||
<script src="openrct2.js"></script>
|
|
||||||
<style>
|
<style>
|
||||||
* { padding: 0; margin: 0; }
|
* { padding: 0; margin: 0; }
|
||||||
canvas {
|
canvas {
|
||||||
|
|||||||
@@ -12,12 +12,46 @@
|
|||||||
if (!window.SharedArrayBuffer)
|
if (!window.SharedArrayBuffer)
|
||||||
{
|
{
|
||||||
document.getElementById("loadingWebassembly").innerText = "Error! SharedArrayBuffer is not defined. This page required the CORP and COEP response headers.";
|
document.getElementById("loadingWebassembly").innerText = "Error! SharedArrayBuffer is not defined. This page required the CORP and COEP response headers.";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!window.WebAssembly)
|
if (!window.WebAssembly)
|
||||||
{
|
{
|
||||||
document.getElementById("loadingWebassembly").innerText = "Error! This page requires WebAssembly. Please upgrade your browser or enable WebAssembly support.";
|
document.getElementById("loadingWebassembly").innerText = "Error! This page requires WebAssembly. Please upgrade your browser or enable WebAssembly support.";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let assets;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
let req = await fetch("openrct2.zip");
|
||||||
|
if (!req.ok) {
|
||||||
|
throw new Error("Response is not ok!")
|
||||||
|
}
|
||||||
|
let data = await req.blob();
|
||||||
|
let zip = new JSZip();
|
||||||
|
let contents = await zip.loadAsync(data);
|
||||||
|
assets = {
|
||||||
|
js: URL.createObjectURL(new Blob([await zip.file("openrct2.js").async("uint8array")], {type: 'application/json'})),
|
||||||
|
wasm: URL.createObjectURL(new Blob([await zip.file("openrct2.wasm").async("uint8array")], {type: 'application/wasm'}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e)
|
||||||
|
{
|
||||||
|
assets = null;
|
||||||
|
console.warn("Failed to fetch openrct2.zip. Will pull not-compressed files", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
await new Promise(resolve => {
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.src = assets === null ? "openrct2.js" : assets.js;
|
||||||
|
script.addEventListener("load", resolve);
|
||||||
|
script.addEventListener("error", (e) => {
|
||||||
|
document.getElementById("loadingWebassembly").innerText = "Error loading openrct2.js!";
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
|
document.body.appendChild(script);
|
||||||
|
})
|
||||||
|
|
||||||
window.Module = await window.OPENRCT2_WEB(
|
window.Module = await window.OPENRCT2_WEB(
|
||||||
{
|
{
|
||||||
noInitialRun: true,
|
noInitialRun: true,
|
||||||
@@ -37,6 +71,10 @@
|
|||||||
monitorRunDependencies: () => {},
|
monitorRunDependencies: () => {},
|
||||||
locateFile: function(fileName)
|
locateFile: function(fileName)
|
||||||
{
|
{
|
||||||
|
if (assets !== null && fileName === "openrct2.wasm")
|
||||||
|
{
|
||||||
|
return assets.wasm;
|
||||||
|
}
|
||||||
console.log("loading", fileName);
|
console.log("loading", fileName);
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,3 +34,4 @@ mkdir -p www/
|
|||||||
cd www/
|
cd www/
|
||||||
cp -r ../openrct2.* ./
|
cp -r ../openrct2.* ./
|
||||||
cp -r ../../emscripten/static/* ./
|
cp -r ../../emscripten/static/* ./
|
||||||
|
zip -r openrct2.zip ../openrct2.*
|
||||||
|
|||||||
Reference in New Issue
Block a user