Misc fixes
This commit is contained in:
parent
60fb895fe8
commit
21fcad14b3
@ -65,6 +65,7 @@ import ru.dbotthepony.kstarbound.math.Vector3iTypeAdapter
|
|||||||
import ru.dbotthepony.kstarbound.math.Vector4dTypeAdapter
|
import ru.dbotthepony.kstarbound.math.Vector4dTypeAdapter
|
||||||
import ru.dbotthepony.kstarbound.math.Vector4fTypeAdapter
|
import ru.dbotthepony.kstarbound.math.Vector4fTypeAdapter
|
||||||
import ru.dbotthepony.kstarbound.math.Vector4iTypeAdapter
|
import ru.dbotthepony.kstarbound.math.Vector4iTypeAdapter
|
||||||
|
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
||||||
import ru.dbotthepony.kstarbound.util.BlockableEventLoop
|
import ru.dbotthepony.kstarbound.util.BlockableEventLoop
|
||||||
import ru.dbotthepony.kstarbound.util.ExecutorWithScheduler
|
import ru.dbotthepony.kstarbound.util.ExecutorWithScheduler
|
||||||
import ru.dbotthepony.kstarbound.util.Directives
|
import ru.dbotthepony.kstarbound.util.Directives
|
||||||
@ -433,6 +434,14 @@ object Starbound : BlockableEventLoop("Universe Thread"), Scheduler, ISBFileLoca
|
|||||||
return JsonPath.query(jsonPath).get(json)
|
return JsonPath.query(jsonPath).get(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun loadJsonAsset(path: JsonElement, relative: String): JsonElement? {
|
||||||
|
if (path is JsonPrimitive) {
|
||||||
|
return loadJsonAsset(AssetPathStack.relativeTo(relative, path.asString))
|
||||||
|
} else {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val fileSystems = ArrayList<IStarboundFile>()
|
private val fileSystems = ArrayList<IStarboundFile>()
|
||||||
private val toLoadPaks = ObjectArraySet<File>()
|
private val toLoadPaks = ObjectArraySet<File>()
|
||||||
private val toLoadPaths = ObjectArraySet<File>()
|
private val toLoadPaths = ObjectArraySet<File>()
|
||||||
@ -573,7 +582,7 @@ object Starbound : BlockableEventLoop("Universe Thread"), Scheduler, ISBFileLoca
|
|||||||
// same assets from other PAKs
|
// same assets from other PAKs
|
||||||
fileSystems.forEach {
|
fileSystems.forEach {
|
||||||
it.explore { file ->
|
it.explore { file ->
|
||||||
if (file.isFile)
|
if (file.isFile && file.name.contains('.'))
|
||||||
fileTree.computeIfAbsent(file.name.substringAfterLast('.')) { HashSet() }.add(file)
|
fileTree.computeIfAbsent(file.name.substringAfterLast('.')) { HashSet() }.add(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -582,7 +591,7 @@ object Starbound : BlockableEventLoop("Universe Thread"), Scheduler, ISBFileLoca
|
|||||||
fileSystems.asReversed().forEach {
|
fileSystems.asReversed().forEach {
|
||||||
it.explore { file ->
|
it.explore { file ->
|
||||||
if (file.isFile && file.name.endsWith(".patch"))
|
if (file.isFile && file.name.endsWith(".patch"))
|
||||||
patchTree.computeIfAbsent(file.computeFullPath().substringAfterLast('.')) { ArrayList() }.add(file)
|
patchTree.computeIfAbsent(file.computeFullPath().substringBeforeLast('.')) { ArrayList() }.add(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import ru.dbotthepony.kstarbound.world.entities.tile.PlantPieceEntity
|
|||||||
import ru.dbotthepony.kstarbound.world.entities.tile.WorldObject
|
import ru.dbotthepony.kstarbound.world.entities.tile.WorldObject
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
enum class EntityType(override val jsonName: String, val storeName: String, val canBeCreatedByClient: Boolean, val canBeSpawnedByClient: Boolean) : IStringSerializable {
|
enum class EntityType(override val jsonName: String, val storeName: String, val canBeCreatedByClient: Boolean, val canBeSpawnedByClient: Boolean, val ephemeralIfSpawnedByClient: Boolean = true) : IStringSerializable {
|
||||||
PLANT("plant", "PlantEntity", false, false) {
|
PLANT("plant", "PlantEntity", false, false) {
|
||||||
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
||||||
return PlantEntity(stream, isLegacy)
|
return PlantEntity(stream, isLegacy)
|
||||||
@ -38,7 +38,7 @@ enum class EntityType(override val jsonName: String, val storeName: String, val
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
VEHICLE("vehicle", "VehicleEntity", false, true) {
|
VEHICLE("vehicle", "VehicleEntity", false, true, false) {
|
||||||
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
||||||
TODO("VEHICLE")
|
TODO("VEHICLE")
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ enum class EntityType(override val jsonName: String, val storeName: String, val
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ITEM_DROP("itemDrop", "ItemDropEntity", false, true) {
|
ITEM_DROP("itemDrop", "ItemDropEntity", false, true, false) {
|
||||||
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
||||||
return ItemDropEntity(stream, isLegacy)
|
return ItemDropEntity(stream, isLegacy)
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ enum class EntityType(override val jsonName: String, val storeName: String, val
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
STAGEHAND("stagehand", "StagehandEntity", false, false) {
|
STAGEHAND("stagehand", "StagehandEntity", true, true) {
|
||||||
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
override fun fromNetwork(stream: DataInputStream, isLegacy: Boolean): AbstractEntity {
|
||||||
TODO("STAGEHAND")
|
TODO("STAGEHAND")
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,7 @@ class ActiveItemStack(entry: ItemRegistry.Entry, config: JsonObject, parameters:
|
|||||||
val animator: Animator
|
val animator: Animator
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val animationPath = AssetPathStack.relativeTo(entry.directory, lookupProperty("animation").asString)
|
var animationConfig = Starbound.loadJsonAsset(lookupProperty("animation"), entry.directory) ?: JsonNull.INSTANCE
|
||||||
var animationConfig = Starbound.loadJsonAsset(animationPath) ?: JsonNull.INSTANCE
|
|
||||||
val animationCustom = lookupProperty("animationCustom")
|
val animationCustom = lookupProperty("animationCustom")
|
||||||
|
|
||||||
if (!animationCustom.isJsonNull) {
|
if (!animationCustom.isJsonNull) {
|
||||||
@ -41,13 +40,13 @@ class ActiveItemStack(entry: ItemRegistry.Entry, config: JsonObject, parameters:
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (animationCustom.isJsonNull) {
|
if (animationConfig.isJsonNull) {
|
||||||
animator = Animator()
|
animator = Animator()
|
||||||
} else {
|
} else {
|
||||||
animator = Animator(Starbound.gson.fromJson(animationConfig, AnimationDefinition::class.java))
|
animator = Animator(Starbound.gson.fromJson(animationConfig, AnimationDefinition::class.java))
|
||||||
}
|
}
|
||||||
} catch (err: Throwable) {
|
} catch (err: Throwable) {
|
||||||
throw RuntimeException("Unable to instance animator for ${entry.name} (animation config: $animationPath)", err)
|
throw RuntimeException("Unable to instance animator for ${entry.name} (animation config: ${lookupProperty("animation")})", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
networkElement.add(animator.networkGroup)
|
networkElement.add(animator.networkGroup)
|
||||||
|
@ -142,7 +142,7 @@ object ItemRegistry {
|
|||||||
for (file in files) {
|
for (file in files) {
|
||||||
futures.add(Starbound.EXECUTOR.submit {
|
futures.add(Starbound.EXECUTOR.submit {
|
||||||
try {
|
try {
|
||||||
val read = JsonPatch.apply(Starbound.ELEMENTS_ADAPTER.read(file.jsonReader()), patches[file.computeFullPath()]) as JsonObject
|
val read = JsonPatch.apply(Starbound.ELEMENTS_ADAPTER.read(file.jsonReader()), patches[file.computeFullPath()]).asJsonObject
|
||||||
val readData = data.fromJsonTree(read)
|
val readData = data.fromJsonTree(read)
|
||||||
|
|
||||||
tasks.add {
|
tasks.add {
|
||||||
|
@ -19,16 +19,26 @@ enum class JsonPatch(val key: String) {
|
|||||||
|
|
||||||
val get = path.find(base) ?: JsonNull.INSTANCE
|
val get = path.find(base) ?: JsonNull.INSTANCE
|
||||||
|
|
||||||
if (inverse && get == value) {
|
if (inverse) {
|
||||||
throw IllegalStateException("Expected $path to not contain $value")
|
if (value == JsonNull.INSTANCE && get != JsonNull.INSTANCE) {
|
||||||
} else if (!inverse && get != value && value != JsonNull.INSTANCE) {
|
throw IllegalStateException("Expected $path to not contain anything")
|
||||||
var text = get.toString()
|
} else if (value != JsonNull.INSTANCE && value == get) {
|
||||||
|
throw IllegalStateException("Expected $path to not contain $value")
|
||||||
if (text.length > 40) {
|
|
||||||
text = text.substring(0, 40) + "..."
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (value == JsonNull.INSTANCE && get == JsonNull.INSTANCE) {
|
||||||
|
throw IllegalStateException("Expected $path to contain anything")
|
||||||
|
} else if (value != JsonNull.INSTANCE && get == JsonNull.INSTANCE) {
|
||||||
|
throw IllegalStateException("Expected $path to contain '$value', but found nothing")
|
||||||
|
} else if (value != JsonNull.INSTANCE && get != JsonNull.INSTANCE && value != get) {
|
||||||
|
var text = get.toString()
|
||||||
|
|
||||||
throw IllegalStateException("Expected $path to contain $value, but found $text")
|
if (text.length > 40) {
|
||||||
|
text = text.substring(0, 40) + "..."
|
||||||
|
}
|
||||||
|
|
||||||
|
throw IllegalStateException("Expected $path to contain $value, but found $text")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
@ -10,6 +10,8 @@ import ru.dbotthepony.kommons.io.readVarInt
|
|||||||
import ru.dbotthepony.kommons.io.writeVarInt
|
import ru.dbotthepony.kommons.io.writeVarInt
|
||||||
import ru.dbotthepony.kommons.util.KOptional
|
import ru.dbotthepony.kommons.util.KOptional
|
||||||
import ru.dbotthepony.kstarbound.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
|
import ru.dbotthepony.kstarbound.defs.tile.BuiltinMetaMaterials
|
||||||
|
import ru.dbotthepony.kstarbound.defs.tile.isNullTile
|
||||||
import ru.dbotthepony.kstarbound.io.BTreeDB5
|
import ru.dbotthepony.kstarbound.io.BTreeDB5
|
||||||
import ru.dbotthepony.kstarbound.json.VersionedJson
|
import ru.dbotthepony.kstarbound.json.VersionedJson
|
||||||
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
||||||
@ -72,7 +74,17 @@ sealed class LegacyWorldStorage() : WorldStorage() {
|
|||||||
|
|
||||||
for (y in 0 until CHUNK_SIZE) {
|
for (y in 0 until CHUNK_SIZE) {
|
||||||
for (x in 0 until CHUNK_SIZE) {
|
for (x in 0 until CHUNK_SIZE) {
|
||||||
result[x, y] = MutableCell().readLegacy(reader, tileSerializationVersion).immutable()
|
val read = MutableCell().readLegacy(reader, tileSerializationVersion)
|
||||||
|
|
||||||
|
if (read.foreground.material == BuiltinMetaMaterials.STRUCTURE) {
|
||||||
|
read.foreground.material = BuiltinMetaMaterials.EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read.background.material == BuiltinMetaMaterials.STRUCTURE) {
|
||||||
|
read.background.material = BuiltinMetaMaterials.EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
result[x, y] = read.immutable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1018,5 +1018,7 @@ class Animator() {
|
|||||||
private val missing = Collections.synchronizedSet(ObjectOpenHashSet<String>())
|
private val missing = Collections.synchronizedSet(ObjectOpenHashSet<String>())
|
||||||
private val vectors by lazy { Starbound.gson.getAdapter(Vector2d::class.java) }
|
private val vectors by lazy { Starbound.gson.getAdapter(Vector2d::class.java) }
|
||||||
private val polies by lazy { Starbound.gson.getAdapter(Poly::class.java) }
|
private val polies by lazy { Starbound.gson.getAdapter(Poly::class.java) }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package ru.dbotthepony.kstarbound.test
|
package ru.dbotthepony.kstarbound.test
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonPrimitive
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import ru.dbotthepony.kommons.arrays.Int2DArray
|
import ru.dbotthepony.kommons.arrays.Int2DArray
|
||||||
import ru.dbotthepony.kstarbound.defs.dungeon.VectorizedBitSet
|
import ru.dbotthepony.kstarbound.defs.dungeon.VectorizedBitSet
|
||||||
|
import ru.dbotthepony.kstarbound.json.JsonPath
|
||||||
import ru.dbotthepony.kstarbound.util.random.random
|
import ru.dbotthepony.kstarbound.util.random.random
|
||||||
import java.rmi.UnexpectedException
|
import java.rmi.UnexpectedException
|
||||||
|
|
||||||
@ -35,4 +38,13 @@ object MiscTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Json patch test")
|
||||||
|
fun jsonPatchTest() {
|
||||||
|
val json = JsonObject()
|
||||||
|
|
||||||
|
JsonPath.pointer("/element").add(json, JsonPrimitive(1))
|
||||||
|
assertEquals(json["element"], JsonPrimitive(1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user