mirror of
https://github.com/isledecomp/isle.pizza.git
synced 2026-03-01 06:17:38 +00:00
Cleanup: parallel fetching, error recovery, dead code removal
- Fetch .tex files in parallel with Promise.all instead of sequentially - Clear cached IndexedDB promise on rejection so subsequent calls retry - Remove unused textureOrder array from Act1State parser - Unify selectDefault/applyCustom into single applyTexture function - Remove redundant squareTexture call on already-squared wdbTexture
This commit is contained in:
parent
8adeb9fed6
commit
4f9740619b
@ -325,19 +325,18 @@ export class SaveGameParser {
|
||||
|
||||
// Conditional textures based on which planes have names
|
||||
const textures = new Map();
|
||||
const textureOrder = [];
|
||||
|
||||
if (planes[3].nameLength > 0) {
|
||||
for (let i = 0; i < 3; i++) textureOrder.push(this.readAct1Texture(textures));
|
||||
for (let i = 0; i < 3; i++) this.readAct1Texture(textures);
|
||||
}
|
||||
if (planes[4].nameLength > 0) {
|
||||
for (let i = 0; i < 2; i++) textureOrder.push(this.readAct1Texture(textures));
|
||||
for (let i = 0; i < 2; i++) this.readAct1Texture(textures);
|
||||
}
|
||||
if (planes[5].nameLength > 0) {
|
||||
textureOrder.push(this.readAct1Texture(textures));
|
||||
this.readAct1Texture(textures);
|
||||
}
|
||||
if (planes[6].nameLength > 0) {
|
||||
for (let i = 0; i < 3; i++) textureOrder.push(this.readAct1Texture(textures));
|
||||
for (let i = 0; i < 3; i++) this.readAct1Texture(textures);
|
||||
}
|
||||
|
||||
// Final fields
|
||||
@ -347,7 +346,6 @@ export class SaveGameParser {
|
||||
this.parsed.act1State = {
|
||||
planes,
|
||||
textures,
|
||||
textureOrder,
|
||||
startOffset,
|
||||
endOffset: this.reader.tell(),
|
||||
cptClickDialogueNextIndex,
|
||||
|
||||
@ -21,6 +21,9 @@ function openDB() {
|
||||
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error);
|
||||
}).catch((err) => {
|
||||
dbPromise = null;
|
||||
throw err;
|
||||
});
|
||||
|
||||
return dbPromise;
|
||||
|
||||
@ -70,13 +70,13 @@
|
||||
return canvas.toDataURL();
|
||||
}
|
||||
|
||||
function selectDefault(tex) {
|
||||
function applyTexture(tex) {
|
||||
onSelect({
|
||||
width: tex.width,
|
||||
height: tex.height,
|
||||
palette: tex.palette,
|
||||
pixels: tex.pixels,
|
||||
paletteSize: tex.palette.length
|
||||
paletteSize: tex.paletteSize || tex.palette.length
|
||||
});
|
||||
}
|
||||
|
||||
@ -86,14 +86,7 @@
|
||||
|
||||
function applyCustom() {
|
||||
const tex = customTextures.find(t => t.id === selectedCustomId);
|
||||
if (!tex) return;
|
||||
onSelect({
|
||||
width: tex.width,
|
||||
height: tex.height,
|
||||
palette: tex.palette,
|
||||
pixels: tex.pixels,
|
||||
paletteSize: tex.paletteSize
|
||||
});
|
||||
if (tex) applyTexture(tex);
|
||||
}
|
||||
|
||||
function handleUploadClick() {
|
||||
@ -194,7 +187,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="texture-thumb"
|
||||
onclick={() => selectDefault(tex)}
|
||||
onclick={() => applyTexture(tex)}
|
||||
title={tex.name}
|
||||
>
|
||||
<img src={tex.dataUrl} alt={tex.name} />
|
||||
|
||||
@ -223,19 +223,19 @@
|
||||
}
|
||||
|
||||
async function preloadDefaultTextures(info) {
|
||||
const loaded = [];
|
||||
for (const texFile of info.texFiles) {
|
||||
const results = await Promise.all(info.texFiles.map(async (texFile) => {
|
||||
const response = await fetch(`/${texFile}.tex`);
|
||||
if (!response.ok) continue;
|
||||
if (!response.ok) return null;
|
||||
const buffer = await response.arrayBuffer();
|
||||
const parsed = parseTex(buffer);
|
||||
if (parsed.textures.length > 0) {
|
||||
loaded.push({ name: texFile, ...parsed.textures[0] });
|
||||
}
|
||||
return { name: texFile, ...parsed.textures[0] };
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
// Only apply if textureInfo hasn't changed since we started
|
||||
if (textureInfo === info) {
|
||||
preloadedDefaults = loaded;
|
||||
preloadedDefaults = results.filter(Boolean);
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,16 +275,16 @@
|
||||
}
|
||||
};
|
||||
|
||||
// Reset texture to WDB default (equivalent to WriteDefaultTexture in the game)
|
||||
// Reset texture to WDB default (equivalent to WriteDefaultTexture in the game).
|
||||
// wdbTexture is already squared when cached in loadCurrentPart().
|
||||
if (canEditTexture && wdbTexture && renderer) {
|
||||
const texKey = textureInfo.textureName.toLowerCase();
|
||||
const saveData = squareTexture(wdbTexture);
|
||||
|
||||
renderer.updateTexture(texKey, saveData);
|
||||
renderer.updateTexture(texKey, wdbTexture);
|
||||
|
||||
update.texture = {
|
||||
textureName: textureInfo.textureName,
|
||||
textureData: saveData
|
||||
textureData: wdbTexture
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user