Search in sources :

Example 1 with ParticleEmitterComponent

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);
}
Also used : ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent)

Example 2 with ParticleEmitterComponent

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()));
        }
    }
}
Also used : ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) Component(org.terasology.entitySystem.Component)

Example 3 with ParticleEmitterComponent

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);
}
Also used : ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent)

Example 4 with ParticleEmitterComponent

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);
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) Test(org.junit.Test)

Example 5 with ParticleEmitterComponent

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));
        }
    }
}
Also used : EnergyRangeGeneratorComponent(org.terasology.particles.components.generators.EnergyRangeGeneratorComponent) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) VelocityAffectorComponent(org.terasology.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) Test(org.junit.Test)

Aggregations

ParticleEmitterComponent (org.terasology.particles.components.ParticleEmitterComponent)5 Test (org.junit.Test)2 Component (org.terasology.entitySystem.Component)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 VelocityAffectorComponent (org.terasology.particles.components.affectors.VelocityAffectorComponent)1 EnergyRangeGeneratorComponent (org.terasology.particles.components.generators.EnergyRangeGeneratorComponent)1