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