All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.artemis.EntityTransmuterFactory Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.artemis;

import com.artemis.utils.BitVector;

/**
 * Builder for {@link EntityTransmuter}.
 * @see EntityEdit for a list of alternate ways to alter composition and access components.
 */
public final class EntityTransmuterFactory {
	private final ComponentTypeFactory types;
	private final BitVector additions;
	private final BitVector removals;
	private final World world;

	/** Prepare new builder. */
	public EntityTransmuterFactory(World world) {
		this.world = world;
		types = world.getComponentManager().typeFactory;
		additions = new BitVector();
		removals = new BitVector();
	}

	/** Component to add upon transmutation. Overwrites and retires if component exists! */
	public EntityTransmuterFactory add(Class component) {
		int index = types.getIndexFor(component);
		additions.set(index, true);
		removals.set(index, false);
		return this;
	}

	/** Component to remove upon transmutation. Does nothing if missing. */
	public EntityTransmuterFactory remove(Class component) {
		int index = types.getIndexFor(component);
		additions.set(index, false);
		removals.set(index, true);
		return this;
	}

	/** Build instance */
	public EntityTransmuter build() {
		return new EntityTransmuter(world, additions, removals);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy