Недо-чтение партиклей, Either<>
This commit is contained in:
parent
8540448bdc
commit
d44fd8d6c1
@ -176,6 +176,8 @@ fun main() {
|
|||||||
item.spawn()
|
item.spawn()
|
||||||
item.movement.applyVelocity(Vector2d(rand.nextDouble() * 1000.0 - 500.0, rand.nextDouble() * 1000.0 - 500.0))
|
item.movement.applyVelocity(Vector2d(rand.nextDouble() * 1000.0 - 500.0, rand.nextDouble() * 1000.0 - 500.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// println(Starbound.statusEffects["firecharge"])
|
||||||
}
|
}
|
||||||
|
|
||||||
//ent.position += Vector2d(y = 14.0, x = -10.0)
|
//ent.position += Vector2d(y = 14.0, x = -10.0)
|
||||||
|
@ -31,11 +31,13 @@ import ru.dbotthepony.kstarbound.defs.item.LiquidItemPrototype
|
|||||||
import ru.dbotthepony.kstarbound.defs.item.MaterialItemPrototype
|
import ru.dbotthepony.kstarbound.defs.item.MaterialItemPrototype
|
||||||
import ru.dbotthepony.kstarbound.defs.liquid.LiquidDefinition
|
import ru.dbotthepony.kstarbound.defs.liquid.LiquidDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.parallax.ParallaxPrototype
|
import ru.dbotthepony.kstarbound.defs.parallax.ParallaxPrototype
|
||||||
|
import ru.dbotthepony.kstarbound.defs.particle.ParticleDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.player.PlayerDefinition
|
import ru.dbotthepony.kstarbound.defs.player.PlayerDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.projectile.*
|
import ru.dbotthepony.kstarbound.defs.projectile.*
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
||||||
import ru.dbotthepony.kstarbound.io.*
|
import ru.dbotthepony.kstarbound.io.*
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.EitherTypeAdapter
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.EnumAdapter
|
import ru.dbotthepony.kstarbound.io.json.builder.EnumAdapter
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter
|
import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.FactoryAdapter
|
import ru.dbotthepony.kstarbound.io.json.builder.FactoryAdapter
|
||||||
@ -89,7 +91,11 @@ object Starbound {
|
|||||||
private val parallax = Object2ObjectOpenHashMap<String, ParallaxPrototype>()
|
private val parallax = Object2ObjectOpenHashMap<String, ParallaxPrototype>()
|
||||||
private val functions = Object2ObjectOpenHashMap<String, JsonFunction>()
|
private val functions = Object2ObjectOpenHashMap<String, JsonFunction>()
|
||||||
private val species = Object2ObjectOpenHashMap<String, Species>()
|
private val species = Object2ObjectOpenHashMap<String, Species>()
|
||||||
private val statusEffects = Object2ObjectOpenHashMap<String, StatusEffectDefinition>()
|
private val _statusEffects = Object2ObjectOpenHashMap<String, StatusEffectDefinition>()
|
||||||
|
private val _particles = Object2ObjectOpenHashMap<String, ParticleDefinition>()
|
||||||
|
|
||||||
|
val particles: Map<String, ParticleDefinition> = Collections.unmodifiableMap(_particles)
|
||||||
|
val statusEffects: Map<String, StatusEffectDefinition> = Collections.unmodifiableMap(_statusEffects)
|
||||||
|
|
||||||
private val items = Object2ObjectOpenHashMap<String, IItemDefinition>()
|
private val items = Object2ObjectOpenHashMap<String, IItemDefinition>()
|
||||||
|
|
||||||
@ -145,6 +151,8 @@ object Starbound {
|
|||||||
// автоматическое создание FactoryAdapter по @аннотациям
|
// автоматическое создание FactoryAdapter по @аннотациям
|
||||||
.registerTypeAdapterFactory(FactoryAdapter.Companion)
|
.registerTypeAdapterFactory(FactoryAdapter.Companion)
|
||||||
|
|
||||||
|
.registerTypeAdapterFactory(EitherTypeAdapter)
|
||||||
|
|
||||||
.also(::addStarboundJsonAdapters)
|
.also(::addStarboundJsonAdapters)
|
||||||
|
|
||||||
.registerTypeAdapterFactory(IItemDefinition.InventoryIcon.Factory(pathStack))
|
.registerTypeAdapterFactory(IItemDefinition.InventoryIcon.Factory(pathStack))
|
||||||
@ -170,7 +178,8 @@ object Starbound {
|
|||||||
.add(functions::get)
|
.add(functions::get)
|
||||||
.add(items::get)
|
.add(items::get)
|
||||||
.add(species::get)
|
.add(species::get)
|
||||||
.add(statusEffects::get)
|
.add(_statusEffects::get)
|
||||||
|
.add(_particles::get)
|
||||||
)
|
)
|
||||||
|
|
||||||
.create()
|
.create()
|
||||||
@ -430,8 +439,9 @@ object Starbound {
|
|||||||
loadStage(callback, TileDefinition::class.java, TileDefinition::materialName, tiles::put, TileDefinition::materialId, tilesByMaterialID::put, ext2files["material"] ?: listOf(), "materials")
|
loadStage(callback, TileDefinition::class.java, TileDefinition::materialName, tiles::put, TileDefinition::materialId, tilesByMaterialID::put, ext2files["material"] ?: listOf(), "materials")
|
||||||
loadStage(callback, MaterialModifier::class.java, MaterialModifier::modName, tileModifiers::put, MaterialModifier::modId, tileModifiersByID::put, ext2files["matmod"] ?: listOf(), "material modifier definitions")
|
loadStage(callback, MaterialModifier::class.java, MaterialModifier::modName, tileModifiers::put, MaterialModifier::modId, tileModifiersByID::put, ext2files["matmod"] ?: listOf(), "material modifier definitions")
|
||||||
loadStage(callback, LiquidDefinition::class.java, LiquidDefinition::name, liquid::put, LiquidDefinition::liquidId, liquidByID::put, ext2files["liquid"] ?: listOf(), "liquid definitions")
|
loadStage(callback, LiquidDefinition::class.java, LiquidDefinition::name, liquid::put, LiquidDefinition::liquidId, liquidByID::put, ext2files["liquid"] ?: listOf(), "liquid definitions")
|
||||||
loadStage(callback, StatusEffectDefinition::class.java, StatusEffectDefinition::name, statusEffects::put, ext2files["statuseffect"] ?: listOf(), "status effects")
|
loadStage(callback, StatusEffectDefinition::class.java, StatusEffectDefinition::name, _statusEffects::put, ext2files["statuseffect"] ?: listOf(), "status effects")
|
||||||
loadStage(callback, Species::class.java, Species::kind, species::put, ext2files["species"] ?: listOf(), "species")
|
loadStage(callback, Species::class.java, Species::kind, species::put, ext2files["species"] ?: listOf(), "species")
|
||||||
|
loadStage(callback, ParticleDefinition::class.java, ParticleDefinition::kind, _particles::put, ext2files["particle"] ?: listOf(), "particles")
|
||||||
|
|
||||||
pathStack.block("/") {
|
pathStack.block("/") {
|
||||||
playerDefinition = GSON.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java)
|
playerDefinition = GSON.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java)
|
||||||
|
@ -7,6 +7,7 @@ import com.google.gson.TypeAdapter
|
|||||||
import com.google.gson.TypeAdapterFactory
|
import com.google.gson.TypeAdapterFactory
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.google.gson.stream.JsonReader
|
import com.google.gson.stream.JsonReader
|
||||||
|
import com.google.gson.stream.JsonToken
|
||||||
import com.google.gson.stream.JsonWriter
|
import com.google.gson.stream.JsonWriter
|
||||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap
|
||||||
import java.lang.ref.Reference
|
import java.lang.ref.Reference
|
||||||
@ -45,12 +46,22 @@ class RegistryReferenceFactory : TypeAdapterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RegistryReferenceTypeAdapter<T>(val resolver: (String) -> T?, val strings: TypeAdapter<String>) : TypeAdapter<RegistryReference<T>>() {
|
class RegistryReferenceTypeAdapter<T>(val resolver: (String) -> T?, val strings: TypeAdapter<String>) : TypeAdapter<RegistryReference<T>>() {
|
||||||
override fun write(out: JsonWriter, value: RegistryReference<T>) {
|
override fun write(out: JsonWriter, value: RegistryReference<T>?) {
|
||||||
strings.write(out, value.name)
|
if (value == null)
|
||||||
|
out.nullValue()
|
||||||
|
else
|
||||||
|
strings.write(out, value.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun read(`in`: JsonReader): RegistryReference<T> {
|
override fun read(`in`: JsonReader): RegistryReference<T>? {
|
||||||
return RegistryReference(strings.read(`in`) ?: throw JsonSyntaxException("Can't have null as registry name"), resolver)
|
if (`in`.peek() == JsonToken.NULL)
|
||||||
|
return null
|
||||||
|
|
||||||
|
if (`in`.peek() == JsonToken.STRING) {
|
||||||
|
return RegistryReference(strings.read(`in`)!!, resolver)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw JsonSyntaxException("Expecting string for registry reference, ${`in`.peek()} given, near ${`in`.path}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,15 @@ package ru.dbotthepony.kstarbound.defs.animation
|
|||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
import ru.dbotthepony.kstarbound.defs.image.SpriteReference
|
import ru.dbotthepony.kstarbound.defs.image.SpriteReference
|
||||||
|
import ru.dbotthepony.kstarbound.defs.particle.ParticleEmitter
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kstarbound.util.Either
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
|
||||||
|
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class AnimationDefinition(
|
data class AnimationDefinition(
|
||||||
val animatedParts: AnimatedParts? = null,
|
val animatedParts: AnimatedParts? = null,
|
||||||
val sounds: ImmutableMap<String, Sound> = ImmutableMap.of(),
|
val sounds: ImmutableMap<String, Either<ImmutableList<String>, CustomSound>> = ImmutableMap.of(),
|
||||||
val transformationGroups: ImmutableMap<String, TransformConfig> = ImmutableMap.of(),
|
val transformationGroups: ImmutableMap<String, TransformConfig> = ImmutableMap.of(),
|
||||||
val particleEmitters: ImmutableMap<String, ParticleEmitter> = ImmutableMap.of(),
|
val particleEmitters: ImmutableMap<String, ParticleEmitter> = ImmutableMap.of(),
|
||||||
) {
|
) {
|
||||||
@ -19,27 +20,16 @@ data class AnimationDefinition(
|
|||||||
val interpolated: Boolean? = null
|
val interpolated: Boolean? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class Sound(
|
data class CustomSound(
|
||||||
// TODO
|
|
||||||
val sound: String? = null
|
val sound: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonFactory
|
|
||||||
data class ParticleEmitter(
|
|
||||||
val enabled: Boolean = true,
|
|
||||||
val emissionRate: Double = 1.0,
|
|
||||||
val count: Int = 1,
|
|
||||||
val offset: Vector2d? = null,
|
|
||||||
val offsetRegion: Vector4d? = null,
|
|
||||||
val transformationGroups: ImmutableList<String> = ImmutableList.of(),
|
|
||||||
val particles: ImmutableList<ParticleDefinition>
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class AnimatedParts(
|
data class AnimatedParts(
|
||||||
val stateTypes: ImmutableMap<String, StateType>,
|
val stateTypes: ImmutableMap<String, StateType> = ImmutableMap.of(),
|
||||||
val parts: ImmutableMap<String, Part>,
|
val parts: ImmutableMap<String, Part> = ImmutableMap.of(),
|
||||||
) {
|
) {
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class StateType(
|
data class StateType(
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package ru.dbotthepony.kstarbound.defs.animation
|
|
||||||
|
|
||||||
import ru.dbotthepony.kstarbound.defs.AssetReference
|
|
||||||
import ru.dbotthepony.kstarbound.defs.image.SpriteReference
|
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
|
||||||
|
|
||||||
@JsonFactory
|
|
||||||
data class ParticleDefinition(
|
|
||||||
val count: Int = 1,
|
|
||||||
val offset: Vector2d? = null,
|
|
||||||
val offsetRegion: Vector4d? = null,
|
|
||||||
val particle: Config,
|
|
||||||
) {
|
|
||||||
@JsonFactory
|
|
||||||
data class Config(
|
|
||||||
val type: ParticleType,
|
|
||||||
val animation: AssetReference<AnimationDefinition>? = null,
|
|
||||||
val image: SpriteReference? = null,
|
|
||||||
val position: Vector2d = Vector2d.ZERO,
|
|
||||||
val offsetRegion: Vector4d = Vector4d.ZERO,
|
|
||||||
val initialVelocity: Vector2d = Vector2d.ZERO,
|
|
||||||
val finalVelocity: Vector2d = Vector2d.ZERO,
|
|
||||||
val approach: Vector2d = Vector2d.ZERO,
|
|
||||||
val angularVelocity: Double = 0.0,
|
|
||||||
val destructionAction: DestructionAction? = null,
|
|
||||||
val destructionTime: Double? = null,
|
|
||||||
val fade: Double = 0.0,
|
|
||||||
val size: Double = 1.0,
|
|
||||||
val layer: ParticleLayer? = null,
|
|
||||||
val timeToLive: Double = 1.0,
|
|
||||||
val variance: Variance = Variance.EMPTY
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonFactory
|
|
||||||
data class Variance(
|
|
||||||
val initialVelocity: Vector2d = Vector2d.ZERO,
|
|
||||||
val position: Vector2d = Vector2d.ZERO,
|
|
||||||
val angularVelocity: Double = 0.0
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
val EMPTY = Variance()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,5 +2,7 @@ package ru.dbotthepony.kstarbound.defs.animation
|
|||||||
|
|
||||||
enum class ParticleType {
|
enum class ParticleType {
|
||||||
ANIMATED,
|
ANIMATED,
|
||||||
TEXTURED
|
TEXTURED,
|
||||||
|
EMBER,
|
||||||
|
TEXT
|
||||||
}
|
}
|
@ -23,12 +23,22 @@ data class SpriteReference(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Adapter(val remapper: AssetPathStack) : TypeAdapter<SpriteReference>() {
|
class Adapter(val remapper: AssetPathStack) : TypeAdapter<SpriteReference>() {
|
||||||
override fun write(out: JsonWriter, value: SpriteReference) {
|
override fun write(out: JsonWriter, value: SpriteReference?) {
|
||||||
out.value(value.image + ":" + value.sprite.raw)
|
if (value == null)
|
||||||
|
out.nullValue()
|
||||||
|
else
|
||||||
|
out.value(value.image + ":" + value.sprite.raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun read(`in`: JsonReader): SpriteReference {
|
override fun read(`in`: JsonReader): SpriteReference? {
|
||||||
return parse(remapper.remap(`in`.nextString()))
|
val value = `in`.nextString() ?: return null
|
||||||
|
|
||||||
|
// TODO: если нам надо принудительно удалить спрайт с вышестоящей ступени, как это сделать?
|
||||||
|
// а ещё, зачем вы это сделали.
|
||||||
|
if (value == "")
|
||||||
|
return null
|
||||||
|
|
||||||
|
return parse(remapper.remap(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.DestructionAction
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.ParticleLayer
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonImplementation
|
||||||
|
import ru.dbotthepony.kstarbound.util.ChainedProperty
|
||||||
|
import ru.dbotthepony.kstarbound.util.SBPattern
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
|
||||||
|
@JsonImplementation(ParticleConfig::class)
|
||||||
|
interface IParticleConfig : IParticleVariance {
|
||||||
|
val finalVelocity: Vector2d?
|
||||||
|
val destructionAction: DestructionAction?
|
||||||
|
val destructionTime: Double?
|
||||||
|
val fade: Double?
|
||||||
|
val layer: ParticleLayer?
|
||||||
|
val timeToLive: Double?
|
||||||
|
val variance: IParticleVariance?
|
||||||
|
val text: SBPattern?
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun chain(vararg particles: IParticleConfig): IParticleConfig {
|
||||||
|
val chain = IParticleVariance.chain(*particles)
|
||||||
|
@Suppress("name_shadowing")
|
||||||
|
val particles = ImmutableList.copyOf(particles)
|
||||||
|
|
||||||
|
return object : IParticleConfig, IParticleVariance by chain {
|
||||||
|
override val finalVelocity by ChainedProperty(IParticleConfig::finalVelocity, particles)
|
||||||
|
override val destructionAction by ChainedProperty(IParticleConfig::destructionAction, particles)
|
||||||
|
override val destructionTime by ChainedProperty(IParticleConfig::destructionTime, particles)
|
||||||
|
override val fade by ChainedProperty(IParticleConfig::fade, particles)
|
||||||
|
override val layer by ChainedProperty(IParticleConfig::layer, particles)
|
||||||
|
override val timeToLive by ChainedProperty(IParticleConfig::timeToLive, particles)
|
||||||
|
override val variance by ChainedProperty(IParticleConfig::variance, particles)
|
||||||
|
override val text by ChainedProperty(IParticleConfig::text, particles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonImplementation
|
||||||
|
import ru.dbotthepony.kstarbound.util.ChainedProperty
|
||||||
|
import ru.dbotthepony.kvector.vector.Color
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
||||||
|
|
||||||
|
@JsonImplementation(ParticleVariance::class)
|
||||||
|
interface IParticleVariance {
|
||||||
|
val offset: Vector2d?
|
||||||
|
val position: Vector2d?
|
||||||
|
val offsetRegion: Vector4d?
|
||||||
|
val initialVelocity: Vector2d?
|
||||||
|
val approach: Vector2d?
|
||||||
|
val angularVelocity: Double?
|
||||||
|
val size: Double?
|
||||||
|
val color: Color?
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun chain(vararg particles: IParticleVariance): IParticleVariance {
|
||||||
|
@Suppress("name_shadowing")
|
||||||
|
val particles = ImmutableList.copyOf(particles)
|
||||||
|
|
||||||
|
return object : IParticleVariance {
|
||||||
|
override val offset by ChainedProperty(IParticleVariance::offset, particles)
|
||||||
|
override val position by ChainedProperty(IParticleVariance::position, particles)
|
||||||
|
override val offsetRegion by ChainedProperty(IParticleVariance::offsetRegion, particles)
|
||||||
|
override val initialVelocity by ChainedProperty(IParticleVariance::initialVelocity, particles)
|
||||||
|
override val approach by ChainedProperty(IParticleVariance::approach, particles)
|
||||||
|
override val angularVelocity by ChainedProperty(IParticleVariance::angularVelocity, particles)
|
||||||
|
override val size by ChainedProperty(IParticleVariance::size, particles)
|
||||||
|
override val color by ChainedProperty(IParticleVariance::color, particles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.defs.AssetReference
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.DestructionAction
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.ParticleLayer
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.ParticleType
|
||||||
|
import ru.dbotthepony.kstarbound.defs.image.SpriteReference
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kstarbound.util.SBPattern
|
||||||
|
import ru.dbotthepony.kvector.vector.Color
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
||||||
|
|
||||||
|
@JsonFactory
|
||||||
|
data class ParticleConfig(
|
||||||
|
val type: ParticleType,
|
||||||
|
val animation: AssetReference<AnimationDefinition>? = null,
|
||||||
|
val image: SpriteReference? = null,
|
||||||
|
override val offset: Vector2d? = null,
|
||||||
|
override val position: Vector2d? = null,
|
||||||
|
override val offsetRegion: Vector4d? = null,
|
||||||
|
override val initialVelocity: Vector2d? = null,
|
||||||
|
override val finalVelocity: Vector2d? = null,
|
||||||
|
override val approach: Vector2d? = null,
|
||||||
|
override val angularVelocity: Double? = null,
|
||||||
|
override val destructionAction: DestructionAction? = null,
|
||||||
|
override val destructionTime: Double? = null,
|
||||||
|
override val fade: Double? = null,
|
||||||
|
override val size: Double? = null,
|
||||||
|
override val layer: ParticleLayer? = null,
|
||||||
|
override val timeToLive: Double? = null,
|
||||||
|
override val variance: IParticleVariance? = null,
|
||||||
|
override val color: Color? = null,
|
||||||
|
override val text: SBPattern? = null,
|
||||||
|
) : IParticleConfig
|
@ -0,0 +1,32 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.defs.RegistryReference
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.DestructionAction
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.ParticleLayer
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kstarbound.util.Either
|
||||||
|
import ru.dbotthepony.kvector.vector.Color
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
||||||
|
|
||||||
|
@JsonFactory
|
||||||
|
data class ParticleCreator(
|
||||||
|
val count: Int = 1,
|
||||||
|
val particle: Either<RegistryReference<ParticleDefinition>, IParticleConfig>,
|
||||||
|
|
||||||
|
//override val offset: Vector2d? = null,
|
||||||
|
//override val position: Vector2d? = null,
|
||||||
|
//override val offsetRegion: Vector4d? = null,
|
||||||
|
//override val initialVelocity: Vector2d? = null,
|
||||||
|
//override val finalVelocity: Vector2d? = null,
|
||||||
|
//override val approach: Vector2d? = null,
|
||||||
|
//override val angularVelocity: Double? = null,
|
||||||
|
//override val destructionAction: DestructionAction? = null,
|
||||||
|
//override val destructionTime: Double? = null,
|
||||||
|
//override val fade: Double? = null,
|
||||||
|
//override val size: Double? = null,
|
||||||
|
//override val layer: ParticleLayer? = null,
|
||||||
|
//override val timeToLive: Double? = null,
|
||||||
|
//override val variance: IParticleVariance? = null,
|
||||||
|
//override val color: Color? = null,
|
||||||
|
) //: IParticleConfig
|
@ -0,0 +1,9 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
|
||||||
|
@JsonFactory
|
||||||
|
data class ParticleDefinition(
|
||||||
|
val kind: String,
|
||||||
|
val definition: IParticleConfig
|
||||||
|
)
|
@ -0,0 +1,36 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.DestructionAction
|
||||||
|
import ru.dbotthepony.kstarbound.defs.animation.ParticleLayer
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kstarbound.util.SBPattern
|
||||||
|
import ru.dbotthepony.kvector.vector.Color
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
||||||
|
|
||||||
|
@JsonFactory
|
||||||
|
data class ParticleEmitter(
|
||||||
|
val enabled: Boolean = true,
|
||||||
|
val emissionRate: Double = 1.0,
|
||||||
|
val count: Int = 1,
|
||||||
|
val transformationGroups: ImmutableList<String> = ImmutableList.of(),
|
||||||
|
val particles: ImmutableList<ParticleCreator>,
|
||||||
|
|
||||||
|
override val offset: Vector2d? = null,
|
||||||
|
override val position: Vector2d? = null,
|
||||||
|
override val offsetRegion: Vector4d? = null,
|
||||||
|
override val initialVelocity: Vector2d? = null,
|
||||||
|
override val finalVelocity: Vector2d? = null,
|
||||||
|
override val approach: Vector2d? = null,
|
||||||
|
override val angularVelocity: Double? = null,
|
||||||
|
override val destructionAction: DestructionAction? = null,
|
||||||
|
override val destructionTime: Double? = null,
|
||||||
|
override val fade: Double? = null,
|
||||||
|
override val size: Double? = null,
|
||||||
|
override val layer: ParticleLayer? = null,
|
||||||
|
override val timeToLive: Double? = null,
|
||||||
|
override val variance: IParticleVariance? = null,
|
||||||
|
override val color: Color? = null,
|
||||||
|
override val text: SBPattern? = null,
|
||||||
|
) : IParticleConfig
|
@ -0,0 +1,18 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs.particle
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kvector.vector.Color
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
import ru.dbotthepony.kvector.vector.ndouble.Vector4d
|
||||||
|
|
||||||
|
@JsonFactory
|
||||||
|
data class ParticleVariance(
|
||||||
|
override val offset: Vector2d? = null,
|
||||||
|
override val position: Vector2d? = null,
|
||||||
|
override val offsetRegion: Vector4d? = null,
|
||||||
|
override val initialVelocity: Vector2d? = null,
|
||||||
|
override val approach: Vector2d? = null,
|
||||||
|
override val angularVelocity: Double? = null,
|
||||||
|
override val size: Double? = null,
|
||||||
|
override val color: Color? = null,
|
||||||
|
) : IParticleVariance
|
@ -0,0 +1,57 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.io.json
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonSyntaxException
|
||||||
|
import com.google.gson.TypeAdapter
|
||||||
|
import com.google.gson.TypeAdapterFactory
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import com.google.gson.stream.JsonReader
|
||||||
|
import com.google.gson.stream.JsonToken
|
||||||
|
import com.google.gson.stream.JsonWriter
|
||||||
|
import ru.dbotthepony.kstarbound.util.Either
|
||||||
|
import java.lang.reflect.ParameterizedType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* При объявлении [Either] для (де)сериализации *НЕОБХОДИМО* объявить
|
||||||
|
* такое *левое* свойство, которое имеет [TypeAdapter] который не "засоряет" JsonReader
|
||||||
|
*/
|
||||||
|
object EitherTypeAdapter : TypeAdapterFactory {
|
||||||
|
override fun <T : Any?> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {
|
||||||
|
if (type.rawType == Either::class.java) {
|
||||||
|
val params = type.type as? ParameterizedType ?: return null
|
||||||
|
val (left, right) = params.actualTypeArguments
|
||||||
|
|
||||||
|
return object : TypeAdapter<Either<Any?, Any?>>() {
|
||||||
|
private val leftAdapter = gson.getAdapter(TypeToken.get(left)) as TypeAdapter<Any?>
|
||||||
|
private val rightAdapter = gson.getAdapter(TypeToken.get(right)) as TypeAdapter<Any?>
|
||||||
|
|
||||||
|
override fun write(out: JsonWriter, value: Either<Any?, Any?>?) {
|
||||||
|
if (value == null)
|
||||||
|
out.nullValue()
|
||||||
|
else
|
||||||
|
value.consume({ leftAdapter.write(out, it) }, { rightAdapter.write(out, it) })
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(`in`: JsonReader): Either<Any?, Any?>? {
|
||||||
|
if (`in`.peek() == JsonToken.NULL)
|
||||||
|
return null
|
||||||
|
|
||||||
|
return try {
|
||||||
|
Either.left(leftAdapter.read(`in`))
|
||||||
|
} catch(leftError: Throwable) {
|
||||||
|
try {
|
||||||
|
Either.right(rightAdapter.read(`in`))
|
||||||
|
} catch(rightError: Throwable) {
|
||||||
|
val error = JsonSyntaxException("Can't read Either of values (left is $left, right is $right)")
|
||||||
|
error.addSuppressed(leftError)
|
||||||
|
error.addSuppressed(rightError)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as TypeAdapter<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,8 @@ class AssetPathStack(private val interner: Interner<String>? = null) {
|
|||||||
inline operator fun <T> invoke(path: String, block: (String) -> T) = block(path, block)
|
inline operator fun <T> invoke(path: String, block: (String) -> T) = block(path, block)
|
||||||
|
|
||||||
private fun remap(a: String, b: String): String {
|
private fun remap(a: String, b: String): String {
|
||||||
|
if (b.isEmpty())
|
||||||
|
return a
|
||||||
if (b[0] == '/')
|
if (b[0] == '/')
|
||||||
return b
|
return b
|
||||||
|
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.util
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
|
import java.util.*
|
||||||
|
import java.util.stream.Stream
|
||||||
|
import kotlin.properties.ReadOnlyProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class ChainedProperty<R, T>(private val getter: (R) -> T?, private val receivers: ImmutableList<R>) : ReadOnlyProperty<Any?, T?> {
|
||||||
|
constructor(getter: (R) -> T?, receivers: Stream<R>) : this(getter, receivers.collect(ImmutableList.toImmutableList()))
|
||||||
|
constructor(getter: (R) -> T?, receivers: Array<out R>) : this(getter, ImmutableList.copyOf(receivers))
|
||||||
|
constructor(getter: (R) -> T?, receivers: List<R>) : this(getter, ImmutableList.copyOf(receivers))
|
||||||
|
|
||||||
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||||
|
for (receiver in receivers) {
|
||||||
|
val value = getter.invoke(receiver)
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
34
src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt
Normal file
34
src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.util
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.io.json.EitherTypeAdapter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Представляет собой контейнер с "или тот или другой" значениями
|
||||||
|
*
|
||||||
|
* JSON адаптер реализуется через [EitherTypeAdapter]
|
||||||
|
*/
|
||||||
|
data class Either<L, R>(val left: L?, val right: R?) {
|
||||||
|
init {
|
||||||
|
require(left != null || right != null) { "Both inputs are null" }
|
||||||
|
require(!(left != null && right != null)) { "Both inputs are not null" }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun consume(left: (L) -> Unit, right: (R) -> Unit) {
|
||||||
|
if (this.left != null)
|
||||||
|
left.invoke(this.left)
|
||||||
|
else
|
||||||
|
right.invoke(this.right!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun <L, R> left(value: L): Either<L, R> {
|
||||||
|
return Either(left = value ?: throw NullPointerException("Left is null"), right = null)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun <L, R> right(value: R): Either<L, R> {
|
||||||
|
return Either(left = null, right = value ?: throw NullPointerException("Right is null"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -126,7 +126,11 @@ class SBPattern private constructor(
|
|||||||
val open = raw.indexOf('<', startIndex = i)
|
val open = raw.indexOf('<', startIndex = i)
|
||||||
|
|
||||||
if (open == -1) {
|
if (open == -1) {
|
||||||
pieces.add(Piece(contents = raw.substring(i)))
|
if (i == 0)
|
||||||
|
pieces.add(Piece(contents = raw))
|
||||||
|
else
|
||||||
|
pieces.add(Piece(contents = raw.substring(i)))
|
||||||
|
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
val closing = raw.indexOf('>', startIndex = open + 1)
|
val closing = raw.indexOf('>', startIndex = open + 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user