// Entity2DView
//
@Override
protected void buildRepresentation(IEntity entity) {
final SpriteStore store = SpriteStore.get();
Sprite sprite;
if (entity.getType().equals("useable_entity")) {
if (entity.getName() == null) {
sprite = store.getSprite(translate("signs/transparent"));
} else {
sprite = store.getSprite(translate("useable/" + getClassResourcePath() + "/" + entity.getName()));
}
} else {
// compatiblity with 0.86 server
sprite = store.getSprite(translate("useable/source/" + entity.getType()));
}
/*
* Entities are [currently] always 1x1. Extra columns are animation.
* Extra rows are ignored.
*/
final int imageWidth = sprite.getWidth();
final int width = Math.max((int) entity.getWidth(), 1);
final int height = Math.max((int) entity.getHeight(), 1);
int frames = imageWidth / IGameScreen.SIZE_UNIT_PIXELS / width;
// Just use the normal sprite if there are no animation frames
int state = ((UseableEntity) entity).getState();
if (frames > 1) {
sprite = store.getAnimatedSprite(sprite,
0, state * IGameScreen.SIZE_UNIT_PIXELS * height,
imageWidth / IGameScreen.SIZE_UNIT_PIXELS / width,
IGameScreen.SIZE_UNIT_PIXELS * width,
IGameScreen.SIZE_UNIT_PIXELS * height,
100);
} else {
sprite = store.getTile(sprite,
0, state * IGameScreen.SIZE_UNIT_PIXELS * height,
IGameScreen.SIZE_UNIT_PIXELS * width,
IGameScreen.SIZE_UNIT_PIXELS * height);
}