package studio.junk.jam.coloritum.entities.systems;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.gdx.graphics.g2d.Sprite;

import studio.junk.jam.coloritum.entities.components.Animated;
import studio.junk.jam.coloritum.entities.components.TilePosition;

public class AnimationRender extends TextureRender {

	@SuppressWarnings("unchecked")
	public static final Family family = Family.all(Animated.class, TilePosition.class).get();

	public AnimationRender() {
		super(family);
	}

	@Override
	protected void processEntity(Entity entity, float deltaTime) {
		TilePosition pos = TilePosition.mapper.get(entity);
		Animated animated = Animated.mapper.get(entity);

		Sprite s = new Sprite(animated.anim.getKeyFrame(animated.stateTime));
		s.setPosition(pos.position.x, pos.position.y);
		s.setSize(1, 1);

		render(entity, s);

		animated.stateTime += deltaTime;
	}
}
