Compare commits
No commits in common. "47cd68fcfeef8eaa00273d67c7baf2661c7bf818" and "2d36517acb8e2f6db3c38fd9b566399158eb0d21" have entirely different histories.
47cd68fcfe
...
2d36517acb
5 changed files with 13 additions and 45 deletions
8
.idea/deploymentTargetSelector.xml
generated
8
.idea/deploymentTargetSelector.xml
generated
|
|
@ -4,14 +4,6 @@
|
|||
<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,7 +21,6 @@ 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(
|
||||
|
|
@ -31,8 +30,8 @@ fun MapCanvas(
|
|||
tileContainer: TileContainer,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
Canvas(
|
||||
modifier = modifier.fillMaxSize()
|
||||
|
|
@ -47,31 +46,15 @@ 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
|
||||
|
|
@ -79,7 +62,7 @@ fun MapCanvas(
|
|||
val gridWidth = grid.width.toInt()
|
||||
val gridHeight = grid.height.toInt()
|
||||
|
||||
val tiles = tileContainer.getTiles(tileOffsetX, tileOffsetY, tileOffsetX + gridWidth + 2, tileOffsetY + gridHeight + 2, level)
|
||||
val tiles = tileContainer.getTiles(tileOffsetX, tileOffsetY, tileOffsetX + gridWidth, tileOffsetY + gridHeight, level)
|
||||
|
||||
for (cellX in 0 .. gridWidth + 2) {
|
||||
val tileX = tileOffsetX + cellX
|
||||
|
|
@ -88,7 +71,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 }?.toBitmap()
|
||||
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.getBitmap()
|
||||
|
||||
bitmap?.let {
|
||||
val imageBitmap = bitmap.asImageBitmap()
|
||||
|
|
@ -97,7 +80,7 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset
|
||||
)
|
||||
}
|
||||
/*
|
||||
|
||||
drawRect(
|
||||
color = gridColor,
|
||||
size = Size(TILE_SIZE, TILE_SIZE),
|
||||
|
|
@ -117,7 +100,6 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset,
|
||||
size = Size(TILE_SIZE, TILE_SIZE)
|
||||
)
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ 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" ])
|
||||
|
|
@ -21,9 +20,6 @@ class Tile {
|
|||
@ColumnInfo(name = "data")
|
||||
var base64: String? = null
|
||||
|
||||
@Ignore
|
||||
var bitmap: Bitmap? = null
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(x: Int, y: Int, level: Int) {
|
||||
|
|
@ -39,11 +35,11 @@ class Tile {
|
|||
this.base64 = base64
|
||||
}
|
||||
|
||||
fun toBitmap(): Bitmap? {
|
||||
if (bitmap != null || base64 == null)
|
||||
return bitmap
|
||||
fun getBitmap(): Bitmap? {
|
||||
if (this.base64 == null)
|
||||
return null
|
||||
val ba = Base64.getDecoder().decode(this.base64)
|
||||
bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bitmap
|
||||
val bmp = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bmp
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,6 @@ 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