И ещё больше штуковин для десериализации!

This commit is contained in:
DBotThePony 2022-12-30 17:29:25 +07:00
parent 366e59cf14
commit 63d5afdfcd
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 17 additions and 13 deletions

View File

@ -111,7 +111,7 @@ object Starbound {
val assetStringInterner: Interner<String> = Interners.newStrongInterner() val assetStringInterner: Interner<String> = Interners.newStrongInterner()
val stringTypeAdapter: TypeAdapter<String?> = object : TypeAdapter<String>() { val nonnullStringTypeAdapter: TypeAdapter<String> = object : TypeAdapter<String>() {
override fun write(out: JsonWriter, value: String) { override fun write(out: JsonWriter, value: String) {
out.value(value) out.value(value)
} }
@ -119,7 +119,9 @@ object Starbound {
override fun read(`in`: JsonReader): String { override fun read(`in`: JsonReader): String {
return assetStringInterner.intern(TypeAdapters.STRING.read(`in`)) return assetStringInterner.intern(TypeAdapters.STRING.read(`in`))
} }
}.nullSafe() }
val stringTypeAdapter: TypeAdapter<String?> = nonnullStringTypeAdapter.nullSafe()
val gson: Gson = GsonBuilder() val gson: Gson = GsonBuilder()
.enableComplexMapKeySerialization() .enableComplexMapKeySerialization()

View File

@ -3,6 +3,8 @@ package ru.dbotthepony.kstarbound.defs.item
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
import ru.dbotthepony.kstarbound.io.json.asJsonObject
import ru.dbotthepony.kstarbound.io.json.asList
import ru.dbotthepony.kstarbound.registerTypeAdapter import ru.dbotthepony.kstarbound.registerTypeAdapter
import ru.dbotthepony.kvector.vector.ndouble.Vector2d import ru.dbotthepony.kvector.vector.ndouble.Vector2d
@ -195,7 +197,7 @@ data class ItemDefinition(
/** /**
* Варианты покраски (???) * Варианты покраски (???)
*/ */
// val colorOptions: Map<String, String> = mapOf(), val colorOptions: List<Map<String, String>> = listOf(),
/** /**
* Визуальные кадры анимации, когда надето на гуманоида мужского пола * Визуальные кадры анимации, когда надето на гуманоида мужского пола
@ -276,7 +278,7 @@ data class ItemDefinition(
.auto(ItemDefinition::fossilSetName) .auto(ItemDefinition::fossilSetName)
.auto(ItemDefinition::setIndex) .auto(ItemDefinition::setIndex)
.auto(ItemDefinition::setCount) .auto(ItemDefinition::setCount)
.map(ItemDefinition::setCollectables, String::class) .mapAsObject(ItemDefinition::setCollectables, String::class)
.auto(ItemDefinition::completeFossilIcon) .auto(ItemDefinition::completeFossilIcon)
.auto(ItemDefinition::completeFossilObject) .auto(ItemDefinition::completeFossilObject)
@ -298,7 +300,7 @@ data class ItemDefinition(
.auto(ItemDefinition::tooltipKind) .auto(ItemDefinition::tooltipKind)
.auto(ItemDefinition::level) .auto(ItemDefinition::level)
.list(ItemDefinition::leveledStatusEffects) .list(ItemDefinition::leveledStatusEffects)
// .map(ItemDefinition::colorOptions) .add(ItemDefinition::colorOptions, Starbound.nonnullStringTypeAdapter.asJsonObject().asList())
.auto(ItemDefinition::maleFrames) .auto(ItemDefinition::maleFrames)
.auto(ItemDefinition::femaleFrames) .auto(ItemDefinition::femaleFrames)

View File

@ -262,10 +262,10 @@ data class RenderTemplate(
companion object { companion object {
val ADAPTER = KConcreteTypeAdapter.Builder(RenderTemplate::class) val ADAPTER = KConcreteTypeAdapter.Builder(RenderTemplate::class)
.map(RenderTemplate::pieces, RenderPiece::class.java) .mapAsObject(RenderTemplate::pieces, RenderPiece::class.java)
.auto(RenderTemplate::representativePiece) .auto(RenderTemplate::representativePiece)
.list(RenderTemplate::matches, RenderMatchList::class.java) .list(RenderTemplate::matches, RenderMatchList::class.java)
.map(RenderTemplate::rules, RenderRuleList::class.java) .mapAsObject(RenderTemplate::rules, RenderRuleList::class.java)
.build() .build()
fun registerGson(gsonBuilder: GsonBuilder) { fun registerGson(gsonBuilder: GsonBuilder) {

View File

@ -428,7 +428,7 @@ class KConcreteTypeAdapter<T : Any> private constructor(
* *
* Таблица неизменяема (создаётся объект [ImmutableMap]) * Таблица неизменяема (создаётся объект [ImmutableMap])
*/ */
fun <K, V> map(field: KProperty1<T, Map<K, V>>, keyType: Class<K>, valueType: Class<V>): Builder<T> { fun <K, V> mapAsArray(field: KProperty1<T, Map<K, V>>, keyType: Class<K>, valueType: Class<V>): Builder<T> {
types.add(PackedProperty(field, MapAdapter(keyType, valueType))) types.add(PackedProperty(field, MapAdapter(keyType, valueType)))
return this return this
} }
@ -442,9 +442,9 @@ class KConcreteTypeAdapter<T : Any> private constructor(
*/ */
inline fun <reified K, reified V> map(field: KProperty1<T, Map<K, V>>): Builder<T> { inline fun <reified K, reified V> map(field: KProperty1<T, Map<K, V>>): Builder<T> {
if (K::class == String::class) if (K::class == String::class)
return this.map(field as KProperty1<T, Map<String, V>?>, V::class.java) return this.mapAsObject(field as KProperty1<T, Map<String, V>?>, V::class.java)
return this.map(field, K::class.java, V::class.java) return this.mapAsArray(field, K::class.java, V::class.java)
} }
/** /**
@ -452,7 +452,7 @@ class KConcreteTypeAdapter<T : Any> private constructor(
* *
* Таблица неизменяема (создаётся объект [ImmutableMap]) * Таблица неизменяема (создаётся объект [ImmutableMap])
*/ */
fun <K : Any, V : Any> map(field: KProperty1<T, Map<K, V>?>, keyType: KClass<K>, valueType: KClass<V>): Builder<T> { fun <K : Any, V : Any> mapAsArray(field: KProperty1<T, Map<K, V>?>, keyType: KClass<K>, valueType: KClass<V>): Builder<T> {
types.add(PackedProperty(field, MapAdapter(keyType.java, valueType.java).nullSafe())) types.add(PackedProperty(field, MapAdapter(keyType.java, valueType.java).nullSafe()))
return this return this
} }
@ -462,7 +462,7 @@ class KConcreteTypeAdapter<T : Any> private constructor(
* *
* Таблица неизменяема (создаётся объект [ImmutableMap]) * Таблица неизменяема (создаётся объект [ImmutableMap])
*/ */
fun <V> map(field: KProperty1<T, Map<String, V>?>, valueType: Class<V>): Builder<T> { fun <V> mapAsObject(field: KProperty1<T, Map<String, V>?>, valueType: Class<V>): Builder<T> {
types.add(PackedProperty(field, String2ObjectAdapter(valueType).nullSafe())) types.add(PackedProperty(field, String2ObjectAdapter(valueType).nullSafe()))
return this return this
} }
@ -472,7 +472,7 @@ class KConcreteTypeAdapter<T : Any> private constructor(
* *
* Таблица неизменяема (создаётся объект [ImmutableMap]) * Таблица неизменяема (создаётся объект [ImmutableMap])
*/ */
fun <V : Any> map(field: KProperty1<T, Map<String, V>?>, valueType: KClass<V>): Builder<T> { fun <V : Any> mapAsObject(field: KProperty1<T, Map<String, V>?>, valueType: KClass<V>): Builder<T> {
types.add(PackedProperty(field, String2ObjectAdapter(valueType.java).nullSafe())) types.add(PackedProperty(field, String2ObjectAdapter(valueType.java).nullSafe()))
return this return this
} }