diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt index 63bfdca6..a9821113 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt @@ -3,11 +3,9 @@ package ru.dbotthepony.kstarbound import com.google.gson.GsonBuilder import com.google.gson.JsonElement import com.google.gson.JsonObject -import com.google.gson.TypeAdapter import com.google.gson.TypeAdapterFactory import com.google.gson.stream.JsonReader import org.apache.logging.log4j.LogManager -import ru.dbotthepony.kommons.util.Either import ru.dbotthepony.kstarbound.defs.Json2Function import ru.dbotthepony.kstarbound.defs.JsonConfigFunction import ru.dbotthepony.kstarbound.defs.JsonFunction @@ -40,15 +38,13 @@ import ru.dbotthepony.kstarbound.defs.tile.TileDefinition import ru.dbotthepony.kstarbound.defs.world.BushVariant import ru.dbotthepony.kstarbound.defs.world.GrassVariant import ru.dbotthepony.kstarbound.defs.world.TreeVariant -import ru.dbotthepony.kstarbound.defs.world.terrain.BiomeDefinition +import ru.dbotthepony.kstarbound.defs.world.BiomeDefinition import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorFactory import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType import ru.dbotthepony.kstarbound.util.AssetPathStack import java.util.* import java.util.concurrent.CompletableFuture -import java.util.concurrent.ExecutorService import java.util.concurrent.Future -import java.util.function.Supplier import kotlin.collections.ArrayList object Registries { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 6ec8cc73..65c76188 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -37,9 +37,9 @@ import ru.dbotthepony.kstarbound.defs.animation.Particle import ru.dbotthepony.kstarbound.defs.item.ItemDescriptor import ru.dbotthepony.kstarbound.defs.world.CelestialParameters import ru.dbotthepony.kstarbound.defs.world.VisitableWorldParametersType -import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlaceables -import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlacementDistributionType -import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlacementItemType +import ru.dbotthepony.kstarbound.defs.world.BiomePlaceables +import ru.dbotthepony.kstarbound.defs.world.BiomePlacementDistributionType +import ru.dbotthepony.kstarbound.defs.world.BiomePlacementItemType import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType import ru.dbotthepony.kstarbound.io.* import ru.dbotthepony.kstarbound.json.factory.MapsTypeAdapterFactory diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/Biome.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/Biome.kt new file mode 100644 index 00000000..d227596f --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/Biome.kt @@ -0,0 +1,23 @@ +package ru.dbotthepony.kstarbound.defs.world + +import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.Registry +import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier +import ru.dbotthepony.kstarbound.defs.tile.TileDefinition +import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition +import ru.dbotthepony.kstarbound.defs.world.BiomePlaceables +import ru.dbotthepony.kstarbound.defs.world.Parallax + +data class Biome( + val hueShift: Double = 0.0, + val baseName: String, + val description: String, + val mainBlock: Registry.Entry? = null, + val subBlocks: ImmutableList> = ImmutableList.of(), + val ores: ImmutableList, Double>> = ImmutableList.of(), + val musicTrack: AmbientNoisesDefinition? = null, + val ambientNoises: AmbientNoisesDefinition? = null, + val surfacePlaceables: BiomePlaceables = BiomePlaceables(), + val undergroundPlaceables: BiomePlaceables = BiomePlaceables(), + val parallax: Parallax? = null, +) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomeDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomeDefinition.kt new file mode 100644 index 00000000..6c8f8370 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomeDefinition.kt @@ -0,0 +1,92 @@ +package ru.dbotthepony.kstarbound.defs.world + +import com.google.common.collect.ImmutableList +import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kommons.collect.filterNotNull +import ru.dbotthepony.kstarbound.Registries +import ru.dbotthepony.kstarbound.Registry +import ru.dbotthepony.kstarbound.Starbound +import ru.dbotthepony.kstarbound.collect.WeightedList +import ru.dbotthepony.kstarbound.defs.AssetReference +import ru.dbotthepony.kstarbound.defs.JsonConfigFunction +import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier +import ru.dbotthepony.kstarbound.defs.tile.TileDefinition +import ru.dbotthepony.kstarbound.json.builder.JsonFactory +import ru.dbotthepony.kstarbound.json.pairListAdapter +import ru.dbotthepony.kstarbound.util.random.random +import java.util.random.RandomGenerator + +@JsonFactory +data class BiomeDefinition( + val airless: Boolean = false, + val name: String, + val statusEffects: ImmutableSet = ImmutableSet.of(), + val weather: ImmutableList>>>> = ImmutableList.of(), // binned reference to other assets + val hueShiftOptions: ImmutableList = ImmutableList.of(), + val skyOptions: ImmutableList = ImmutableList.of(), + val description: String = "...", + val mainBlock: Registry.Ref? = null, + val subBlocks: ImmutableList>? = null, + val ores: Registry.Ref? = null, + val musicTrack: AmbientNoisesDefinition? = null, + val ambientNoises: AmbientNoisesDefinition? = null, + val surfacePlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(), + val undergroundPlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(), + val parallax: AssetReference? = null, +) { + data class CreationParams( + val hueShift: Double, + val random: RandomGenerator + ) + + fun skyColoring(random: RandomGenerator): SkyColoring { + if (skyOptions.isEmpty()) + return SkyColoring.BLACK + + return skyOptions.random(random) + } + + fun hueShift(random: RandomGenerator): Double { + if (hueShiftOptions.isEmpty()) + return 0.0 + + return hueShiftOptions.random(random) + } + + fun create(random: RandomGenerator, verticalMidPoint: Int, threatLevel: Double): Biome { + val hueShift = hueShift(random) + val data = CreationParams(hueShift = hueShift, random = random) + val surfacePlaceables = surfacePlaceables.create(data) + val undergroundPlaceables = undergroundPlaceables.create(data) + + return Biome( + baseName = name, + description = description, + hueShift = hueShift, + + mainBlock = mainBlock?.entry, + subBlocks = subBlocks?.stream()?.map { it.entry }?.filterNotNull()?.collect(ImmutableList.toImmutableList()) ?: ImmutableList.of(), + + musicTrack = musicTrack, + ambientNoises = ambientNoises, + surfacePlaceables = surfacePlaceables, + undergroundPlaceables = undergroundPlaceables, + + parallax = parallax?.value?.create(random, verticalMidPoint.toDouble(), hueShift, surfacePlaceables.firstTreeVariant()), + + ores = (ores?.value?.evaluate(threatLevel, oresAdapter)?.map { + it.stream() + .filter { it.second > 0.0 } + .map { Registries.tileModifiers[it.first] to it.second } + .filter { it.first != null } + .collect(ImmutableList.toImmutableList()) + }?.orElse(ImmutableList.of()) ?: ImmutableList.of()) as ImmutableList, Double>> + ) + } + + companion object { + private val oresAdapter by lazy { + Starbound.gson.pairListAdapter() + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/Biome.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceables.kt similarity index 85% rename from src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/Biome.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceables.kt index 05982285..34ae2f4e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/Biome.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceables.kt @@ -1,4 +1,4 @@ -package ru.dbotthepony.kstarbound.defs.world.terrain +package ru.dbotthepony.kstarbound.defs.world import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet @@ -20,15 +20,8 @@ import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.collect.WeightedList import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier -import ru.dbotthepony.kstarbound.defs.tile.TileDefinition -import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition -import ru.dbotthepony.kstarbound.defs.world.BushVariant -import ru.dbotthepony.kstarbound.defs.world.GrassVariant -import ru.dbotthepony.kstarbound.defs.world.Parallax -import ru.dbotthepony.kstarbound.defs.world.TreeVariant import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kstarbound.json.builder.JsonImplementation import ru.dbotthepony.kstarbound.json.listAdapter import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise import java.util.stream.Stream @@ -109,7 +102,9 @@ data class BiomePlaceables( // Truly our hero here. val obj = when (val type = `in`.nextString()) { "treasureBoxSet" -> TreasureBox(`in`.nextString()) - "microDungeon" -> MicroDungeon(arrays.read(`in`).stream().map { it.asString }.collect(ImmutableSet.toImmutableSet())) + "microDungeon" -> MicroDungeon(arrays.read(`in`).stream().map { it.asString }.collect( + ImmutableSet.toImmutableSet() + )) "grass" -> Grass(grassVariant.read(`in`)) "bush" -> Bush(bushVariant.read(`in`)) "tree" -> Tree(trees.read(`in`)) @@ -171,7 +166,10 @@ data class BiomePlaceables( get() = BiomePlacementItemType.TREE override fun toJson(): JsonElement { - return Starbound.gson.toJsonTree(trees, TypeToken.getParameterized(ImmutableList::class.java, TreeVariant::class.java).type) + return Starbound.gson.toJsonTree(trees, TypeToken.getParameterized( + ImmutableList::class.java, + TreeVariant::class.java + ).type) } } @@ -224,18 +222,4 @@ data class BiomePlaceables( return weightedItems.stream().map { it.first } } } -} - -data class Biome( - val hueShift: Double = 0.0, - val baseName: String, - val description: String, - val mainBlock: Registry.Entry? = null, - val subBlocks: ImmutableList> = ImmutableList.of(), - val ores: ImmutableList, Double>> = ImmutableList.of(), - val musicTrack: AmbientNoisesDefinition? = null, - val ambientNoises: AmbientNoisesDefinition? = null, - val surfacePlaceables: BiomePlaceables = BiomePlaceables(), - val undergroundPlaceables: BiomePlaceables = BiomePlaceables(), - val parallax: Parallax? = null, -) +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/BiomeDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceablesDefinition.kt similarity index 59% rename from src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/BiomeDefinition.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceablesDefinition.kt index 13da7f35..34b18d58 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/terrain/BiomeDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlaceablesDefinition.kt @@ -1,81 +1,24 @@ -package ru.dbotthepony.kstarbound.defs.world.terrain +package ru.dbotthepony.kstarbound.defs.world import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet import com.google.gson.JsonElement import com.google.gson.JsonObject -import com.google.gson.reflect.TypeToken -import com.google.gson.stream.JsonWriter import ru.dbotthepony.kommons.collect.filterNotNull import ru.dbotthepony.kommons.vector.Vector2i -import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.Registry -import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.collect.WeightedList import ru.dbotthepony.kstarbound.defs.AssetReference -import ru.dbotthepony.kstarbound.defs.JsonConfigFunction import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier -import ru.dbotthepony.kstarbound.defs.tile.TileDefinition -import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition -import ru.dbotthepony.kstarbound.defs.world.BushVariant -import ru.dbotthepony.kstarbound.defs.world.GrassVariant -import ru.dbotthepony.kstarbound.defs.world.Parallax -import ru.dbotthepony.kstarbound.defs.world.SkyColoring -import ru.dbotthepony.kstarbound.defs.world.TreeVariant -import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter -import ru.dbotthepony.kstarbound.json.builder.IStringSerializable import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat import ru.dbotthepony.kstarbound.json.builder.JsonSingleton -import ru.dbotthepony.kstarbound.json.pairListAdapter import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise import ru.dbotthepony.kstarbound.util.random.nextRange import ru.dbotthepony.kstarbound.util.random.random -import java.util.random.RandomGenerator import java.util.stream.IntStream -enum class BiomePlacementDistributionType( - override val jsonName: String, - val def: TypeToken, - val data: TypeToken, -) : IStringSerializable { - RANDOM("random", TypeToken.get(BiomePlaceablesDefinition.RandomDistribution::class.java), TypeToken.get(BiomePlaceables.RandomDistribution::class.java)), - PERIODIC("periodic", TypeToken.get(BiomePlaceablesDefinition.PeriodicDistribution::class.java), TypeToken.get(BiomePlaceables.PeriodicDistribution::class.java)); - - override fun match(name: String): Boolean { - return name.lowercase() == jsonName - } - - companion object { - val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries) - val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries) - } -} - -enum class BiomePlacementItemType( - override val jsonName: String, - val def: TypeToken, - val data: TypeToken, -) : IStringSerializable { - MICRO_DUNGEON("microdungeon", TypeToken.get(BiomePlaceablesDefinition.MicroDungeon::class.java), TypeToken.get(BiomePlaceables.MicroDungeon::class.java)), - TREASURE_BOX_SET("treasurebox", TypeToken.get(BiomePlaceablesDefinition.TreasureBox::class.java), TypeToken.get(BiomePlaceables.TreasureBox::class.java)), - GRASS("grass", TypeToken.get(BiomePlaceablesDefinition.Grass::class.java), TypeToken.get(BiomePlaceables.Grass::class.java)), - BUSH("bush", TypeToken.get(BiomePlaceablesDefinition.Bush::class.java), TypeToken.get(BiomePlaceables.Bush::class.java)), - TREE("tree", TypeToken.get(BiomePlaceablesDefinition.Tree::class.java), TypeToken.get(BiomePlaceables.Tree::class.java)), - OBJECT("object", TypeToken.get(BiomePlaceablesDefinition.Object::class.java), TypeToken.get(BiomePlaceables.Object::class.java)), - ; - - override fun match(name: String): Boolean { - return name.lowercase() == jsonName - } - - companion object { - val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries) - val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries) - } -} - @JsonFactory data class BiomePlaceablesDefinition( val grassMod: ImmutableList> = ImmutableList.of(), @@ -149,7 +92,7 @@ data class BiomePlaceablesDefinition( throw NoSuchElementException("None of grass variants are valid (candidates: $grasses)") } - return BiomePlaceables.Grass(GrassVariant.create(valid.random(biome.random), biome.hueShift)) + return BiomePlaceables.Grass(GrassVariant.Companion.create(valid.random(biome.random), biome.hueShift)) } } @@ -211,14 +154,32 @@ data class BiomePlaceablesDefinition( if (foliage == null) { for (i2 in 0 until subTreeVariants) { - trees.add(TreeVariant.create(stem, if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(-1.0, 1.0))) + trees.add( + TreeVariant.create( + stem, + if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble( + -1.0, + 1.0 + ) + ) + ) } } else { for (i2 in 0 until subTreeVariants) { - trees.add(TreeVariant.create( - stem, if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(-1.0, 1.0), - foliage, if (sameFoliageHueShift) treeFoliageHueShift else treeFoliageHueShiftMax * biome.random.nextDouble(-1.0, 1.0) - )) + trees.add( + TreeVariant.create( + stem, + if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble( + -1.0, + 1.0 + ), + foliage, + if (sameFoliageHueShift) treeFoliageHueShift else treeFoliageHueShiftMax * biome.random.nextDouble( + -1.0, + 1.0 + ) + ) + ) } } } @@ -250,7 +211,14 @@ data class BiomePlaceablesDefinition( val data = name.entry!!.value val mod = if (data.mods.isNotEmpty()) data.mods.random(biome.random) else "" - return BiomePlaceables.Bush(BushVariant.create(name.entry!!, biome.random.nextDouble(-1.0, 1.0) * baseHueShiftMax, mod, biome.random.nextDouble(-1.0 * 1.0) * modHueShiftMax)) + return BiomePlaceables.Bush( + BushVariant.create( + name.entry!!, + biome.random.nextDouble(-1.0, 1.0) * baseHueShiftMax, + mod, + biome.random.nextDouble(-1.0 * 1.0) * modHueShiftMax + ) + ) } } @@ -268,7 +236,12 @@ data class BiomePlaceablesDefinition( } val rand = objectSets.random(biome.random) - return BiomePlaceables.Object(WeightedList(rand.pool.stream().map { it.first to (it.second to rand.parameters) }.collect(ImmutableList.toImmutableList()))) + return BiomePlaceables.Object( + WeightedList( + rand.pool.stream().map { it.first to (it.second to rand.parameters) } + .collect(ImmutableList.toImmutableList()) + ) + ) } } @@ -354,20 +327,22 @@ data class BiomePlaceablesDefinition( weightedItems = IntStream.range(0, self.variants) .mapToObj { self.data.create(biome) } - .map { it to AbstractPerlinNoise.of( - PerlinNoiseParameters( - type = noiseType, - scale = noiseScale, - octaves = octaves, - alpha = alpha, - beta = beta, + .map { + it to AbstractPerlinNoise.of( + PerlinNoiseParameters( + type = noiseType, + scale = noiseScale, + octaves = octaves, + alpha = alpha, + beta = beta, - frequency = 1.0 / typePeriod, - amplitude = 1.0, - bias = 0.0, - seed = biome.random.nextLong(), + frequency = 1.0 / typePeriod, + amplitude = 1.0, + bias = 0.0, + seed = biome.random.nextLong(), + ) ) - ) } + } .collect(ImmutableList.toImmutableList()) ) } @@ -384,79 +359,4 @@ data class BiomePlaceablesDefinition( .collect(ImmutableList.toImmutableList()) ) } -} - -@JsonFactory -data class BiomeDefinition( - val airless: Boolean = false, - val name: String, - val statusEffects: ImmutableSet = ImmutableSet.of(), - val weather: ImmutableList>>>> = ImmutableList.of(), // binned reference to other assets - val hueShiftOptions: ImmutableList = ImmutableList.of(), - val skyOptions: ImmutableList = ImmutableList.of(), - val description: String = "...", - val mainBlock: Registry.Ref? = null, - val subBlocks: ImmutableList>? = null, - val ores: Registry.Ref? = null, - val musicTrack: AmbientNoisesDefinition? = null, - val ambientNoises: AmbientNoisesDefinition? = null, - val surfacePlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(), - val undergroundPlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(), - val parallax: AssetReference? = null, -) { - data class CreationParams( - val hueShift: Double, - val random: RandomGenerator - ) - - fun skyColoring(random: RandomGenerator): SkyColoring { - if (skyOptions.isEmpty()) - return SkyColoring.BLACK - - return skyOptions.random(random) - } - - fun hueShift(random: RandomGenerator): Double { - if (hueShiftOptions.isEmpty()) - return 0.0 - - return hueShiftOptions.random(random) - } - - fun create(random: RandomGenerator, verticalMidPoint: Int, threatLevel: Double): Biome { - val hueShift = hueShift(random) - val data = CreationParams(hueShift = hueShift, random = random) - val surfacePlaceables = surfacePlaceables.create(data) - val undergroundPlaceables = undergroundPlaceables.create(data) - - return Biome( - baseName = name, - description = description, - hueShift = hueShift, - - mainBlock = mainBlock?.entry, - subBlocks = subBlocks?.stream()?.map { it.entry }?.filterNotNull()?.collect(ImmutableList.toImmutableList()) ?: ImmutableList.of(), - - musicTrack = musicTrack, - ambientNoises = ambientNoises, - surfacePlaceables = surfacePlaceables, - undergroundPlaceables = undergroundPlaceables, - - parallax = parallax?.value?.create(random, verticalMidPoint.toDouble(), hueShift, surfacePlaceables.firstTreeVariant()), - - ores = (ores?.value?.evaluate(threatLevel, oresAdapter)?.map { - it.stream() - .filter { it.second > 0.0 } - .map { Registries.tileModifiers[it.first] to it.second } - .filter { it.first != null } - .collect(ImmutableList.toImmutableList()) - }?.orElse(ImmutableList.of()) ?: ImmutableList.of()) as ImmutableList, Double>> - ) - } - - companion object { - private val oresAdapter by lazy { - Starbound.gson.pairListAdapter() - } - } -} +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementDistributionType.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementDistributionType.kt new file mode 100644 index 00000000..697f7c14 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementDistributionType.kt @@ -0,0 +1,29 @@ +package ru.dbotthepony.kstarbound.defs.world + +import com.google.gson.reflect.TypeToken +import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter +import ru.dbotthepony.kstarbound.json.builder.IStringSerializable + +enum class BiomePlacementDistributionType( + override val jsonName: String, + val def: TypeToken, + val data: TypeToken, +) : IStringSerializable { + RANDOM("random", + TypeToken.get(BiomePlaceablesDefinition.RandomDistribution::class.java), + TypeToken.get(BiomePlaceables.RandomDistribution::class.java) + ), + PERIODIC("periodic", + TypeToken.get(BiomePlaceablesDefinition.PeriodicDistribution::class.java), + TypeToken.get(BiomePlaceables.PeriodicDistribution::class.java) + ); + + override fun match(name: String): Boolean { + return name.lowercase() == jsonName + } + + companion object { + val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries) + val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementItemType.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementItemType.kt new file mode 100644 index 00000000..849f7462 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/BiomePlacementItemType.kt @@ -0,0 +1,46 @@ +package ru.dbotthepony.kstarbound.defs.world + +import com.google.gson.reflect.TypeToken +import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter +import ru.dbotthepony.kstarbound.json.builder.IStringSerializable + +enum class BiomePlacementItemType( + override val jsonName: String, + val def: TypeToken, + val data: TypeToken, +) : IStringSerializable { + MICRO_DUNGEON("microdungeon", + TypeToken.get(BiomePlaceablesDefinition.MicroDungeon::class.java), + TypeToken.get(BiomePlaceables.MicroDungeon::class.java) + ), + TREASURE_BOX_SET("treasurebox", + TypeToken.get(BiomePlaceablesDefinition.TreasureBox::class.java), + TypeToken.get(BiomePlaceables.TreasureBox::class.java) + ), + GRASS("grass", + TypeToken.get(BiomePlaceablesDefinition.Grass::class.java), + TypeToken.get(BiomePlaceables.Grass::class.java) + ), + BUSH("bush", + TypeToken.get(BiomePlaceablesDefinition.Bush::class.java), + TypeToken.get(BiomePlaceables.Bush::class.java) + ), + TREE("tree", + TypeToken.get(BiomePlaceablesDefinition.Tree::class.java), + TypeToken.get(BiomePlaceables.Tree::class.java) + ), + OBJECT("object", + TypeToken.get(BiomePlaceablesDefinition.Object::class.java), + TypeToken.get(BiomePlaceables.Object::class.java) + ), + ; + + override fun match(name: String): Boolean { + return name.lowercase() == jsonName + } + + companion object { + val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries) + val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldLayout.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldLayout.kt index 1872c1ac..6afff605 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldLayout.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldLayout.kt @@ -9,9 +9,6 @@ import it.unimi.dsi.fastutil.doubles.DoubleArrayList import it.unimi.dsi.fastutil.ints.IntArrayList import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import ru.dbotthepony.kommons.gson.JsonArrayCollector -import ru.dbotthepony.kommons.gson.contains -import ru.dbotthepony.kommons.gson.get -import ru.dbotthepony.kommons.gson.getArray import ru.dbotthepony.kommons.gson.set import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.kommons.util.AABBi @@ -22,10 +19,8 @@ import ru.dbotthepony.kstarbound.GlobalDefaults import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.defs.world.terrain.AbstractTerrainSelector -import ru.dbotthepony.kstarbound.defs.world.terrain.Biome import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorParameters import ru.dbotthepony.kstarbound.defs.world.terrain.createNamedTerrainSelector -import ru.dbotthepony.kstarbound.fromJson import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.util.ListInterner import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise