use of org.terasology.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.
the class ParticleUpdaterImpl method register.
@Override
public void register(final EntityRef emitter) {
Preconditions.checkArgument(emitter != null, "Argument can not be null");
ParticleEmitterComponent emitterComponent = emitter.getComponent(ParticleEmitterComponent.class);
Preconditions.checkArgument(emitterComponent != null, "Entity %s does not have a ParticleEmitterComponent", emitter);
registeredParticleSystems.add(emitterComponent);
}
use of org.terasology.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.
the class ParticleUpdaterImpl method configureEmitter.
@Override
public void configureEmitter(final ParticleEmitterComponent emitter, final BiMap<Class<Component>, AffectorFunction> registeredAffectorFunctions, final BiMap<Class<Component>, GeneratorFunction> registeredGeneratorFunctions) {
emitter.generatorFunctionMap.clear();
emitter.affectorFunctionMap.clear();
for (Component c : emitter.ownerEntity.iterateComponents()) {
if (registeredGeneratorFunctions.containsKey(c.getClass())) {
emitter.generatorFunctionMap.put(c, registeredGeneratorFunctions.get(c.getClass()));
} else if (registeredAffectorFunctions.containsKey(c.getClass())) {
emitter.affectorFunctionMap.put(c, registeredAffectorFunctions.get(c.getClass()));
}
}
}
use of org.terasology.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.
the class ParticleUpdaterImpl method dispose.
@Override
public void dispose(final EntityRef emitter) {
Preconditions.checkArgument(emitter != null, "Argument can not be null");
ParticleEmitterComponent emitterComponent = emitter.getComponent(ParticleEmitterComponent.class);
Preconditions.checkState(registeredParticleSystems.contains(emitterComponent), "Entity %s is not a registered entity", emitter);
registeredParticleSystems.remove(emitterComponent);
}
use of org.terasology.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.
the class ParticleUpdaterImplTest method testEmitterRegistration.
@Test
public void testEmitterRegistration() {
EntityRef emitterEntity = mock(EntityRef.class);
when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(new ParticleEmitterComponent());
particleUpdater.register(emitterEntity);
}
use of org.terasology.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.
the class ParticleUpdaterImplTest method testEmitterConfiguration.
@Test
public void testEmitterConfiguration() {
EntityRef emitterEntity = mock(EntityRef.class);
Iterator<Component> componentIterator = getTestGeneratorsAndAffectors();
when(emitterEntity.iterateComponents()).thenReturn(() -> componentIterator);
ParticleEmitterComponent particleEmitterComponent = new ParticleEmitterComponent();
particleEmitterComponent.ownerEntity = emitterEntity;
when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(particleEmitterComponent);
particleUpdater.register(emitterEntity);
particleUpdater.configureEmitter(particleEmitterComponent, registeredAffectorFunctions, registeredGeneratorFunctions);
for (Component component : (Iterable<Component>) () -> componentIterator) {
if (registeredGeneratorFunctions.containsKey(component.getClass())) {
assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
} else if (registeredGeneratorFunctions.containsKey(component.getClass())) {
assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
}
}
}
Aggregations