Skip to content

Commit

Permalink
Revert change to camelCase, instead parse it in GearyComponentSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Dec 26, 2023
1 parent fadef6f commit e0e63c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
* in the Engine.
*/
@Serializable
@SerialName("geary:copyToInstances")
@SerialName("geary:copy_to_instances")
data class CopyToInstances(
private val temporary: Set<@Polymorphic Component> = setOf(),
private val persisting: Set<@Polymorphic Component> = setOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ComponentListAsMapSerializer(

else -> {
val foundValueSerializer = serializableComponents.serializers
.getSerializerFor("$prefix$key", GearyComponent::class, namespaces) as? KSerializer<Any>
.getSerializerFor("$prefix$key".fromCamelCaseToSnakeCase(), GearyComponent::class, namespaces) as? KSerializer<Any>
?: error("No component serializer registered for $key")

val decodedValue = compositeDecoder.decodeMapValue(foundValueSerializer)
Expand All @@ -82,7 +82,15 @@ class ComponentListAsMapSerializer(
return components.toList()
}


override fun serialize(encoder: Encoder, value: List<GearyComponent>) {
TODO("Not implemented")
}

companion object{
private val camelRegex = Regex("([A-Z])")
fun String.fromCamelCaseToSnakeCase(): String {
return this.replace(camelRegex, "_$1").removePrefix("_").lowercase()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

object PrefabKeySerializer : KSerializer<PrefabKey> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("geary:prefabKey", PrimitiveKind.STRING)
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("geary:prefab_key", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): PrefabKey {
return PrefabKey.of(decoder.decodeString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.reflect.KClassifier
* Represents the [class][kClass] a component entity is responsible for.
*/
@Serializable
@SerialName("geary:componentInfo")
@SerialName("geary:component_info")
data class ComponentInfo(
val kClass: KClassifier
)

0 comments on commit e0e63c5

Please sign in to comment.