Compare commits
3 commits
2d36517acb
...
47cd68fcfe
| Author | SHA1 | Date | |
|---|---|---|---|
| 47cd68fcfe | |||
| be85e92397 | |||
| 2f15a6f625 |
5 changed files with 45 additions and 13 deletions
8
.idea/deploymentTargetSelector.xml
generated
8
.idea/deploymentTargetSelector.xml
generated
|
|
@ -4,6 +4,14 @@
|
|||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-08-08T10:50:02.571721922Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=/home/secondbeam/.android/avd/Pixel_3.avd" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.KtHeightMap"
|
||||
tools:targetApi="31">
|
||||
<profileable android:shell="true" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.KtHeightMap">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import androidx.compose.ui.text.drawText
|
|||
import androidx.compose.ui.text.rememberTextMeasurer
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
@Composable
|
||||
fun MapCanvas(
|
||||
|
|
@ -30,8 +31,8 @@ fun MapCanvas(
|
|||
tileContainer: TileContainer,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
Canvas(
|
||||
modifier = modifier.fillMaxSize()
|
||||
|
|
@ -46,15 +47,31 @@ fun MapCanvas(
|
|||
color = backColor,
|
||||
size = size
|
||||
)
|
||||
val oldLevel = tileContainer.getLevel()
|
||||
val level = scale.floatValue.toInt()
|
||||
val levelDiff = level - oldLevel
|
||||
|
||||
if (levelDiff < 0) {
|
||||
repeat (levelDiff.absoluteValue) {
|
||||
offsetX.floatValue -= size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue -= size.height / 2F + TILE_SIZE
|
||||
offsetX.floatValue /= 2F
|
||||
offsetY.floatValue /= 2F
|
||||
}
|
||||
} else if (levelDiff > 0) {
|
||||
repeat (levelDiff) {
|
||||
offsetX.floatValue *= 2F
|
||||
offsetY.floatValue *= 2F
|
||||
offsetX.floatValue += size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue += size.height / 2F + TILE_SIZE
|
||||
}
|
||||
}
|
||||
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 +79,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
|
||||
|
|
@ -71,7 +88,7 @@ fun MapCanvas(
|
|||
val tileY = tileOffsetY + cellY
|
||||
val localOffsetY = TILE_SIZE * (cellY - 1)
|
||||
|
||||
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.getBitmap()
|
||||
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.toBitmap()
|
||||
|
||||
bitmap?.let {
|
||||
val imageBitmap = bitmap.asImageBitmap()
|
||||
|
|
@ -80,7 +97,7 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
drawRect(
|
||||
color = gridColor,
|
||||
size = Size(TILE_SIZE, TILE_SIZE),
|
||||
|
|
@ -100,6 +117,7 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset,
|
||||
size = Size(TILE_SIZE, TILE_SIZE)
|
||||
)
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.graphics.Bitmap
|
|||
import android.graphics.BitmapFactory
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import java.util.Base64
|
||||
|
||||
@Entity(tableName = "tiles", primaryKeys = [ "x", "y", "level" ])
|
||||
|
|
@ -20,6 +21,9 @@ class Tile {
|
|||
@ColumnInfo(name = "data")
|
||||
var base64: String? = null
|
||||
|
||||
@Ignore
|
||||
var bitmap: Bitmap? = null
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(x: Int, y: Int, level: Int) {
|
||||
|
|
@ -35,11 +39,11 @@ class Tile {
|
|||
this.base64 = base64
|
||||
}
|
||||
|
||||
fun getBitmap(): Bitmap? {
|
||||
if (this.base64 == null)
|
||||
return null
|
||||
fun toBitmap(): Bitmap? {
|
||||
if (bitmap != null || base64 == null)
|
||||
return bitmap
|
||||
val ba = Base64.getDecoder().decode(this.base64)
|
||||
val bmp = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bmp
|
||||
bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
|
|
@ -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 )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue