Add initial data preload

This commit is contained in:
Varun Patil 2020-10-20 04:15:24 +05:30
parent 0fa7a4e687
commit 2f50155ad7
1 changed files with 115 additions and 94 deletions

View File

@ -270,6 +270,16 @@
console.error("An error occured!") console.error("An error occured!")
}; };
function preloadList(jsonArray) {
jsonArray.forEach((f) => {
const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")];
if (!url) return;
// Preload the asset
fetch('gameasync/' + url).then().catch();
});
}
window.fileLoadedAsync = function(file) { window.fileLoadedAsync = function(file) {
document.title = wTitle; document.title = wTitle;
@ -281,13 +291,7 @@
}) })
.then(function(jsonResponse) { .then(function(jsonResponse) {
setTimeout(() => { setTimeout(() => {
jsonResponse.forEach((f) => { preloadList(jsonResponse);
const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")];
if (!url) return;
// Preload the asset
fetch('gameasync/' + url).then().catch();
});
}, 200); }, 200);
}); });
}; };
@ -343,9 +347,27 @@
} }
document.title = wTitle; document.title = wTitle;
</script>
<script> // Load important files
preloadList([
'rgss.rb',
'data/scripts',
'data/actors',
'data/classes',
'data/skills',
'data/items',
'data/weapons',
'data/armors',
'data/enemies',
'data/troops',
'data/states',
'data/animations',
'data/tilesets',
'data/commonevents',
'data/system',
'data/mapinfos',
]);
// Load wasm then initialize // Load wasm then initialize
setTimeout(() => { setTimeout(() => {
getLazyAsset('mkxp.wasm', 'Game engine', () => { getLazyAsset('mkxp.wasm', 'Game engine', () => {
@ -353,7 +375,7 @@
s.setAttribute('src', 'mkxp.js'); s.setAttribute('src', 'mkxp.js');
document.body.appendChild(s); document.body.appendChild(s);
}); });
}, 500); }, 200);
function simulateKeyEvent(eventType, keyCode, charCode) { function simulateKeyEvent(eventType, keyCode, charCode) {
var e = document.createEventObject ? document.createEventObject() : document.createEvent("Events"); var e = document.createEventObject ? document.createEventObject() : document.createEvent("Events");
@ -454,7 +476,6 @@
window.addEventListener('resize', resize); window.addEventListener('resize', resize);
resize(); resize();
</script> </script>
<!-- {{{ SCRIPT }}} --> <!-- {{{ SCRIPT }}} -->