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

net.mostlyoriginal.api.operation.basic.SetOperation Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
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