streaming assets

This commit is contained in:
David Allemang
2026-07-06 14:02:29 -04:00
parent 7f946723ce
commit 0a32b46e93
6 changed files with 160 additions and 56 deletions

View File

@@ -38,6 +38,13 @@ export class TextureHandler {
this.uvmap.set(id, uvData);
this.pendingDraws.set(id, {x: currentX, y: currentY});
this.ctx.fillStyle = '#00000066';
this.ctx.fillRect(currentX, currentY, this.cellSize, this.cellSize);
}
getFallback(id) {
return this.uvmap.get(id); // UVs map to the black silhouette!
}
async process(cache, id, url) {
@@ -47,31 +54,31 @@ export class TextureHandler {
const drawMissing = () => {
const half = this.cellSize / 2;
this.ctx.fillStyle = '#ff00ff'; // Magenta
this.ctx.fillStyle = '#33333366'; // Gray
this.ctx.fillRect(pos.x, pos.y, half, half);
this.ctx.fillRect(pos.x + half, pos.y + half, half, half);
this.ctx.fillStyle = '#000000'; // Black
this.ctx.fillStyle = '#00000066'; // Black
this.ctx.fillRect(pos.x + half, pos.y, half, half);
this.ctx.fillRect(pos.x, pos.y + half, half, half);
};
if (id === ':missing') {
drawMissing();
return this.uvmap.get(id);
}
drawMissing();
try {
const img = await new Promise((resolve, reject) => {
const i = new Image();
i.crossOrigin = 'anonymous';
i.onload = () => resolve(i);
i.onerror = () => reject(new Error(`Image load failed`));
i.src = url + '.png';
});
this.ctx.drawImage(img, pos.x, pos.y, this.cellSize, this.cellSize);
} catch (e) {
console.warn(`Missing texture: ${id}`);
drawMissing();
if (id !== ':missing') {
try {
const img = await new Promise((resolve, reject) => {
const i = new Image();
i.crossOrigin = 'anonymous';
i.onload = () => resolve(i);
i.onerror = () => reject(new Error(`Image load failed`));
i.src = url + '.png';
});
// await new Promise(r => setTimeout(r, 2000))
this.ctx.clearRect(pos.x, pos.y, this.cellSize, this.cellSize);
this.ctx.drawImage(img, pos.x, pos.y, this.cellSize, this.cellSize);
} catch (e) {
console.warn(`Missing texture: ${id}`);
}
}
return this.uvmap.get(id);