KStarbound/src/main/kotlin/ru/dbotthepony/kstarbound/StarboundJsonAdapters.kt

93 lines
3.9 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ru.dbotthepony.kstarbound
import com.google.gson.GsonBuilder
import ru.dbotthepony.kstarbound.defs.DamageType
import ru.dbotthepony.kstarbound.defs.JsonFunction
import ru.dbotthepony.kstarbound.defs.MaterialReference
import ru.dbotthepony.kstarbound.defs.SBPattern
import ru.dbotthepony.kstarbound.defs.ThingDescription
import ru.dbotthepony.kstarbound.defs.image.AtlasConfiguration
import ru.dbotthepony.kstarbound.defs.image.SpriteReference
import ru.dbotthepony.kstarbound.defs.item.IArmorItemDefinition
import ru.dbotthepony.kstarbound.defs.item.IItemDefinition
import ru.dbotthepony.kstarbound.defs.item.LeveledStatusEffect
import ru.dbotthepony.kstarbound.defs.parallax.ParallaxPrototype
import ru.dbotthepony.kstarbound.defs.parallax.ParallaxPrototypeLayer
import ru.dbotthepony.kstarbound.defs.projectile.ActionActions
import ru.dbotthepony.kstarbound.defs.projectile.ActionConfig
import ru.dbotthepony.kstarbound.defs.projectile.ActionLoop
import ru.dbotthepony.kstarbound.defs.projectile.ActionProjectile
import ru.dbotthepony.kstarbound.defs.projectile.ActionSound
import ru.dbotthepony.kstarbound.defs.world.SkyColoring
import ru.dbotthepony.kstarbound.defs.world.SkyColoringManifold
import ru.dbotthepony.kstarbound.defs.world.SkyParameters
import ru.dbotthepony.kstarbound.defs.world.SkySatellite
import ru.dbotthepony.kstarbound.defs.world.dungeon.DungeonWorldDef
import ru.dbotthepony.kstarbound.io.ColorTypeAdapter
import ru.dbotthepony.kstarbound.io.json.AABBTypeAdapter
import ru.dbotthepony.kstarbound.io.json.AABBiTypeAdapter
import ru.dbotthepony.kstarbound.io.json.Vector2dTypeAdapter
import ru.dbotthepony.kstarbound.io.json.Vector2fTypeAdapter
import ru.dbotthepony.kstarbound.io.json.Vector2iTypeAdapter
import ru.dbotthepony.kstarbound.io.json.Vector4iTypeAdapter
import ru.dbotthepony.kstarbound.io.json.builder.EnumAdapter
import ru.dbotthepony.kstarbound.math.PolyTypeAdapter
fun addStarboundJsonAdapters(builder: GsonBuilder) {
with(builder) {
registerTypeAdapterFactory(SBPattern.Companion)
registerTypeAdapter(ColorTypeAdapter.nullSafe())
// математические классы
registerTypeAdapter(AABBTypeAdapter)
registerTypeAdapter(AABBiTypeAdapter)
registerTypeAdapter(Vector2dTypeAdapter)
registerTypeAdapter(Vector2fTypeAdapter)
registerTypeAdapter(Vector2iTypeAdapter)
registerTypeAdapter(Vector4iTypeAdapter)
registerTypeAdapter(PolyTypeAdapter)
// Снаряды
registerTypeAdapterFactory(ActionConfig.ADAPTER)
registerTypeAdapterFactory(ActionProjectile.ADAPTER)
registerTypeAdapterFactory(ActionSound.ADAPTER)
registerTypeAdapterFactory(ActionLoop.ADAPTER)
registerTypeAdapterFactory(ActionActions.ADAPTER)
// Параметры неба
registerTypeAdapterFactory(SkyParameters.ADAPTER)
registerTypeAdapter(SkyColoringManifold.ADAPTER)
registerTypeAdapterFactory(SkyColoring.ADAPTER)
registerTypeAdapterFactory(SkySatellite.ADAPTER)
registerTypeAdapterFactory(SkySatellite.LAYER_ADAPTER)
// Данные о данжах
registerTypeAdapterFactory(DungeonWorldDef.ADAPTER)
// Параллакс
registerTypeAdapterFactory(ParallaxPrototype.ADAPTER)
registerTypeAdapterFactory(ParallaxPrototypeLayer.ADAPTER)
registerTypeAdapter(ParallaxPrototypeLayer.LAYER_PARALLAX_ADAPTER)
// Предметы
registerTypeAdapterFactory(IItemDefinition.InventoryIcon.ADAPTER)
registerTypeAdapterFactory(IArmorItemDefinition.ArmorFrames.ADAPTER)
// Функции
registerTypeAdapter(JsonFunction.CONSTRAINT_ADAPTER)
registerTypeAdapter(JsonFunction.INTERPOLATION_ADAPTER)
registerTypeAdapter(JsonFunction.Companion)
// Общее
registerTypeAdapter(SpriteReference.Companion)
registerTypeAdapterFactory(AtlasConfiguration.Companion)
registerTypeAdapterFactory(LeveledStatusEffect.ADAPTER)
registerTypeAdapter(MaterialReference.Companion)
registerTypeAdapter(ThingDescription.Companion)
registerTypeAdapter(EnumAdapter(DamageType::class, default = DamageType.NORMAL))
}
}