Merge pull request #5 from kobolol/codex/fix-drawimage-typeerror-in-playground
Fix snake overlay image lookup for case-sensitive asset paths
This commit is contained in:
@@ -8,7 +8,15 @@ class Overlay{
|
|||||||
this.src = imgSrc;
|
this.src = imgSrc;
|
||||||
|
|
||||||
if(!this.src) return;
|
if(!this.src) return;
|
||||||
this.image = this.tileLoader.tileMap.get(this.src);
|
const image = this.tileLoader.getImage(this.src);
|
||||||
|
|
||||||
|
if(!image){
|
||||||
|
this.src = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.src = this.tileLoader.resolveSrc(this.src);
|
||||||
|
this.image = image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,26 @@ class TileLoader{
|
|||||||
this.tileMap.set(src, img);
|
this.tileMap.set(src, img);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveSrc(src){
|
||||||
|
if(this.tileMap.has(src)) return src;
|
||||||
|
|
||||||
|
const [category, color, ...rest] = src.split("/");
|
||||||
|
if(category !== "Snakes" || rest.length === 0) return src;
|
||||||
|
|
||||||
|
const mappedColor = SNAKE_COLOR_ASSET_MAP[color] ?? color;
|
||||||
|
const normalizedSrc = [category, mappedColor, ...rest].join("/");
|
||||||
|
|
||||||
|
if(this.tileMap.has(normalizedSrc)) return normalizedSrc;
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
|
||||||
|
getImage(src){
|
||||||
|
const resolvedSrc = this.resolveSrc(src);
|
||||||
|
|
||||||
|
return this.tileMap.get(resolvedSrc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TileLoader;
|
export default TileLoader;
|
||||||
Reference in New Issue
Block a user