Правильные имена адаптеров типов
This commit is contained in:
parent
2a4ad28e3e
commit
b3636e5a55
@ -6,7 +6,7 @@ import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonToken
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import ru.dbotthepony.kstarbound.io.json.KTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.BuilderAdapter
|
||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@ -16,7 +16,7 @@ class ParallaxPrototype {
|
||||
var layers = Array(0) { ParallaxPrototypeLayer() }
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ParallaxPrototype,
|
||||
val ADAPTER = BuilderAdapter(::ParallaxPrototype,
|
||||
ParallaxPrototype::verticalOrigin,
|
||||
ParallaxPrototype::layers,
|
||||
)
|
||||
@ -80,7 +80,7 @@ class ParallaxPrototypeLayer {
|
||||
}
|
||||
}
|
||||
|
||||
val ADAPTER = KTypeAdapter(::ParallaxPrototypeLayer,
|
||||
val ADAPTER = BuilderAdapter(::ParallaxPrototypeLayer,
|
||||
ParallaxPrototypeLayer::timeOfDayCorrelation,
|
||||
ParallaxPrototypeLayer::offset,
|
||||
ParallaxPrototypeLayer::repeatY,
|
||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.defs.item
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.defs.animation.SpriteReference
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.ListAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.asJsonObject
|
||||
import ru.dbotthepony.kstarbound.io.json.asList
|
||||
@ -263,11 +263,11 @@ data class ItemDefinition(
|
||||
)
|
||||
|
||||
companion object {
|
||||
val INVENTORY_ICON_ADAPTER = KConcreteTypeAdapter.Builder(InventoryIcon::class)
|
||||
val INVENTORY_ICON_ADAPTER = FactoryAdapter.Builder(InventoryIcon::class)
|
||||
.auto(InventoryIcon::image)
|
||||
.build()
|
||||
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(ItemDefinition::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(ItemDefinition::class)
|
||||
.auto(ItemDefinition::itemName)
|
||||
.auto(ItemDefinition::price)
|
||||
.auto(ItemDefinition::rarity)
|
||||
@ -323,20 +323,20 @@ data class ItemDefinition(
|
||||
|
||||
.build()
|
||||
|
||||
val FOSSIL_ADAPTER = KConcreteTypeAdapter.Builder(FossilSetDescription::class)
|
||||
val FOSSIL_ADAPTER = FactoryAdapter.Builder(FossilSetDescription::class)
|
||||
.auto(FossilSetDescription::price)
|
||||
.auto(FossilSetDescription::shortdescription)
|
||||
.auto(FossilSetDescription::description)
|
||||
.build()
|
||||
|
||||
val ARMOR_FRAMES_ADAPTER = KConcreteTypeAdapter.Builder(ArmorFrames::class)
|
||||
val ARMOR_FRAMES_ADAPTER = FactoryAdapter.Builder(ArmorFrames::class)
|
||||
.auto(ArmorFrames::body, transformer = Starbound::readingFolderTransformer)
|
||||
.auto(ArmorFrames::backSleeve, transformer = Starbound::readingFolderTransformerNullable)
|
||||
.auto(ArmorFrames::frontSleeve, transformer = Starbound::readingFolderTransformerNullable)
|
||||
.build()
|
||||
.ifString { ArmorFrames(Starbound.readingFolderTransformer(it), null, null) }
|
||||
|
||||
val STATUS_EFFECT_ADAPTER = KConcreteTypeAdapter.Builder(StatusEffect::class)
|
||||
val STATUS_EFFECT_ADAPTER = FactoryAdapter.Builder(StatusEffect::class)
|
||||
.auto(StatusEffect::levelFunction)
|
||||
.auto(StatusEffect::stat)
|
||||
.auto(StatusEffect::baseMultiplier)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package ru.dbotthepony.kstarbound.defs.liquid
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
import ru.dbotthepony.kstarbound.registerTypeAdapter
|
||||
import ru.dbotthepony.kvector.vector.Color
|
||||
|
||||
@ -25,7 +25,7 @@ data class LiquidDefinition(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(LiquidDefinition::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(LiquidDefinition::class)
|
||||
.auto(LiquidDefinition::name)
|
||||
.auto(LiquidDefinition::liquidId)
|
||||
.auto(LiquidDefinition::description)
|
||||
@ -39,7 +39,7 @@ data class LiquidDefinition(
|
||||
.auto(LiquidDefinition::textureMovementFactor)
|
||||
.build()
|
||||
|
||||
val INTERACTION_ADAPTER = KConcreteTypeAdapter.Builder(Interaction::class)
|
||||
val INTERACTION_ADAPTER = FactoryAdapter.Builder(Interaction::class)
|
||||
.auto(Interaction::liquid)
|
||||
.auto(Interaction::liquidResult)
|
||||
.auto(Interaction::materialResult)
|
||||
|
@ -8,7 +8,7 @@ import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.defs.*
|
||||
import ru.dbotthepony.kstarbound.io.json.ConfigurableTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.KTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.BuilderAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.CustomEnumTypeAdapter
|
||||
import ru.dbotthepony.kvector.vector.Color
|
||||
import kotlin.properties.Delegates
|
||||
@ -182,7 +182,7 @@ class ActionConfig : IConfigurableAction {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ActionConfig, ActionConfig::file).ignoreProperty("action")
|
||||
val ADAPTER = BuilderAdapter(::ActionConfig, ActionConfig::file).ignoreProperty("action")
|
||||
|
||||
private val cache = HashMap<String, CActionConfig>()
|
||||
}
|
||||
@ -201,7 +201,7 @@ class ActionProjectile : IConfigurableAction {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ActionProjectile,
|
||||
val ADAPTER = BuilderAdapter(::ActionProjectile,
|
||||
ActionProjectile::type,
|
||||
ActionProjectile::angle,
|
||||
ActionProjectile::inheritDamageFactor,
|
||||
@ -220,7 +220,7 @@ class ActionSound : IConfigurableAction {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ActionSound,
|
||||
val ADAPTER = BuilderAdapter(::ActionSound,
|
||||
ActionSound::options,
|
||||
).ignoreProperty("action")
|
||||
}
|
||||
@ -238,7 +238,7 @@ class ActionLoop : IConfigurableAction {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ActionLoop,
|
||||
val ADAPTER = BuilderAdapter(::ActionLoop,
|
||||
ActionLoop::count,
|
||||
ActionLoop::body,
|
||||
).ignoreProperty("action")
|
||||
@ -256,7 +256,7 @@ class ActionActions : IConfigurableAction {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::ActionActions,
|
||||
val ADAPTER = BuilderAdapter(::ActionActions,
|
||||
ActionActions::list,
|
||||
).ignoreProperty("action")
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package ru.dbotthepony.kstarbound.defs.tile
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
|
||||
data class MaterialModifier(
|
||||
val modId: Int,
|
||||
@ -22,7 +22,7 @@ data class MaterialModifier(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(MaterialModifier::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(MaterialModifier::class)
|
||||
.auto(MaterialModifier::modId)
|
||||
.auto(MaterialModifier::modName)
|
||||
.auto(MaterialModifier::itemDrop)
|
||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.defs.tile
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
|
||||
const val TILE_COLOR_VARIANTS = 9
|
||||
|
||||
@ -27,7 +27,7 @@ data class RenderParameters(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderParameters::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderParameters::class)
|
||||
.auto(
|
||||
RenderParameters::texture,
|
||||
RenderParameters::variants,
|
||||
|
@ -10,7 +10,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.io.json.EnumAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
import ru.dbotthepony.kstarbound.registerTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.util.WriteOnce
|
||||
import ru.dbotthepony.kstarbound.world.ITileGetter
|
||||
@ -26,7 +26,7 @@ data class RenderPiece(
|
||||
val variantStride: Vector2i? = null,
|
||||
) {
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderPiece::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderPiece::class)
|
||||
.auto(
|
||||
RenderPiece::texture,
|
||||
RenderPiece::textureSize,
|
||||
@ -82,7 +82,7 @@ data class RenderRuleList(
|
||||
private val LOGGER = LogManager.getLogger()
|
||||
private val LOGGED = ObjectArraySet<String>()
|
||||
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(Entry::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(Entry::class)
|
||||
.auto(
|
||||
Entry::type,
|
||||
Entry::matchHue,
|
||||
@ -117,7 +117,7 @@ data class RenderRuleList(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderRuleList::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderRuleList::class)
|
||||
.autoList(RenderRuleList::entries)
|
||||
.auto(RenderRuleList::join)
|
||||
.build()
|
||||
@ -206,7 +206,7 @@ data class RenderMatch(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderMatch::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderMatch::class)
|
||||
.autoList(RenderMatch::pieces)
|
||||
.autoList(RenderMatch::matchAllPoints)
|
||||
.autoList(RenderMatch::matchAnyPoints)
|
||||
@ -215,13 +215,13 @@ data class RenderMatch(
|
||||
.auto(RenderMatch::haltOnSubMatch)
|
||||
.build()
|
||||
|
||||
val PIECE_ADAPTER = KConcreteTypeAdapter.Builder(Piece::class)
|
||||
val PIECE_ADAPTER = FactoryAdapter.Builder(Piece::class)
|
||||
.auto(Piece::name)
|
||||
.auto(Piece::offset)
|
||||
.inputAsList()
|
||||
.build()
|
||||
|
||||
val MATCHER_ADAPTER = KConcreteTypeAdapter.Builder(Matcher::class)
|
||||
val MATCHER_ADAPTER = FactoryAdapter.Builder(Matcher::class)
|
||||
.auto(Matcher::offset)
|
||||
.auto(Matcher::ruleName)
|
||||
.inputAsList()
|
||||
@ -240,7 +240,7 @@ data class RenderMatchList(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderMatchList::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderMatchList::class)
|
||||
.auto(RenderMatchList::name)
|
||||
.autoList(RenderMatchList::list)
|
||||
.inputAsList()
|
||||
@ -261,7 +261,7 @@ data class RenderTemplate(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(RenderTemplate::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(RenderTemplate::class)
|
||||
.mapAsObject(RenderTemplate::pieces, RenderPiece::class.java)
|
||||
.auto(RenderTemplate::representativePiece)
|
||||
.list(RenderTemplate::matches, RenderMatchList::class.java)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package ru.dbotthepony.kstarbound.defs.tile
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.io.json.KConcreteTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.FactoryAdapter
|
||||
import ru.dbotthepony.kstarbound.registerTypeAdapter
|
||||
import ru.dbotthepony.kvector.vector.Color
|
||||
|
||||
@ -24,7 +24,7 @@ data class TileDefinition(
|
||||
override val renderParameters: RenderParameters,
|
||||
) : IRenderableTile {
|
||||
companion object {
|
||||
val ADAPTER = KConcreteTypeAdapter.Builder(TileDefinition::class)
|
||||
val ADAPTER = FactoryAdapter.Builder(TileDefinition::class)
|
||||
.auto(
|
||||
TileDefinition::materialId,
|
||||
TileDefinition::materialName,
|
||||
|
@ -7,7 +7,7 @@ import com.google.gson.stream.JsonWriter
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.io.ColorTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.CustomEnumTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.KTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.BuilderAdapter
|
||||
import ru.dbotthepony.kvector.vector.Color
|
||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
@ -26,7 +26,7 @@ class SkyParameters {
|
||||
var seed = 0L
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::SkyParameters,
|
||||
val ADAPTER = BuilderAdapter(::SkyParameters,
|
||||
SkyParameters::spaceLevel,
|
||||
SkyParameters::ambientLightLevel,
|
||||
SkyParameters::skyType,
|
||||
@ -85,7 +85,7 @@ class SkyColoring {
|
||||
var nightLightColor = Color.TRANSLUCENT
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::SkyColoring,
|
||||
val ADAPTER = BuilderAdapter(::SkyColoring,
|
||||
SkyColoring::mainColor,
|
||||
SkyColoring::morningColors,
|
||||
SkyColoring::dayColors,
|
||||
@ -138,12 +138,12 @@ class SkySatellite {
|
||||
var layers = Array(0) { Layer() }
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::SkySatellite,
|
||||
val ADAPTER = BuilderAdapter(::SkySatellite,
|
||||
SkySatellite::pos,
|
||||
SkySatellite::layers,
|
||||
)
|
||||
|
||||
val LAYER_ADAPTER = KTypeAdapter(::Layer,
|
||||
val LAYER_ADAPTER = BuilderAdapter(::Layer,
|
||||
Layer::scale,
|
||||
Layer::image,
|
||||
Layer::hueShift,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package ru.dbotthepony.kstarbound.defs.world
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.io.json.KTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.BuilderAdapter
|
||||
|
||||
class WorldProperties {
|
||||
var nonCombat = false
|
||||
@ -13,7 +13,7 @@ class WorldProperties {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::WorldProperties,
|
||||
val ADAPTER = BuilderAdapter(::WorldProperties,
|
||||
WorldProperties::nonCombat,
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import com.google.gson.GsonBuilder
|
||||
import ru.dbotthepony.kstarbound.defs.world.SkyParameters
|
||||
import ru.dbotthepony.kstarbound.defs.world.WorldProperties
|
||||
import ru.dbotthepony.kstarbound.io.json.CustomEnumTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.KTypeAdapter
|
||||
import ru.dbotthepony.kstarbound.io.json.BuilderAdapter
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class DungeonWorldDef {
|
||||
@ -32,7 +32,7 @@ class DungeonWorldDef {
|
||||
var planetSize: String? = null
|
||||
|
||||
companion object {
|
||||
val ADAPTER = KTypeAdapter(::DungeonWorldDef,
|
||||
val ADAPTER = BuilderAdapter(::DungeonWorldDef,
|
||||
DungeonWorldDef::type,
|
||||
DungeonWorldDef::dungeonWorld,
|
||||
DungeonWorldDef::seed,
|
||||
|
@ -22,11 +22,9 @@ import kotlin.reflect.full.isSuperclassOf
|
||||
* Создаёт пустые классы, а после наполняет их данными, что подходит для builder'ов с очень
|
||||
* большим количеством возможных данных внутри.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Подходит для игровых структур которые могут быть "разобраны" и пересобраны.
|
||||
*/
|
||||
class KTypeAdapter<T>(val factory: () -> T, vararg fields: KMutableProperty1<T, *>) : TypeAdapter<T>() {
|
||||
class BuilderAdapter<T>(val factory: () -> T, vararg fields: KMutableProperty1<T, *>) : TypeAdapter<T>() {
|
||||
private val mappedFields = Object2ObjectArrayMap<String, KMutableProperty1<T, in Any?>>()
|
||||
// потому что returnType медленный
|
||||
private val mappedFieldsReturnTypes = Object2ObjectArrayMap<String, KType>()
|
||||
@ -52,7 +50,7 @@ class KTypeAdapter<T>(val factory: () -> T, vararg fields: KMutableProperty1<T,
|
||||
}
|
||||
}
|
||||
|
||||
fun ignoreProperty(vararg value: String): KTypeAdapter<T> {
|
||||
fun ignoreProperty(vararg value: String): BuilderAdapter<T> {
|
||||
ignoreProperties.addAll(value)
|
||||
return this
|
||||
}
|
||||
@ -60,12 +58,12 @@ class KTypeAdapter<T>(val factory: () -> T, vararg fields: KMutableProperty1<T,
|
||||
var missingPropertiesAreFatal = true
|
||||
var missingLogLevel = Level.ERROR
|
||||
|
||||
fun missingPropertiesAreFatal(flag: Boolean): KTypeAdapter<T> {
|
||||
fun missingPropertiesAreFatal(flag: Boolean): BuilderAdapter<T> {
|
||||
missingPropertiesAreFatal = flag
|
||||
return this
|
||||
}
|
||||
|
||||
fun missingLogLevel(level: Level): KTypeAdapter<T> {
|
||||
fun missingLogLevel(level: Level): BuilderAdapter<T> {
|
||||
missingLogLevel = level
|
||||
return this
|
||||
}
|
@ -38,7 +38,7 @@ private data class PackedProperty<Clazz : Any, T>(
|
||||
/**
|
||||
* TypeAdapter для классов которые создаются единожды и более не меняются ("бетонных классов").
|
||||
*/
|
||||
class KConcreteTypeAdapter<T : Any> private constructor(
|
||||
class FactoryAdapter<T : Any> private constructor(
|
||||
val bound: KClass<T>,
|
||||
private val types: ImmutableList<PackedProperty<T, *>>,
|
||||
val asJsonArray: Boolean,
|
||||
@ -354,7 +354,7 @@ class KConcreteTypeAdapter<T : Any> private constructor(
|
||||
}
|
||||
|
||||
/**
|
||||
* Позволяет построить класс [KConcreteTypeAdapter] на основе заданных параметров
|
||||
* Позволяет построить класс [FactoryAdapter] на основе заданных параметров
|
||||
*/
|
||||
class Builder<T : Any>(val clazz: KClass<T>) {
|
||||
private val types = ArrayList<PackedProperty<T, *>>()
|
||||
@ -489,8 +489,8 @@ class KConcreteTypeAdapter<T : Any> private constructor(
|
||||
return this
|
||||
}
|
||||
|
||||
fun build(): KConcreteTypeAdapter<T> {
|
||||
return KConcreteTypeAdapter(
|
||||
fun build(): FactoryAdapter<T> {
|
||||
return FactoryAdapter(
|
||||
bound = clazz,
|
||||
types = ImmutableList.copyOf(types),
|
||||
asJsonArray = asList,
|
Loading…
Reference in New Issue
Block a user