Search in sources :

Example 6 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testMassRemovedComponentEventSentOnDestroy.

@Test
public void testMassRemovedComponentEventSentOnDestroy() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.destroy();
    verify(eventSystem).send(entity1, BeforeDeactivateComponent.newInstance());
    verify(eventSystem).send(entity1, BeforeRemoveComponent.newInstance());
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 7 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testRemoveComponentEventSent.

@Test
public void testRemoveComponentEventSent() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.removeComponent(StringComponent.class);
    verify(eventSystem).send(entity1, BeforeDeactivateComponent.newInstance(), comp);
    verify(eventSystem).send(entity1, BeforeRemoveComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 8 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testAddComponentEventSent.

@Test
public void testAddComponentEventSent() {
    EventSystem eventSystem = mock(EventSystem.class);
    entityManager.setEventSystem(eventSystem);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    verify(eventSystem).send(entity1, OnAddedComponent.newInstance(), comp);
    verify(eventSystem).send(entity1, OnActivatedComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 9 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenAddOverExisting.

@Test
public void testChangeComponentEventSentWhenAddOverExisting() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    StringComponent comp2 = entity1.addComponent(new StringComponent());
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp2);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 10 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityPool method destroy.

/**
 * Destroys this entity, sending event
 *
 * @param entityId the id of the entity to destroy
 */
@Override
public void destroy(long entityId) {
    // Don't allow the destruction of unloaded entities.
    if (!entityManager.idLoaded(entityId)) {
        return;
    }
    EntityRef ref = getEntity(entityId);
    EventSystem eventSystem = entityManager.getEventSystem();
    if (eventSystem != null) {
        eventSystem.send(ref, BeforeDeactivateComponent.newInstance());
        eventSystem.send(ref, BeforeRemoveComponent.newInstance());
    }
    entityManager.notifyComponentRemovalAndEntityDestruction(entityId, ref);
    destroy(ref);
}
Also used : EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EventSystem (org.terasology.engine.entitySystem.event.internal.EventSystem)10 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)6 Test (org.junit.jupiter.api.Test)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 PojoEntityManager (org.terasology.engine.entitySystem.entity.internal.PojoEntityManager)1 EventSystemImpl (org.terasology.engine.entitySystem.event.internal.EventSystemImpl)1 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)1 PrefabManager (org.terasology.engine.entitySystem.prefab.PrefabManager)1 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)1 ConsoleImpl (org.terasology.engine.logic.console.ConsoleImpl)1 ConsoleSystem (org.terasology.engine.logic.console.ConsoleSystem)1 CoreCommands (org.terasology.engine.logic.console.commands.CoreCommands)1 NetworkEventSystemDecorator (org.terasology.engine.network.NetworkEventSystemDecorator)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 EntityRefTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.EntityRefTypeHandler)1 CharacterStateEventPositionMap (org.terasology.engine.recording.CharacterStateEventPositionMap)1 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)1