/**
 * 
 */
package studio.junk.jam.coloritum.entities.components;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.math.Vector2;

import studio.junk.jam.coloritum.GameState;

/**
 * @author held03
 */
public class TilePosition implements Component {
	public static final ComponentMapper<TilePosition> mapper = ComponentMapper.getFor(TilePosition.class);

	public final Vector2 position;

	/**
	 * 
	 */
	public TilePosition(Vector2 position) {
		this.position = position;
	}

	@SuppressWarnings("unchecked")
	public static Entity getEntityAt(int x, int y) {
		ImmutableArray<Entity> entities = GameState.state.engine.getEntitiesFor(Family.all(TilePosition.class).get());
		for (Entity e : entities) {
			Vector2 p = mapper.get(e).position;
			if (x >= p.x && x < p.x + 1 && y >= p.y && y < p.y + 1) {
				return e;
			}
		}
		return null;
	}
}
