DynamicDefinition.toJsonTree

This commit is contained in:
DBotThePony 2023-02-07 21:58:12 +07:00
parent ebdf0aa642
commit 89fbbadec3
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -1,12 +1,8 @@
package ru.dbotthepony.kstarbound.defs
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.internal.bind.JsonTreeReader
import com.google.gson.reflect.TypeToken
import ru.dbotthepony.kstarbound.RegistryObject
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
private fun merge(destination: JsonObject, source: JsonObject) {
for ((k, v) in source.entrySet()) {
@ -25,6 +21,7 @@ private fun merge(destination: JsonObject, source: JsonObject) {
}
abstract class DynamicDefinition<Def : Any>(val original: RegistryObject<Def>) {
@Volatile
private var isDirty = false
private var dynamicData = JsonObject()
@ -61,5 +58,11 @@ abstract class DynamicDefinition<Def : Any>(val original: RegistryObject<Def>) {
dynamicData = saveInput
}
fun toJsonTree(): JsonObject {
val tree = original.gson.toJsonTree(def) as JsonObject
sanitize(tree)
return tree
}
abstract fun sanitize(saveInput: JsonObject)
}