net.mostlyoriginal.api.operation.basic.SetOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of contrib-plugin-operations Show documentation
Show all versions of contrib-plugin-operations Show documentation
Scheduled operations on entities and components.
package net.mostlyoriginal.api.operation.basic;
import com.artemis.Component;
import com.artemis.Entity;
import com.artemis.utils.reflect.ClassReflection;
import com.artemis.utils.reflect.ReflectionException;
import net.mostlyoriginal.api.component.common.Mirrorable;
import net.mostlyoriginal.api.operation.common.BasicOperation;
import net.mostlyoriginal.api.plugin.extendedcomponentmapper.M;
/**
* Set component state.
*
* Creates component if missing. Calls {@see Mirrorable#set} on target component.
*
* Fully pooled; state container is preserved when returned to pool.
*
* @author Daan van Yperen
*/
public abstract class SetOperation extends BasicOperation {
protected final Component a;
protected M m;
public SetOperation(Class type) {
try {
a = ClassReflection.newInstance(type);
} catch (ReflectionException e) {
String error = "Couldn't instantiate object of type " + type.getName();
throw new RuntimeException(error, e);
}
}
@Override
@SuppressWarnings("unchecked")
public void process(Entity e) {
if ( m == null ) {
m = M.getFor(a.getClass(), e.getWorld());
}
// mirror or create component.
((Mirrorable) m.create(e)).set(a);
}
@SuppressWarnings("unchecked")
public final T get() {
return (T) a;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy