Code intended to leverage imports in the load functions.

This commit is contained in:
Rezmason
2025-05-20 07:59:20 -07:00
parent f61a4e29c9
commit 658f07c6ab
4 changed files with 31 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ export const init = async (canvas) => {
];
const regl = createREGL({ canvas, pixelRatio: 1, extensions, optionalExtensions });
const cache = new Map();
const cache = new Map(inclusions);
const rain = { canvas, resize, doubleClick, cache, regl, resolution: 1 };
window.addEventListener("dblclick", doubleClick);

View File

@@ -59,7 +59,13 @@ const loadImage = (cache, regl, url, mipmap) => {
if (url != null) {
const data = new Image();
data.crossOrigin = "anonymous";
data.src = url;
let imageURL;
if (typeof cache.get(`import::${url}`) === "function") {
imageURL = (await cache.get(`import::${url}`)()).default;
} else {
imageURL = url;
}
data.src = imageURL;
await data.decode();
loaded = true;
if (mipmap) {
@@ -97,7 +103,13 @@ const loadText = (cache, url) => {
},
loaded: (async () => {
if (url != null) {
text = await (await fetch(url)).text();
let textURL;
if (typeof cache.get(`import::${url}`) === "function") {
textURL = (await cache.get(`import::${url}`)()).default;
} else {
textURL = url;
}
text = await (await fetch(textURL)).text();
loaded = true;
}
})(),