/**
 * 
 */
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 box2dLight.Light;
import studio.junk.jam.coloritum.entities.Pigment;

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

	public Pigment pigment;

	public PigmentComponent(Pigment pigment) {
		this.pigment = pigment;
	}

	public static void setPigment(Entity e, Pigment p) {
		if (!mapper.has(e)) {
			throw new IllegalArgumentException("Entity e (" + e.toString() + ") has to have a pigment!");
		}

		PigmentComponent pc = mapper.get(e);

		pc.pigment = p;

		if (Lights.mapper.has(e)) {
			for (Light l : Lights.mapper.get(e).lights) {
				l.setColor(p.color);
			}
		}
	}
}
