diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt index be4458ee..1e98ef47 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt @@ -144,17 +144,17 @@ private fun loop() { var y = 0 for (tile in Starbound.tilesAccess.values) { - chunk[x, y + 1] = (tile) - chunk[x++, y] = (tile) - chunk[x, y + 1] = (tile) - chunk[x++, y] = (tile) - chunk[x, y + 1] = (tile) - chunk[x++, y] = (tile) - chunk[x, y + 1] = (tile) - chunk[x++, y] = (tile) - chunk[x, y + 1] = (tile) - chunk[x++, y] = (tile) - chunk[x, y + 1] = (tile) + chunk[x, y + 1] = tile + chunk[x++, y] = tile + chunk[x, y + 1] = tile + chunk[x++, y] = tile + chunk[x, y + 1] = tile + chunk[x++, y] = tile + chunk[x, y + 1] = tile + chunk[x++, y] = tile + chunk[x, y + 1] = tile + chunk[x++, y] = tile + chunk[x, y + 1] = tile if (x >= 32) { x = 0 diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TileDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TileDefinition.kt index 1fadbb81..4e76e033 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TileDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TileDefinition.kt @@ -10,6 +10,7 @@ import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.math.Vector2i import ru.dbotthepony.kstarbound.util.Color import ru.dbotthepony.kstarbound.world.IChunk +import ru.dbotthepony.kstarbound.world.ITileAccess import java.io.File data class TileDefinition( @@ -180,7 +181,7 @@ sealed class RenderRule(params: Map) { val matchHue = params["matchHue"] as? Boolean ?: false val inverse = params["inverse"] as? Boolean ?: false - abstract fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean + abstract fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean companion object { fun factory(name: String, params: Map): RenderRule { @@ -220,7 +221,7 @@ sealed class RenderRule(params: Map) { } class RenderRuleEqualsSelf(params: Map) : RenderRule(params) { - override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { val otherTile = getter[thisPos + offsetPos] ?: return inverse if (inverse) @@ -231,13 +232,13 @@ class RenderRuleEqualsSelf(params: Map) : RenderRule(params) { } class RenderRuleShadows(params: Map) : RenderRule(params) { - override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { return false // TODO } } class RenderRuleConnects(params: Map) : RenderRule(params) { - override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { if (inverse) return getter[thisPos + offsetPos] == null @@ -246,13 +247,13 @@ class RenderRuleConnects(params: Map) : RenderRule(params) { } class AlwaysPassingRenderRule(params: Map) : RenderRule(params) { - override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { return inverse } } class AlwaysFailingRenderRule(params: Map) : RenderRule(params) { - override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { return !inverse } } @@ -273,7 +274,7 @@ data class TileRenderRule( val join: RenderRuleCombination, val pieces: List ) { - fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { + fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { if (join == RenderRuleCombination.ANY) { for (piece in pieces) { if (piece.test(getter, thisRef, thisPos, offsetPos)) { @@ -337,7 +338,7 @@ data class TileRenderMatchPositioned( /** * Состояние [condition] на [thisPos] с [offset] */ - fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i): Boolean { + fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i): Boolean { return condition.test(getter, thisRef, thisPos, offset) } @@ -372,7 +373,7 @@ data class TileRenderMatchPiece( * * [subMatches] стоит итерировать только если это вернуло true */ - fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i): Boolean { + fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i): Boolean { for (matcher in matchAllPoints) { if (!matcher.test(getter, thisRef, thisPos)) { return false diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt index 120bdf36..f3e66b5c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt @@ -8,9 +8,7 @@ data class ChunkTile(val def: TileDefinition) { var forceVariant = -1 } -interface IChunk { - val pos: ChunkPos - +interface ITileAccess { /** * Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка */ @@ -20,7 +18,10 @@ interface IChunk { * Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка */ operator fun get(pos: Vector2i) = get(pos.x, pos.y) +} +interface IChunk : ITileAccess { + val pos: ChunkPos /** * Возвращает фоновый тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка