Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Oct 19, 2024
2 parents 36b46c3 + 2f99985 commit 05e9334
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 642 deletions.
489 changes: 22 additions & 467 deletions app/src/commonMain/kotlin/model/Cluster.kt

Large diffs are not rendered by default.

507 changes: 507 additions & 0 deletions app/src/commonMain/kotlin/model/ClusterType.kt

Large diffs are not rendered by default.

62 changes: 0 additions & 62 deletions app/src/commonMain/kotlin/model/World.kt

This file was deleted.

8 changes: 4 additions & 4 deletions app/src/commonMain/kotlin/model/filter/FilterQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ package model.filter

import kotlinx.serialization.Serializable
import model.AsteroidType
import model.Cluster
import model.ClusterType
import model.Dlc
import model.filter.FilterRule.Companion.EMPTY
import serializer.ClusterSerializer
import serializer.ClusterTypeSerializer

@Serializable
data class FilterQuery(

@Serializable(with = ClusterSerializer::class)
val cluster: Cluster?,
@Serializable(with = ClusterTypeSerializer::class)
val cluster: ClusterType?,

val dlcs: List<Dlc>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import model.Cluster
import model.ClusterType

object ClusterSerializer : KSerializer<Cluster> {
object ClusterTypeSerializer : KSerializer<ClusterType> {

override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("Cluster", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: Cluster) =
override fun serialize(encoder: Encoder, value: ClusterType) =
encoder.encodeString(value.prefix)

override fun deserialize(decoder: Decoder): Cluster {
override fun deserialize(decoder: Decoder): ClusterType {

val prefix = decoder.decodeString()

return Cluster.entries.find { it.prefix == prefix }
return ClusterType.entries.find { it.prefix == prefix }
?: throw IllegalArgumentException("Unknown prefix: $prefix")
}
}
14 changes: 7 additions & 7 deletions app/src/commonMain/kotlin/service/DefaultWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import model.World
import model.Cluster
import model.filter.FilterQuery

const val BASE_API_URL = "https://apibeta.mapsnotincluded.org"
Expand Down Expand Up @@ -56,9 +56,9 @@ object DefaultWebClient : WebClient {
}
}

override suspend fun countWorlds(): Long? {
override suspend fun countSeeds(): Long? {

println("Count worlds")
println("Count seeds")

val response = httpClient.get(COUNT_URL)

Expand All @@ -68,7 +68,7 @@ object DefaultWebClient : WebClient {
return response.body()
}

override suspend fun find(coordinate: String): World? {
override suspend fun find(coordinate: String): Cluster? {

println("Find: $coordinate")

Expand All @@ -82,15 +82,15 @@ object DefaultWebClient : WebClient {
return response.body()
}

override suspend fun search(filterQuery: FilterQuery): List<World> {
override suspend fun search(filterQuery: FilterQuery): List<Cluster> {

println("Search: " + jsonPretty.encodeToString(filterQuery))

val worlds: List<World> = httpClient.post(SEARCH_URL) {
val clusters: List<Cluster> = httpClient.post(SEARCH_URL) {
contentType(ContentType.Application.Json)
setBody(filterQuery)
}.body()

return worlds
return clusters
}
}
8 changes: 4 additions & 4 deletions app/src/commonMain/kotlin/service/WebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package service

import model.World
import model.Cluster
import model.filter.FilterQuery

interface WebClient {

suspend fun countWorlds(): Long?
suspend fun countSeeds(): Long?

suspend fun find(coordinate: String): World?
suspend fun find(coordinate: String): Cluster?

suspend fun search(filterQuery: FilterQuery): List<World>
suspend fun search(filterQuery: FilterQuery): List<Cluster>

}
28 changes: 14 additions & 14 deletions app/src/commonMain/kotlin/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import model.Asteroid
import model.World
import model.Cluster
import model.filter.FilterQuery
import oni_seed_browser.app.generated.resources.Res
import oni_seed_browser.app.generated.resources.background_space
Expand Down Expand Up @@ -67,7 +67,7 @@ fun App(
) {

val worldCount = produceState<Long?>(null) {
value = DefaultWebClient.countWorlds()
value = DefaultWebClient.countSeeds()
}

val coroutineScope = rememberCoroutineScope()
Expand All @@ -76,7 +76,7 @@ fun App(

val lazyListState = rememberLazyListState()

val showStarMap = remember { mutableStateOf<World?>(null) }
val showStarMap = remember { mutableStateOf<Cluster?>(null) }

val showAsteroidMap = remember { mutableStateOf<Asteroid?>(null) }

Expand All @@ -93,7 +93,7 @@ fun App(
showAsteroidDetails.value = null
}

val worlds = remember { mutableStateOf(emptyList<World>()) }
val clusters = remember { mutableStateOf(emptyList<Cluster>()) }

LaunchedEffect(urlHash.value) {

Expand All @@ -110,9 +110,9 @@ fun App(
val world = DefaultWebClient.find(urlHashValue)

if (world != null)
worlds.value = listOf(world)
clusters.value = listOf(world)
else
worlds.value = emptyList()
clusters.value = emptyList()

} catch (ex: Exception) {

Expand All @@ -128,10 +128,10 @@ fun App(

println("Load demo data...")

val parsedWorlds = Json.decodeFromString<List<World>>(sampleWorldsJson)
val parsedClusters = Json.decodeFromString<List<Cluster>>(sampleWorldsJson)

/* DLCs first */
worlds.value = parsedWorlds.sortedWith(compareBy({ it.cluster.isBaseGame() }, { it.cluster }))
clusters.value = parsedClusters.sortedWith(compareBy({ it.cluster.isBaseGame() }, { it.cluster }))
}
}

Expand All @@ -140,7 +140,7 @@ fun App(
if (worldForStarMapView != null) {

StarMapView(
world = worldForStarMapView,
cluster = worldForStarMapView,
onCloseClicked = { showStarMap.value = null }
)

Expand Down Expand Up @@ -217,15 +217,15 @@ fun App(
errorMessage.value = null

/* Reset the data */
worlds.value = emptyList()
clusters.value = emptyList()

val searchResultWorlds = DefaultWebClient.search(
filterQueryState.value
)

val sortedWorlds = searchResultWorlds.sortedByDescending { it.getRating() }

worlds.value = sortedWorlds
clusters.value = sortedWorlds

} catch (ex: Exception) {

Expand Down Expand Up @@ -262,7 +262,7 @@ fun App(
)
}

} else if (worlds.value.isEmpty()) {
} else if (clusters.value.isEmpty()) {

Box(
contentAlignment = Alignment.Center,
Expand Down Expand Up @@ -302,9 +302,9 @@ fun App(
modifier = Modifier.weight(1F)
) {

WorldViewList(
ClusterViewList(
lazyListState,
worlds.value,
clusters.value,
showStarMap,
showAsteroidMap,
showAsteroidDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import model.Asteroid
import model.World
import model.Cluster
import ui.theme.*
import kotlin.math.max

val widthPerWorld: Dp = 380.dp

@Composable
fun WorldView(
world: World,
fun ClusterView(
cluster: Cluster,
index: Int,
totalCount: Int,
showStarMap: MutableState<World?>,
showStarMap: MutableState<Cluster?>,
showAsteroidMap: MutableState<Asteroid?>,
showAsteroidDetails: MutableState<Asteroid?>,
showTooltip: MutableState<Tooltip?>
Expand All @@ -61,13 +61,13 @@ fun WorldView(
.border(0.dp, lightGrayTransparentBorderColor, defaultRoundedCornerShape)
) {

val showMapClicked: (() -> Unit) = { showStarMap.value = world }
val showMapClicked: (() -> Unit) = { showStarMap.value = cluster }

CoordinateBox(
index = index,
totalCount = totalCount,
coordinate = world.coordinate,
showMapClicked = if (world.starMapEntriesSpacedOut != null)
coordinate = cluster.coordinate,
showMapClicked = if (cluster.starMapEntriesSpacedOut != null)
showMapClicked
else
null
Expand All @@ -80,7 +80,7 @@ fun WorldView(
if (asteroid == null) {

AsteroidsGrid(
world,
cluster,
showAsteroidMap,
showAsteroidDetails,
showTooltip
Expand Down Expand Up @@ -109,7 +109,7 @@ fun WorldView(

val clipboardManager = LocalClipboardManager.current

val url = "https://stefan-oltmann.de/oni-seed-browser/#" + world.coordinate;
val url = "https://stefan-oltmann.de/oni-seed-browser/#" + cluster.coordinate;

Spacer(modifier = Modifier.width(defaultSpacing + halfSpacing))

Expand Down Expand Up @@ -164,7 +164,7 @@ fun WorldView(

@Composable
private fun AsteroidsGrid(
world: World,
cluster: Cluster,
showAsteroidMap: MutableState<Asteroid?>,
showAsteroidDetails: MutableState<Asteroid?>,
showTooltip: MutableState<Tooltip?>
Expand All @@ -187,7 +187,7 @@ private fun AsteroidsGrid(
verticalArrangement = Arrangement.spacedBy(defaultSpacing)
) {

val firstAsteroid = world.asteroids.first()
val firstAsteroid = cluster.asteroids.first()

/* First Asteroid should span the whole column. */
AsteroidView(
Expand All @@ -207,7 +207,7 @@ private fun AsteroidsGrid(
}
)

val remainingAsteroids = world.asteroids.drop(1)
val remainingAsteroids = cluster.asteroids.drop(1)

val asteroidsPerColumn = remainingAsteroids.chunked(gridLayoutColumnCount)

Expand Down
Loading

0 comments on commit 05e9334

Please sign in to comment.