Search in sources :

Example 11 with IntegerComponent

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

the class EntitySerializerTest method testDeltaLoadAddedComponent.

@Test
public void testDeltaLoadAddedComponent() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    entity.addComponent(new IntegerComponent(2));
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertTrue(loadedEntity.hasComponent(StringComponent.class));
    assertEquals("Value", loadedEntity.getComponent(StringComponent.class).value);
    assertTrue(loadedEntity.hasComponent(IntegerComponent.class));
    assertEquals(2, loadedEntity.getComponent(IntegerComponent.class).value);
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 12 with IntegerComponent

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

the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs.

@Test
public void testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.addComponent(new IntegerComponent(1));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), IntegerComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 13 with IntegerComponent

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

the class PojoEventSystemTests method testChildEventReceivedByUnfilteredHandler.

@Test
public void testChildEventReceivedByUnfilteredHandler() {
    entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEvent(new SimpleUri("test:childEvent"), TestChildEvent.class);
    eventSystem.registerEventHandler(handler);
    TestChildEvent event = new TestChildEvent();
    eventSystem.send(entity, event);
    assertEquals(1, handler.unfilteredEvents.size());
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Example 14 with IntegerComponent

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

the class PojoEventSystemTests method testReceiveEventRequiringMultipleComponents.

@Test
public void testReceiveEventRequiringMultipleComponents() {
    StringComponent stringComponent = entity.addComponent(new StringComponent());
    IntegerComponent intComponent = entity.addComponent(new IntegerComponent());
    TestCompoundComponentEventHandler handler = new TestCompoundComponentEventHandler();
    eventSystem.registerEventHandler(handler);
    TestEvent event = new TestEvent();
    eventSystem.send(entity, event);
    assertEquals(1, handler.receivedList.size());
    assertEquals(event, handler.receivedList.get(0).event);
    assertEquals(entity, handler.receivedList.get(0).entity);
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)14 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 StringComponent (org.terasology.entitySystem.stubs.StringComponent)6 SimpleUri (org.terasology.engine.SimpleUri)2 EntityData (org.terasology.protobuf.EntityData)2 Vector3i (org.terasology.math.geom.Vector3i)1