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

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.gdx.math.Vector2;

import studio.junk.jam.coloritum.entities.components.Collision;
import studio.junk.jam.coloritum.entities.components.SpriteComponent;
import studio.junk.jam.coloritum.entities.components.TilePosition;
import studio.junk.jam.coloritum.screen.InGame;

public class SpriteRender extends TextureRender {

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

	public SpriteRender() {
		super(family);
	}

	@Override
	protected void processEntity(Entity entity, float deltaTime) {
		SpriteComponent sc = SpriteComponent.mapper.get(entity);

		if (TilePosition.mapper.has(entity)) {
			TilePosition pos = TilePosition.mapper.get(entity);

			sc.sprite.setPosition(pos.position.x, pos.position.y);
		} else {
			Collision col = Collision.mapper.get(entity);

			Vector2 v = col.body.getWorldCenter();

			sc.sprite.setPosition(v.x - 0.5f, v.y - 0.5f);

		}


		sc.sprite.draw(InGame.currentGame.batch);


	}

}
