package com.custardgames.hotel.entities.ecs.systems;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.physics.box2d.Body;
import com.custardgames.hotel.entities.ecs.components.Box2dBodyComponent;
import com.custardgames.hotel.entities.ecs.components.ObjectDataComponent;

public class ObjectMovementSystem extends EntityProcessingSystem
{

	@Mapper
	ComponentMapper<Box2dBodyComponent> bodyComponents;
	@Mapper
	ComponentMapper<ObjectDataComponent> objectDataComponents;

	@SuppressWarnings("unchecked")
	public ObjectMovementSystem()
	{
		super(Aspect.getAspectForAll(Box2dBodyComponent.class, ObjectDataComponent.class));

	}

	@Override
	protected void process(Entity e)
	{
		Body body = bodyComponents.get(e).getBody();
		ObjectDataComponent objectDataComponent = objectDataComponents.get(e);

		if (objectDataComponent.isTaken())
		{
			Entity player = objectDataComponent.getPlayer();

			if (player != null)
			{
				Body playerBody = player.getComponent(Box2dBodyComponent.class).getBody();

				body.setTransform(playerBody.getPosition().x, playerBody.getPosition().y + 1.5f, 0);
			}
		}

	}

}
