Search in sources :

Example 16 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testDestroyEntity.

@Test
public void testDestroyEntity() {
    EntityRef entity = entityManager.create();
    entity.addComponent(new StringComponent());
    entity.addComponent(new IntegerComponent());
    entity.destroy();
    assertNull(entity.getComponent(StringComponent.class));
    assertNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 17 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testDestroyingEntityInvalidatesEntityRefs.

@Test
public void testDestroyingEntityInvalidatesEntityRefs() {
    EntityRef main = entityManager.create();
    main.addComponent(new StringComponent());
    EntityRef reference = entityManager.create();
    EntityRefComponent refComp = reference.addComponent(new EntityRefComponent());
    refComp.entityRef = entityManager.getEntitiesWith(StringComponent.class).iterator().next();
    assertTrue(main.exists());
    entityManager.getEntitiesWith(StringComponent.class).iterator().next().destroy();
    assertFalse(main.exists());
    assertFalse(refComp.entityRef.exists());
}
Also used : EntityRefComponent(org.terasology.entitySystem.stubs.EntityRefComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 18 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testIterateEntitiesFindsEntityWithSingleComponent.

@Test
public void testIterateEntitiesFindsEntityWithSingleComponent() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    List<EntityRef> results = Lists.newArrayList(entityManager.getEntitiesWith(StringComponent.class));
    assertEquals(Lists.newArrayList(entity1), results);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 19 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentsDuringIterator.

@Test
public void testChangeComponentsDuringIterator() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    EntityRef entity2 = entityManager.create();
    entity2.addComponent(new StringComponent());
    Iterator<Map.Entry<EntityRef, StringComponent>> iterator = entityManager.listComponents(StringComponent.class).iterator();
    iterator.next();
    entity2.removeComponent(StringComponent.class);
    iterator.next();
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 20 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testIterateEntitiesFindsEntityWithTwoComponents.

@Test
public void testIterateEntitiesFindsEntityWithTwoComponents() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entity1.addComponent(new IntegerComponent());
    List<EntityRef> results = Lists.newArrayList(entityManager.getEntitiesWith(StringComponent.class, IntegerComponent.class));
    assertEquals(Lists.newArrayList(entity1), results);
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

StringComponent (org.terasology.entitySystem.stubs.StringComponent)41 Test (org.junit.Test)38 EntityRef (org.terasology.entitySystem.entity.EntityRef)22 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)8 EntityData (org.terasology.protobuf.EntityData)8 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)5 ResourceUrn (org.terasology.assets.ResourceUrn)4 PrefabData (org.terasology.entitySystem.prefab.PrefabData)4 Prefab (org.terasology.entitySystem.prefab.Prefab)3 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)3 Before (org.junit.Before)2 SimpleUri (org.terasology.engine.SimpleUri)2 Component (org.terasology.entitySystem.Component)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 GetterSetterComponent (org.terasology.entitySystem.stubs.GetterSetterComponent)2 Vector3i (org.terasology.math.geom.Vector3i)2 NetworkSystem (org.terasology.network.NetworkSystem)2 Map (java.util.Map)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 StorageManager (org.terasology.persistence.StorageManager)1