MCPcopy Create free account
hub / github.com/melonjs/melonJS / loadWithFallback

Function loadWithFallback

packages/melonjs/tests/imageFallback.node-test.js:112–130  ·  view source on GitHub ↗

* Mirrors the fallback chain logic from preloadImage in image.js: * try each source sequentially, stop at the first that succeeds.

(
	name,
	sources,
	fileServer,
	supportedFormats,
	imgCache,
)

Source from the content-addressed store, hash-verified

110 * try each source sequentially, stop at the first that succeeds.
111 */
112function loadWithFallback(
113 name,
114 sources,
115 fileServer,
116 supportedFormats,
117 imgCache,
118) {
119 let chain = Promise.reject();
120 const triedSources = [];
121 for (const src of sources) {
122 chain = chain.catch(() => {
123 triedSources.push(src);
124 return tryLoadSource(src, name, fileServer, supportedFormats, imgCache);
125 });
126 }
127 return chain.then(() => {
128 return triedSources;
129 });
130}
131
132// ── synthetic compressed texture builders ───────────────────────────────────
133

Callers 1

Calls 2

tryLoadSourceFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected