// the modulo of 32
int tileGroupIdx = index / 32;
int tileIdx = index % 32;
// fetch the land tile
LandTile tile = this.tileGroups[tileGroupIdx].getTiles()[tileIdx];
TexIdx textureIndex = this.texIdxs[(int) tile.getTextureId()];
// fetch the texture object
Texture texture = null;
try {
texture = this.textureCache.get(textureIndex.getStart());
} catch (CacheItemNotFoundException e) {
// not found in cache, so load
texture = textureReader.read(textureIndex);
// put texture into cache
this.textureCache.put(textureIndex.getStart(), texture);
}
// and the image of the texture
Image textureImg = null;
if (texture != null) {
textureImg = texture.getImage();
} else {
// create dummy image
textureImg = graphicsConfiguration.createCompatibleImage(64, 64,
Transparency.TRANSLUCENT);
Graphics g = textureImg.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, 64, 64);
g.setColor(Color.WHITE);
g.drawString("N/A", 22, 35);
}
// create bounds object (note: x and y is not set here)
Rectangle bounds = new Rectangle(0, 0, 64, 64);
// set drawable tile properties
drawableTile.setAltitude(mapCell.getAltitude());
drawableTile.setFlags(tile.getFlags());
drawableTile.setName(tile.getName());
drawableTile.setTexture(textureImg);
drawableTile.setRelativeBounds(bounds);
return drawableTile;
}