Deploying to built from @ 2f50155ad7 🚀

This commit is contained in:
pulsejet 2020-10-19 22:57:35 +00:00
parent 2c8df35ec7
commit ba28fbffbd
6 changed files with 893 additions and 247 deletions

View file

@ -18,3 +18,79 @@ function _base64ToBytes(base64) {
}
return bytes;
}
// Canvas used for image generation
var generationCanvas = document.createElement('canvas')
window.loadFileAsync = function(fullPath, bitmap, callback) {
// noop
callback = callback || (() => {});
// Make cache object
if (!window.fileAsyncCache) window.fileAsyncCache = {};
// Check if already loaded
if (window.fileAsyncCache.hasOwnProperty(fullPath)) return callback();
// Show spinner
if (!bitmap && window.setBusy) window.setBusy();
// Get mapping key
const mappingKey = fullPath.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "");
const mappingValue = mapping[mappingKey];
// Check if this is a folder
if (!mappingValue || mappingValue.endsWith("h=")) {
console.error("Skipping loading", fullPath, mappingValue);
return callback();
}
// Get target URL
const iurl = "gameasync/" + mappingValue;
// Get path and filename
const path = "/game/" + mappingValue.substring(0, mappingValue.lastIndexOf("/"));
const filename = mappingValue.substring(mappingValue.lastIndexOf("/") + 1).split("?")[0];
// Main loading function
const load = (cb1) => {
getLazyAsset(iurl, filename, (data) => {
FS.createPreloadedFile(path, filename, new Uint8Array(data), true, true, function() {
window.fileAsyncCache[fullPath] = 1;
if (!bitmap && window.setNotBusy) window.setNotBusy();
if (window.fileLoadedAsync) window.fileLoadedAsync(fullPath);
callback();
if (cb1) cb1();
}, console.error, false, false, () => {
try { FS.unlink(path + "/" + filename); } catch (err) {}
});
});
}
// Show progress if doing it synchronously only
if (bitmap && bitmapSizeMapping[mappingKey]) {
// Get image
const sm = bitmapSizeMapping[mappingKey];
generationCanvas.width = sm[0];
generationCanvas.height = sm[1];
// Create dummy from data uri
FS.createPreloadedFile(path, filename, generationCanvas.toDataURL(), true, true, function() {
// Return control to C++
callback(); callback = () => {};
// Lazy load and refresh
load(() => {
const reloadBitmap = Module.cwrap('reloadBitmap', 'number', ['number'])
reloadBitmap(bitmap);
});
}, console.error, false, false, () => {
try { FS.unlink(path + "/" + filename); } catch (err) {}
});
} else {
if (bitmap) {
console.warn('No sizemap for image', mappingKey);
}
load();
}
}