aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/config/serializations/KeySerializer.kt
blob: 702dab51ef4986812b44b1aa28c253601ed7cb9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.dulkirfabric.config.serializations

import kotlinx.serialization.KSerializer
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.client.util.InputUtil

object KeySerializer: KSerializer<InputUtil.Key> {
    override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("InputUtil.Key", PrimitiveKind.INT)

    override fun deserialize(decoder: Decoder): InputUtil.Key {
        return InputUtil.fromKeyCode(decoder.decodeInt(), 0)
    }

    override fun serialize(encoder: Encoder, value: InputUtil.Key) {
        encoder.encodeInt(value.code)
    }
}