diff --git a/frontend/game/scripts/Game/Elements/Overlay.js b/frontend/game/scripts/Game/Elements/Overlay.js index 4037672..6a013a0 100644 --- a/frontend/game/scripts/Game/Elements/Overlay.js +++ b/frontend/game/scripts/Game/Elements/Overlay.js @@ -8,7 +8,15 @@ class Overlay{ this.src = imgSrc; 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; } } diff --git a/frontend/game/scripts/Game/Elements/TileLoader.js b/frontend/game/scripts/Game/Elements/TileLoader.js index c607e9e..78a855e 100644 --- a/frontend/game/scripts/Game/Elements/TileLoader.js +++ b/frontend/game/scripts/Game/Elements/TileLoader.js @@ -32,6 +32,26 @@ class TileLoader{ 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; \ No newline at end of file