Skip to content

Commit

Permalink
fix unsupported effects serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhirkevich Alexander Y authored and Zhirkevich Alexander Y committed Jul 23, 2024
1 parent 34f4bc1 commit c24dbd8
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonContentPolymorphicSerializer
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.JsonTransformingSerializer
import kotlinx.serialization.json.intOrNull
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
Expand All @@ -22,7 +26,6 @@ import kotlin.math.min
@Serializable(with = AnimatedVectorNSerializer::class)
internal sealed class AnimatedVectorN : DynamicProperty<List<Float>>() {


override fun mapEvaluated(e: Any): List<Float> {
return when (e) {
is List<*> -> e as List<Float>
Expand All @@ -36,6 +39,7 @@ internal sealed class AnimatedVectorN : DynamicProperty<List<Float>>() {
@Serializable
class Default(
@SerialName("k")
@Serializable(with = ToListSerializer::class)
val value: List<Float>,

@SerialName("x")
Expand All @@ -49,9 +53,6 @@ internal sealed class AnimatedVectorN : DynamicProperty<List<Float>>() {
prepare()
}

@Transient
private val vec = Vec2(value[0], value[1])

override fun raw(state: AnimationState): List<Float> = value

override fun copy(): AnimatedVectorN {
Expand Down Expand Up @@ -107,6 +108,8 @@ internal sealed class AnimatedVectorN : DynamicProperty<List<Float>>() {
}
}



internal class AnimatedVectorNSerializer : JsonContentPolymorphicSerializer<AnimatedVectorN>(AnimatedVectorN::class) {

override fun selectDeserializer(element: JsonElement): DeserializationStrategy<AnimatedVectorN> {
Expand All @@ -123,3 +126,13 @@ internal class AnimatedVectorNSerializer : JsonContentPolymorphicSerializer<Anim
}
}
}

internal class ToListSerializer : JsonTransformingSerializer<List<Float>>(ListSerializer(Float.serializer())){
override fun transformDeserialize(element: JsonElement): JsonElement {
return if (element is JsonPrimitive){
JsonArray(listOf(element))
} else {
element
}
}
}

0 comments on commit c24dbd8

Please sign in to comment.