Search in sources :

Example 16 with PersistedData

use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testDeserializeHex.

@Test
public void testDeserializeHex() {
    PersistedData data = new PersistedString("DEADBEEF");
    Color color = handler.deserialize(data, deserializationContext);
    Assert.assertEquals(0xDEADBEEF, color.rgba());
}
Also used : PersistedString(org.terasology.persistence.typeHandling.inMemory.PersistedString) Color(org.terasology.rendering.nui.Color) PersistedData(org.terasology.persistence.typeHandling.PersistedData) Test(org.junit.Test)

Example 17 with PersistedData

use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testDeserializeArray.

@Test
public void testDeserializeArray() {
    JsonArray array = new Gson().fromJson("[12, 34, 56, 78]", JsonArray.class);
    PersistedData data = new GsonPersistedDataArray(array);
    Color color = handler.deserialize(data, deserializationContext);
    Assert.assertEquals(12, color.r());
    Assert.assertEquals(34, color.g());
    Assert.assertEquals(56, color.b());
    Assert.assertEquals(78, color.a());
}
Also used : JsonArray(com.google.gson.JsonArray) Color(org.terasology.rendering.nui.Color) Gson(com.google.gson.Gson) PersistedData(org.terasology.persistence.typeHandling.PersistedData) GsonPersistedDataArray(org.terasology.persistence.typeHandling.gson.GsonPersistedDataArray) Test(org.junit.Test)

Aggregations

PersistedData (org.terasology.persistence.typeHandling.PersistedData)17 PersistedDataArray (org.terasology.persistence.typeHandling.PersistedDataArray)6 Test (org.junit.Test)4 ReplicatedFieldMetadata (org.terasology.entitySystem.metadata.ReplicatedFieldMetadata)4 Serializer (org.terasology.persistence.typeHandling.Serializer)4 ProtobufPersistedData (org.terasology.persistence.typeHandling.protobuf.ProtobufPersistedData)4 DeserializationContext (org.terasology.persistence.typeHandling.DeserializationContext)3 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)3 Map (java.util.Map)2 SerializationContext (org.terasology.persistence.typeHandling.SerializationContext)2 SimpleTypeHandler (org.terasology.persistence.typeHandling.SimpleTypeHandler)2 TypeHandler (org.terasology.persistence.typeHandling.TypeHandler)2 EntityData (org.terasology.protobuf.EntityData)2 Color (org.terasology.rendering.nui.Color)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 Component (org.terasology.entitySystem.Component)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 Vector3i (org.terasology.math.geom.Vector3i)1 NetworkComponent (org.terasology.network.NetworkComponent)1