Search in sources :

Example 16 with EntityData

use of org.terasology.protobuf.EntityData 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)

Aggregations

EntityData (org.terasology.protobuf.EntityData)16 EntityRef (org.terasology.entitySystem.entity.EntityRef)15 Test (org.junit.Test)11 StringComponent (org.terasology.entitySystem.stubs.StringComponent)5 TIntIterator (gnu.trove.iterator.TIntIterator)2 Component (org.terasology.entitySystem.Component)2 EntityInfoComponent (org.terasology.entitySystem.entity.internal.EntityInfoComponent)2 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)2 NetworkComponent (org.terasology.network.NetworkComponent)2 ServerComponentFieldCheck (org.terasology.network.serialization.ServerComponentFieldCheck)2 BlockComponent (org.terasology.world.block.BlockComponent)2 SimpleUri (org.terasology.engine.SimpleUri)1 EntityScope (org.terasology.entitySystem.entity.internal.EntityScope)1 MappedTypeComponent (org.terasology.entitySystem.stubs.MappedTypeComponent)1 Client (org.terasology.network.Client)1 ClientComponentFieldCheck (org.terasology.network.serialization.ClientComponentFieldCheck)1