use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.
the class FloatTypeHandler method deserializeCollection.
@Override
public List<Float> deserializeCollection(PersistedData data, DeserializationContext context) {
if (data.isArray()) {
PersistedDataArray array = data.getAsArray();
List<Float> result = Lists.newArrayListWithCapacity(array.size());
for (PersistedData item : array) {
if (item.isNumber()) {
result.add(item.getAsFloat());
} else {
result.add(null);
}
}
return result;
}
return Lists.newArrayList();
}
use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.
the class IntTypeHandler method deserializeCollection.
@Override
public List<Integer> deserializeCollection(PersistedData data, DeserializationContext context) {
if (data.isArray()) {
PersistedDataArray array = data.getAsArray();
List<Integer> result = Lists.newArrayListWithCapacity(array.size());
for (PersistedData item : array) {
if (item.isNumber()) {
result.add(item.getAsInteger());
} else {
result.add(null);
}
}
return result;
}
return Lists.newArrayList();
}
use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.
the class LongTypeHandler method deserializeCollection.
@Override
public List<Long> deserializeCollection(PersistedData data, DeserializationContext context) {
if (data.isArray()) {
PersistedDataArray array = data.getAsArray();
List<Long> result = Lists.newArrayListWithCapacity(array.size());
for (PersistedData item : array) {
if (item.isNumber()) {
result.add(item.getAsLong());
} else {
result.add(null);
}
}
return result;
}
return Lists.newArrayList();
}
use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.
the class MappedContainerTypeHandler method serialize.
@Override
public PersistedData serialize(T value, SerializationContext context) {
if (value == null) {
return context.createNull();
}
Map<String, PersistedData> mappedData = Maps.newLinkedHashMap();
for (Map.Entry<FieldMetadata<T, ?>, TypeHandler<?>> entry : mappedFields.entrySet()) {
Object val = entry.getKey().getValue(value);
if (val != null) {
TypeHandler handler = entry.getValue();
PersistedData fieldValue = handler.serialize(val, context);
if (fieldValue != null) {
mappedData.put(entry.getKey().getName(), fieldValue);
}
}
}
return context.create(mappedData);
}
use of org.terasology.persistence.typeHandling.PersistedData in project Terasology by MovingBlocks.
the class NetEntityRefTypeHandler method serializeCollection.
@Override
public PersistedData serializeCollection(Collection<EntityRef> value, SerializationContext context) {
List<PersistedData> items = Lists.newArrayList();
for (EntityRef ref : value) {
BlockComponent blockComponent = ref.getComponent(BlockComponent.class);
if (blockComponent != null) {
Vector3i blockPos = blockComponent.getPosition();
items.add(context.create(blockPos.x, blockPos.y, blockPos.z));
} else {
NetworkComponent netComponent = ref.getComponent(NetworkComponent.class);
if (netComponent != null) {
items.add(context.create(netComponent.getNetworkId()));
} else {
items.add(context.createNull());
}
}
}
return context.create(items);
}
Aggregations