Search in sources :

Example 1 with ParticleEmitterComponent

use of org.terasology.engine.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.addEmitter(emitterEntity);
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) Test(org.junit.jupiter.api.Test)

Example 2 with ParticleEmitterComponent

use of org.terasology.engine.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method configureEmitter.

@Override
public void configureEmitter(final ParticleEmitterComponent emitter) {
    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 : Component(org.terasology.gestalt.entitysystem.component.Component) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent)

Example 3 with ParticleEmitterComponent

use of org.terasology.engine.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.addEmitter(emitterEntity);
    particleUpdater.configureEmitter(particleEmitterComponent);
    for (Component component : (Iterable<Component>) () -> componentIterator) {
        if (component.getClass() == EnergyRangeGeneratorComponent.class) {
            assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
        } else if (component.getClass() == VelocityAffectorComponent.class) {
            assertTrue(particleEmitterComponent.affectorFunctionMap.containsKey(component));
        }
    }
}
Also used : VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.gestalt.entitysystem.component.Component) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) EnergyRangeGeneratorComponent(org.terasology.engine.particles.components.generators.EnergyRangeGeneratorComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent) Test(org.junit.jupiter.api.Test)

Example 4 with ParticleEmitterComponent

use of org.terasology.engine.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method addEmitter.

@Override
public void addEmitter(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.engine.particles.components.ParticleEmitterComponent)

Example 5 with ParticleEmitterComponent

use of org.terasology.engine.particles.components.ParticleEmitterComponent in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method removeEmitter.

@Override
public void removeEmitter(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.engine.particles.components.ParticleEmitterComponent)

Aggregations

ParticleEmitterComponent (org.terasology.engine.particles.components.ParticleEmitterComponent)5 Test (org.junit.jupiter.api.Test)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 VelocityAffectorComponent (org.terasology.engine.particles.components.affectors.VelocityAffectorComponent)1 EnergyRangeGeneratorComponent (org.terasology.engine.particles.components.generators.EnergyRangeGeneratorComponent)1