From 89fbbadec353c90421b163e3c7850dd329be23cd Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 7 Feb 2023 21:58:12 +0700 Subject: [PATCH] DynamicDefinition.toJsonTree --- .../dbotthepony/kstarbound/defs/DynamicDefinition.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DynamicDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DynamicDefinition.kt index 35aa126e..893c3027 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DynamicDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DynamicDefinition.kt @@ -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(val original: RegistryObject) { + @Volatile private var isDirty = false private var dynamicData = JsonObject() @@ -61,5 +58,11 @@ abstract class DynamicDefinition(val original: RegistryObject) { dynamicData = saveInput } + fun toJsonTree(): JsonObject { + val tree = original.gson.toJsonTree(def) as JsonObject + sanitize(tree) + return tree + } + abstract fun sanitize(saveInput: JsonObject) }