Rename proto classes to be more descriptive
This commit is contained in:
parent
aa9d379d41
commit
dcc06319c6
@ -252,7 +252,7 @@ object Starbound : IVFS {
|
||||
try {
|
||||
callback("Loading $listedFile")
|
||||
|
||||
val def = gson.fromJson(getReader(listedFile), ConfigurableProjectile::class.java).configure(getPathFolder(listedFile))
|
||||
val def = gson.fromJson(getReader(listedFile), ConfigurableProjectile::class.java).assemble(getPathFolder(listedFile))
|
||||
check(projectiles[def.projectileName] == null) { "Already has projectile with ID ${def.projectileName} loaded!" }
|
||||
projectiles[def.projectileName] = def
|
||||
} catch(err: Throwable) {
|
||||
|
@ -128,10 +128,10 @@ fun flattenMap(input: Map<String, Any>): Object2ObjectArrayMap<String, Any> {
|
||||
* Если границы поля зависят от других полей, то проверка такого поля должна осуществляться уже при самой
|
||||
* сборке прототипа.
|
||||
*/
|
||||
abstract class ConfigurableDefinition<Configurable : ConfigurableDefinition<Configurable, Configured>, Configured : ConfiguredDefinition<Configured, Configurable>> {
|
||||
abstract class RawPrototype<RAW : RawPrototype<RAW, ASSEMBLED>, ASSEMBLED : AssembledPrototype<ASSEMBLED, RAW>> {
|
||||
val json = Object2ObjectArrayMap<String, Any>()
|
||||
fun enroll() = enrollMap(json)
|
||||
abstract fun configure(directory: String = ""): Configured
|
||||
abstract fun assemble(directory: String = ""): ASSEMBLED
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,13 +139,13 @@ abstract class ConfigurableDefinition<Configurable : ConfigurableDefinition<Conf
|
||||
*
|
||||
* Должен иметь все поля объекта, которые будут использоваться движком напрямую
|
||||
*
|
||||
* Создается соответствующим [ConfigurableDefinition], который проверил уже все поля
|
||||
* Создается соответствующим [RawPrototype], который проверил уже все поля
|
||||
* на их правильность.
|
||||
*/
|
||||
abstract class ConfiguredDefinition<Configured : ConfiguredDefinition<Configured, Configurator>, Configurator : ConfigurableDefinition<Configurator, Configured>>(
|
||||
abstract class AssembledPrototype<ASSEMBLED : AssembledPrototype<ASSEMBLED, RAW>, RAW : RawPrototype<RAW, ASSEMBLED>>(
|
||||
val json: ImmutableMap<String, Any>
|
||||
) {
|
||||
open fun getParameter(key: String): Any? = json[key]
|
||||
fun flatten() = flattenMap(json)
|
||||
abstract fun reconfigure(): Configurator
|
||||
fun unroll() = flattenMap(json)
|
||||
abstract fun disassemble(): RAW
|
||||
}
|
@ -13,7 +13,7 @@ import ru.dbotthepony.kstarbound.io.CustomEnumTypeAdapter
|
||||
import ru.dbotthepony.kvector.vector.Color
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class ConfigurableProjectile : ConfigurableDefinition<ConfigurableProjectile, ConfiguredProjectile>() {
|
||||
class ConfigurableProjectile : RawPrototype<ConfigurableProjectile, ConfiguredProjectile>() {
|
||||
var projectileName by Delegates.notNull<String>()
|
||||
var physics: ProjectilePhysics = ProjectilePhysics.DEFAULT
|
||||
var damageKindImage: String? = null
|
||||
@ -46,7 +46,7 @@ class ConfigurableProjectile : ConfigurableDefinition<ConfigurableProjectile, Co
|
||||
var speed = 0.0
|
||||
var power = 0.0
|
||||
|
||||
override fun configure(directory: String): ConfiguredProjectile {
|
||||
override fun assemble(directory: String): ConfiguredProjectile {
|
||||
val actions = ArrayList<IActionOnReap>()
|
||||
|
||||
if (actionOnReap != null) {
|
||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.defs.projectile
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.defs.ConfiguredDefinition
|
||||
import ru.dbotthepony.kstarbound.defs.AssembledPrototype
|
||||
import ru.dbotthepony.kstarbound.defs.DamageType
|
||||
import ru.dbotthepony.kstarbound.defs.FrameSet
|
||||
import ru.dbotthepony.kstarbound.world.entities.projectile.AbstractProjectileMovementController
|
||||
@ -33,8 +33,8 @@ class ConfiguredProjectile(
|
||||
val piercing: Boolean,
|
||||
val speed: Double,
|
||||
val power: Double,
|
||||
) : ConfiguredDefinition<ConfiguredProjectile, ConfigurableProjectile>(json) {
|
||||
override fun reconfigure(): ConfigurableProjectile {
|
||||
) : AssembledPrototype<ConfiguredProjectile, ConfigurableProjectile>(json) {
|
||||
override fun disassemble(): ConfigurableProjectile {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.defs.ConfigurableDefinition
|
||||
import ru.dbotthepony.kstarbound.defs.RawPrototype
|
||||
import ru.dbotthepony.kstarbound.defs.flattenJsonElement
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
@ -20,7 +20,7 @@ import kotlin.reflect.full.isSuperclassOf
|
||||
/**
|
||||
* Kotlin property aware adapter with arbitrary structure writer
|
||||
*/
|
||||
class ConfigurableTypeAdapter<T : ConfigurableDefinition<*, *>>(val factory: () -> T, vararg fields: KMutableProperty1<T, *>) : TypeAdapter<T>() {
|
||||
class ConfigurableTypeAdapter<T : RawPrototype<*, *>>(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>()
|
||||
|
Loading…
Reference in New Issue
Block a user