Search in sources :

Example 1 with StringComponent

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

the class ComponentSerializerTest method testSerializeComponentDeltas.

@Test
public void testSerializeComponentDeltas() throws Exception {
    EntityData.Component componentData = componentSerializer.serialize(new StringComponent("Original"), new StringComponent("Delta"));
    assertEquals("value", componentData.getField(0).getName());
    assertEquals("Delta", componentData.getField(0).getValue().getString(0));
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Test(org.junit.Test)

Example 2 with StringComponent

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

the class ComponentSerializerTest method testComponentTypeIdUsedWhenLookupTableEnabled.

@Test
public void testComponentTypeIdUsedWhenLookupTableEnabled() throws Exception {
    componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
    Component stringComponent = new StringComponent("Test");
    EntityData.Component compData = componentSerializer.serialize(stringComponent);
    assertEquals(1, compData.getTypeIndex());
    assertFalse(compData.hasType());
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) GetterSetterComponent(org.terasology.entitySystem.stubs.GetterSetterComponent) IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) Component(org.terasology.entitySystem.Component) StringComponent(org.terasology.entitySystem.stubs.StringComponent) Test(org.junit.Test)

Example 3 with StringComponent

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

the class ComponentSerializerTest method testComponentTypeIdDeserializes.

@Test
public void testComponentTypeIdDeserializes() throws Exception {
    componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
    EntityData.Component compData = EntityData.Component.newBuilder().setTypeIndex(1).addField(EntityData.NameValue.newBuilder().setName("value").setValue(EntityData.Value.newBuilder().addString("item"))).build();
    Component comp = componentSerializer.deserialize(compData);
    assertTrue(comp instanceof StringComponent);
    assertEquals("item", ((StringComponent) comp).value);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) GetterSetterComponent(org.terasology.entitySystem.stubs.GetterSetterComponent) IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) Component(org.terasology.entitySystem.Component) StringComponent(org.terasology.entitySystem.stubs.StringComponent) Test(org.junit.Test)

Example 4 with StringComponent

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

the class ComponentSerializerTest method testDeltaComponentTypeIdDeserializesWithValue.

@Test
public void testDeltaComponentTypeIdDeserializesWithValue() throws Exception {
    componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
    EntityData.Component compData = EntityData.Component.newBuilder().setTypeIndex(1).addField(EntityData.NameValue.newBuilder().setName("value").setValue(EntityData.Value.newBuilder().addString("item"))).build();
    StringComponent original = new StringComponent("test");
    componentSerializer.deserializeOnto(original, compData);
    assertEquals("item", original.value);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Test(org.junit.Test)

Example 5 with StringComponent

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

the class EntitySerializerTest method testDeltaChangedComponent.

@Test
public void testDeltaChangedComponent() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Delta";
    entity.saveComponent(comp);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(1, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
    EntityData.Component componentData = entityData.getComponent(0);
    assertEquals("test:string", componentData.getType());
    assertEquals(Lists.newArrayList(EntityData.NameValue.newBuilder().setName("value").setValue(EntityData.Value.newBuilder().addString("Delta").build()).build()), componentData.getFieldList());
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) 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