From e0e63c53fc821d8a0429ef5214da1c52e8e6a9ac Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Tue, 26 Dec 2023 01:39:42 -0500 Subject: [PATCH] Revert change to camelCase, instead parse it in GearyComponentSerializer --- .../configuration/components/CopyToInstances.kt | 2 +- .../serializers/ComponentListAsMapSerializer.kt | 10 +++++++++- .../geary/prefabs/serializers/PrefabKeySerializer.kt | 2 +- .../com/mineinabyss/geary/components/ComponentInfo.kt | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt index adcb0f83b..446d5b2ee 100644 --- a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt +++ b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt @@ -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(), diff --git a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/ComponentListAsMapSerializer.kt b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/ComponentListAsMapSerializer.kt index 5e30279c6..7266ad32d 100644 --- a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/ComponentListAsMapSerializer.kt +++ b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/ComponentListAsMapSerializer.kt @@ -70,7 +70,7 @@ class ComponentListAsMapSerializer( else -> { val foundValueSerializer = serializableComponents.serializers - .getSerializerFor("$prefix$key", GearyComponent::class, namespaces) as? KSerializer + .getSerializerFor("$prefix$key".fromCamelCaseToSnakeCase(), GearyComponent::class, namespaces) as? KSerializer ?: error("No component serializer registered for $key") val decodedValue = compositeDecoder.decodeMapValue(foundValueSerializer) @@ -82,7 +82,15 @@ class ComponentListAsMapSerializer( return components.toList() } + override fun serialize(encoder: Encoder, value: List) { TODO("Not implemented") } + + companion object{ + private val camelRegex = Regex("([A-Z])") + fun String.fromCamelCaseToSnakeCase(): String { + return this.replace(camelRegex, "_$1").removePrefix("_").lowercase() + } + } } diff --git a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/PrefabKeySerializer.kt b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/PrefabKeySerializer.kt index 0ec30d686..d6f659706 100644 --- a/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/PrefabKeySerializer.kt +++ b/addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/serializers/PrefabKeySerializer.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder object PrefabKeySerializer : KSerializer { - 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()) diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/components/ComponentInfo.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/components/ComponentInfo.kt index 5e54925e7..7d88152d3 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/components/ComponentInfo.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/components/ComponentInfo.kt @@ -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 )