All composing terrain selectors now can reference other terrain selectors by name
This commit is contained in:
parent
edf33ca224
commit
8f407465f5
@ -13,6 +13,9 @@ This document briefly documents what have been added (or removed) regarding modd
|
|||||||
* Perlin noise now can be of arbitrary scale (defaults to `512`, specified with `scale` key, integer type, 2048>=x>=16)
|
* Perlin noise now can be of arbitrary scale (defaults to `512`, specified with `scale` key, integer type, 2048>=x>=16)
|
||||||
|
|
||||||
#### Terrain
|
#### Terrain
|
||||||
|
* All composing terrain selectors (such as `min`, `displacement`, `rotate`, etc) now can reference other terrain selectors by name (the `.terrain` files) instead of embedding entire config inside them
|
||||||
|
* They can be referenced by either specifying corresponding field as string, or as object like so: `{"name": "namedselector"}`
|
||||||
|
* `min`, `max` and `minmax` terrain selectors now also accept next format: `{"name": "namedselector", "seedBias": 4}`
|
||||||
* `mix` terrain selector got `mixSeedBias`, `aSeedBias` and `bSeedBias` fields, whose deviate respective selectors seeds (default to `0`)
|
* `mix` terrain selector got `mixSeedBias`, `aSeedBias` and `bSeedBias` fields, whose deviate respective selectors seeds (default to `0`)
|
||||||
* `displacement` terrain selector has `seedBias` added, which deviate seed of `source` selector (default to `0`)
|
* `displacement` terrain selector has `seedBias` added, which deviate seed of `source` selector (default to `0`)
|
||||||
* `displacement` terrain selector has `xClamp` added, works like `yClamp`
|
* `displacement` terrain selector has `xClamp` added, works like `yClamp`
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.terrain
|
package ru.dbotthepony.kstarbound.world.terrain
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import ru.dbotthepony.kommons.gson.get
|
import ru.dbotthepony.kommons.gson.get
|
||||||
import ru.dbotthepony.kstarbound.defs.world.TerrainSelectorParameters
|
import ru.dbotthepony.kstarbound.defs.world.TerrainSelectorParameters
|
||||||
@ -8,7 +9,7 @@ import ru.dbotthepony.kstarbound.json.builder.JsonFactory
|
|||||||
|
|
||||||
sealed class ComparingTerrainSelector(data: Data, parameters: TerrainSelectorParameters) : AbstractTerrainSelector<ComparingTerrainSelector.Data>(data, parameters) {
|
sealed class ComparingTerrainSelector(data: Data, parameters: TerrainSelectorParameters) : AbstractTerrainSelector<ComparingTerrainSelector.Data>(data, parameters) {
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class Data(val sources: ImmutableList<JsonObject>)
|
data class Data(val sources: ImmutableList<JsonElement>)
|
||||||
|
|
||||||
protected val sources = ArrayList<AbstractTerrainSelector<*>>()
|
protected val sources = ArrayList<AbstractTerrainSelector<*>>()
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ sealed class ComparingTerrainSelector(data: Data, parameters: TerrainSelectorPar
|
|||||||
require(data.sources.isNotEmpty()) { "'sources' array is empty" }
|
require(data.sources.isNotEmpty()) { "'sources' array is empty" }
|
||||||
|
|
||||||
for (source in data.sources) {
|
for (source in data.sources) {
|
||||||
sources.add(TerrainSelectorType.create(source, parameters.withSeed(parameters.seed + source.get("seedBias", 0L))))
|
sources.add(TerrainSelectorType.create(source, parameters.withSeed(parameters.seed + if (source is JsonObject) source.get("seedBias", 0L) else 0L)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.terrain
|
package ru.dbotthepony.kstarbound.world.terrain
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import ru.dbotthepony.kommons.vector.Vector2d
|
import ru.dbotthepony.kommons.vector.Vector2d
|
||||||
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
|
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
|
||||||
@ -41,7 +42,7 @@ class DisplacementTerrainSelector(data: Data, parameters: TerrainSelectorParamet
|
|||||||
val xClampSmoothing: Double = 0.0,
|
val xClampSmoothing: Double = 0.0,
|
||||||
|
|
||||||
val seedBias: Long = 0L,
|
val seedBias: Long = 0L,
|
||||||
val source: JsonObject,
|
val source: JsonElement,
|
||||||
)
|
)
|
||||||
|
|
||||||
val xFn: AbstractPerlinNoise
|
val xFn: AbstractPerlinNoise
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.terrain
|
package ru.dbotthepony.kstarbound.world.terrain
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import ru.dbotthepony.kommons.math.linearInterpolation
|
import ru.dbotthepony.kommons.math.linearInterpolation
|
||||||
import ru.dbotthepony.kstarbound.defs.world.TerrainSelectorParameters
|
import ru.dbotthepony.kstarbound.defs.world.TerrainSelectorParameters
|
||||||
@ -8,11 +9,11 @@ import ru.dbotthepony.kstarbound.json.builder.JsonFactory
|
|||||||
class MixTerrainSelector(data: Data, parameters: TerrainSelectorParameters) : AbstractTerrainSelector<MixTerrainSelector.Data>(data, parameters) {
|
class MixTerrainSelector(data: Data, parameters: TerrainSelectorParameters) : AbstractTerrainSelector<MixTerrainSelector.Data>(data, parameters) {
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class Data(
|
data class Data(
|
||||||
val mixSource: JsonObject,
|
val mixSource: JsonElement,
|
||||||
val mixSeedBias: Long = 0L,
|
val mixSeedBias: Long = 0L,
|
||||||
val aSource: JsonObject,
|
val aSource: JsonElement,
|
||||||
val aSeedBias: Long = 0L,
|
val aSeedBias: Long = 0L,
|
||||||
val bSource: JsonObject,
|
val bSource: JsonElement,
|
||||||
val bSeedBias: Long = 0L,
|
val bSeedBias: Long = 0L,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.terrain
|
package ru.dbotthepony.kstarbound.world.terrain
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonSyntaxException
|
import com.google.gson.JsonSyntaxException
|
||||||
import com.google.gson.TypeAdapter
|
import com.google.gson.TypeAdapter
|
||||||
@ -9,6 +10,7 @@ import com.google.gson.reflect.TypeToken
|
|||||||
import com.google.gson.stream.JsonReader
|
import com.google.gson.stream.JsonReader
|
||||||
import com.google.gson.stream.JsonWriter
|
import com.google.gson.stream.JsonWriter
|
||||||
import ru.dbotthepony.kommons.gson.consumeNull
|
import ru.dbotthepony.kommons.gson.consumeNull
|
||||||
|
import ru.dbotthepony.kommons.gson.contains
|
||||||
import ru.dbotthepony.kommons.gson.value
|
import ru.dbotthepony.kommons.gson.value
|
||||||
import ru.dbotthepony.kstarbound.Registries
|
import ru.dbotthepony.kstarbound.Registries
|
||||||
import ru.dbotthepony.kstarbound.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
@ -95,8 +97,16 @@ enum class TerrainSelectorType(val jsonName: String, private val data: Data<*, *
|
|||||||
throw IllegalArgumentException("Unknown terrain selector type $type")
|
throw IllegalArgumentException("Unknown terrain selector type $type")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create(json: JsonObject, parameters: TerrainSelectorParameters): AbstractTerrainSelector<*> {
|
fun create(json: JsonElement, parameters: TerrainSelectorParameters): AbstractTerrainSelector<*> {
|
||||||
return factory(json, false).create(parameters)
|
if (json is JsonObject) {
|
||||||
|
if ("name" in json) {
|
||||||
|
return named(json["name"].asString, parameters)
|
||||||
|
} else {
|
||||||
|
return factory(json, false).create(parameters)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return named(json.asString, parameters)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun load(json: JsonObject): AbstractTerrainSelector<*> {
|
fun load(json: JsonObject): AbstractTerrainSelector<*> {
|
||||||
|
Loading…
Reference in New Issue
Block a user