diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index d7780df2..1fd3643c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -779,6 +779,41 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("treeStemDirectory", this) { args -> + // String root.treeStemDirectory(String stemName) + TODO("treeStemDirectory") + } + + state.setTableFunction("treeFoliageDirectory", this) { args -> + // String root.treeFoliageDirectory(String foliageName) + TODO("treeFoliageDirectory") + } + + state.setTableFunction("collection", this) { args -> + // Collection root.collection(String collectionName) + TODO("collection") + } + + state.setTableFunction("collectables", this) { args -> + // List root.collectables(String collectionName) + TODO("collectables") + } + + state.setTableFunction("elementalResistance", this) { args -> + // String root.elementalResistance(String elementalType) + TODO("elementalResistance") + } + + state.setTableFunction("dungeonMetadata", this) { args -> + // Json root.dungeonMetadata(String dungeonName) + TODO("dungeonMetadata") + } + + state.setTableFunction("behavior", this) { args -> + // BehaviorState root.behavior(`LuaTable` context, Json config, `JsonObject` parameters) + TODO("behavior") + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt index 4f494680..a2125356 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt @@ -65,7 +65,7 @@ class TreasurePoolDefinition(pieces: List) { for (round in 0 until rounds) { for (entry in fill) { - entry.map(left = { + entry.run(left = { val stack = it.makeStack() if (stack.isNotEmpty) result.add(stack) }, right = { @@ -78,7 +78,7 @@ class TreasurePoolDefinition(pieces: List) { for (entry in pool) { if (chosen <= entry.weight) { - entry.treasure.map(left = { + entry.treasure.run(left = { val stack = it.makeStack() if (stack.isNotEmpty) result.add(stack) }, right = { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt index 16547893..5b690ce2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt @@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.defs.particle import com.google.common.collect.ImmutableList import ru.dbotthepony.kstarbound.defs.animation.DestructionAction import ru.dbotthepony.kstarbound.io.json.builder.JsonImplementation -import ru.dbotthepony.kstarbound.util.ChainedProperty +import ru.dbotthepony.kstarbound.util.VirtualProperty import ru.dbotthepony.kstarbound.util.SBPattern import ru.dbotthepony.kvector.vector.ndouble.Vector2d @@ -25,14 +25,14 @@ interface IParticleConfig : IParticleVariance { 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) + override val finalVelocity by VirtualProperty(IParticleConfig::finalVelocity, particles) + override val destructionAction by VirtualProperty(IParticleConfig::destructionAction, particles) + override val destructionTime by VirtualProperty(IParticleConfig::destructionTime, particles) + override val fade by VirtualProperty(IParticleConfig::fade, particles) + override val layer by VirtualProperty(IParticleConfig::layer, particles) + override val timeToLive by VirtualProperty(IParticleConfig::timeToLive, particles) + override val variance by VirtualProperty(IParticleConfig::variance, particles) + override val text by VirtualProperty(IParticleConfig::text, particles) } } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt index cc5ccf9e..53b4c688 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt @@ -2,7 +2,7 @@ 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.kstarbound.util.VirtualProperty import ru.dbotthepony.kvector.vector.Color import ru.dbotthepony.kvector.vector.ndouble.Vector2d import ru.dbotthepony.kvector.vector.ndouble.Vector4d @@ -24,14 +24,14 @@ interface IParticleVariance { 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) + override val offset by VirtualProperty(IParticleVariance::offset, particles) + override val position by VirtualProperty(IParticleVariance::position, particles) + override val offsetRegion by VirtualProperty(IParticleVariance::offsetRegion, particles) + override val initialVelocity by VirtualProperty(IParticleVariance::initialVelocity, particles) + override val approach by VirtualProperty(IParticleVariance::approach, particles) + override val angularVelocity by VirtualProperty(IParticleVariance::angularVelocity, particles) + override val size by VirtualProperty(IParticleVariance::size, particles) + override val color by VirtualProperty(IParticleVariance::color, particles) } } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt index 0d304fcd..ca6eb7bd 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt @@ -29,7 +29,7 @@ object EitherTypeAdapter : TypeAdapterFactory { if (value == null) out.nullValue() else - value.map({ leftAdapter.write(out, it) }, { rightAdapter.write(out, it) }) + value.run({ leftAdapter.write(out, it) }, { rightAdapter.write(out, it) }) } override fun read(`in`: JsonReader): Either? { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt index 8bcb0a65..0cf8051f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt @@ -13,7 +13,7 @@ data class Either(val left: L?, val right: R?) { require(!(left != null && right != null)) { "Both inputs are not null" } } - inline fun map(left: (L) -> Unit, right: (R) -> Unit) { + inline fun run(left: (L) -> Unit, right: (R) -> Unit) { if (this.left != null) left.invoke(this.left) else diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/ChainedProperty.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/VirtualProperty.kt similarity index 90% rename from src/main/kotlin/ru/dbotthepony/kstarbound/util/ChainedProperty.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/util/VirtualProperty.kt index 2838036f..f39057fc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/ChainedProperty.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/VirtualProperty.kt @@ -1,12 +1,11 @@ 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(private val getter: (R) -> T?, private val receivers: ImmutableList) : ReadOnlyProperty { +class VirtualProperty(private val getter: (R) -> T?, private val receivers: ImmutableList) : ReadOnlyProperty { constructor(getter: (R) -> T?, receivers: Stream) : this(getter, receivers.collect(ImmutableList.toImmutableList())) constructor(getter: (R) -> T?, receivers: Array) : this(getter, ImmutableList.copyOf(receivers)) constructor(getter: (R) -> T?, receivers: List) : this(getter, ImmutableList.copyOf(receivers))