Proper scaling

This commit is contained in:
Alexey 2025-08-08 13:27:12 +03:00
commit 2f15a6f625
2 changed files with 16 additions and 3 deletions

View file

@ -46,15 +46,26 @@ fun MapCanvas(
color = backColor,
size = size
)
val oldLevel = tileContainer.getLevel()
val level = scale.floatValue.toInt()
if (oldLevel > level) {
offsetX.floatValue -= size.width / 2F
offsetY.floatValue -= size.height / 2F
offsetX.floatValue /= 2F
offsetY.floatValue /= 2F
} else if (oldLevel < level) {
offsetX.floatValue *= 2F
offsetY.floatValue *= 2F
offsetX.floatValue += size.width / 2F
offsetY.floatValue += size.height / 2F
}
val tileOffsetX = (offsetX.floatValue / TILE_SIZE).toInt()
val tileOffsetY = (offsetY.floatValue / TILE_SIZE).toInt()
val strippedOffsetX = offsetX.floatValue % TILE_SIZE
val strippedOffsetY = offsetY.floatValue % TILE_SIZE
val level = scale.floatValue.toInt()
val offset = Offset(strippedOffsetX, strippedOffsetY)
val grid = size / TILE_SIZE
@ -62,7 +73,7 @@ fun MapCanvas(
val gridWidth = grid.width.toInt()
val gridHeight = grid.height.toInt()
val tiles = tileContainer.getTiles(tileOffsetX, tileOffsetY, tileOffsetX + gridWidth, tileOffsetY + gridHeight, level)
val tiles = tileContainer.getTiles(tileOffsetX, tileOffsetY, tileOffsetX + gridWidth + 2, tileOffsetY + gridHeight + 2, level)
for (cellX in 0 .. gridWidth + 2) {
val tileX = tileOffsetX + cellX

View file

@ -13,6 +13,8 @@ class TileContainer(private val vm: TileViewModel, private val coroutineScope: C
private var level = 1
fun getLevel(): Int = level
fun getTiles(_startX: Int, _startY: Int, _endX: Int, _endY: Int, _level: Int): List<Tile> {
val newParams = arrayOf( _startX, _startY, _endX, _endY, _level )
val oldParams = arrayOf( startX, startY, endX, endY, level )