diff options
Diffstat (limited to 'src/main/kotlin/util/skyblock/Rarity.kt')
-rw-r--r-- | src/main/kotlin/util/skyblock/Rarity.kt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/Rarity.kt b/src/main/kotlin/util/skyblock/Rarity.kt index f26cefe..0244630 100644 --- a/src/main/kotlin/util/skyblock/Rarity.kt +++ b/src/main/kotlin/util/skyblock/Rarity.kt @@ -1,5 +1,12 @@ package moe.nea.firmament.util.skyblock +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder import net.minecraft.item.ItemStack import net.minecraft.text.Text import moe.nea.firmament.util.StringUtil.words @@ -10,6 +17,7 @@ import moe.nea.firmament.util.unformattedString typealias RepoRarity = io.github.moulberry.repo.data.Rarity +@Serializable(with = Rarity.Serializer::class) enum class Rarity(vararg altNames: String) { COMMON, UNCOMMON, @@ -24,6 +32,19 @@ enum class Rarity(vararg altNames: String) { UNKNOWN ; + object Serializer : KSerializer<Rarity> { + override val descriptor: SerialDescriptor + get() = PrimitiveSerialDescriptor(Rarity::class.java.name, PrimitiveKind.STRING) + + override fun deserialize(decoder: Decoder): Rarity { + return valueOf(decoder.decodeString().replace(" ", "_")) + } + + override fun serialize(encoder: Encoder, value: Rarity) { + encoder.encodeString(value.name) + } + } + val names = setOf(name) + altNames val neuRepoRarity: RepoRarity? = RepoRarity.entries.find { it.name == name } |