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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations