mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
actor serialiser
This commit is contained in:
33
src/net/torvald/terrarum/serialise/WriteActor.kt
Normal file
33
src/net/torvald/terrarum/serialise/WriteActor.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.badlogic.gdx.utils.JsonValue
|
||||
import com.badlogic.gdx.utils.JsonWriter
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import java.math.BigInteger
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-24.
|
||||
*/
|
||||
object WriteActor {
|
||||
|
||||
private val jsoner = Json(JsonWriter.OutputType.json)
|
||||
|
||||
// install custom (de)serialiser
|
||||
init {
|
||||
jsoner.setSerializer(BigInteger::class.java, object : Json.Serializer<BigInteger> {
|
||||
override fun write(json: Json, obj: BigInteger?, knownType: Class<*>?) {
|
||||
json.writeValue(obj?.toString())
|
||||
}
|
||||
|
||||
override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): BigInteger {
|
||||
return BigInteger(jsonData.asString())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
operator fun invoke(actor: Actor): String {
|
||||
return jsoner.toJson(actor)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user