Our game utilizes TypeScript, Pixi.js, VSCode, and ESLint.
We maintain a dictionary of image files as follows:
export function getAllImages(): {name: string, extension: string}[] {
return [
{name: 'tile_lumber', extension: '.svg'},
{name: 'tile_brick', extension: '.svg'},
....
]
}
The images are loaded using the following method:
export function loadImages() {
for(const img of getAllImages()) {
PIXI.Loader.shared.add(img.name, getImagePath(img.name + img.extension), { crossOrigin: true })
}
PIXI.Loader.shared
.on('progress', loadProgressHandler)
.load(assetsFinishedLoading)
}
To retrieve an image for a player, we use the following code structure:
export function getBannerForPlayer(playerColor: PlayerColors): PIXI.Texture {
switch(playerColor) {
case PlayerColors.Bronze: return PIXI.Loader.shared.resources.banner_bronze.texture
case PlayerColors.Silver: return PIXI.Loader.shared.resources.banner_silver.texture
case PlayerColors.Gold: return PIXI.Loader.shared.resources.banner_goldf.texture
....
}
}
An oversight in our code has led to a bug where banner_goldf
should actually be banner_gold
. Despite this error, the compiler does not flag it as incorrect. How can we ensure that such errors are caught during development?