diff --git a/src/main/kotlin/com/mineinabyss/launchy/data/config/GameInstanceConfig.kt b/src/main/kotlin/com/mineinabyss/launchy/data/config/GameInstanceConfig.kt index b3414be..20b3bcf 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/data/config/GameInstanceConfig.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/data/config/GameInstanceConfig.kt @@ -1,8 +1,6 @@ package com.mineinabyss.launchy.data.config -import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.res.loadImageBitmap import com.charleskorn.kaml.encodeToStream @@ -65,19 +63,15 @@ data class GameInstanceConfig( }.onFailure { it.printStackTrace() } } - @Composable - fun getBackground() = remember { + fun getBackgroundAsState() = cachedBackground.also { if (it.value == null) downloadScope.launch { loadBackground() } } - } - @Composable - fun getLogo() = remember { + fun getLogoAsState() = cachedLogo.also { if (it.value == null) downloadScope.launch { loadLogo() } } - } fun saveTo(path: Path) = runCatching { Formats.yaml.encodeToStream(this, path.outputStream()) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/HomeScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/HomeScreen.kt index 872f1b0..3b2293c 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/HomeScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/HomeScreen.kt @@ -40,7 +40,9 @@ fun HomeScreen() { Spacer(Modifier.height(16.dp)) } item { - InstanceList("Instances", state.gameInstances) + InstanceList( + "Instances", + state.gameInstances.sortedByDescending { state.lastPlayed[it.config.name] }) } // item { // ModpackGroup("Find more", state.downloadedModpacks) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceCard.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceCard.kt index 65d0a87..bd78a8e 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceCard.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceCard.kt @@ -12,6 +12,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -52,7 +53,7 @@ fun InstanceCard( ) { val state = LocalLaunchyState val coroutineScope = rememberCoroutineScope() - val background by config.getBackground() + val background by remember(config) { config.getBackgroundAsState() } Card( onClick = { instance ?: return@Card diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceList.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceList.kt index 2715c78..911045f 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceList.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/home/InstanceList.kt @@ -40,7 +40,7 @@ fun InstanceList(title: String, packs: List) { horizontalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp), ) { - items(visiblePacks.sortedByDescending { state.lastPlayed[it.config.name] }) { pack -> + items(visiblePacks) { pack -> InstanceCard(pack.config, pack) } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/modpack/main/MainScreenImages.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/modpack/main/MainScreenImages.kt index 38476cd..d674420 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/modpack/main/MainScreenImages.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/modpack/main/MainScreenImages.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.window.WindowDraggableArea import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush @@ -24,7 +25,7 @@ import com.mineinabyss.launchy.ui.screens.LocalGameInstanceState @Composable fun BoxScope.BackgroundImage(windowScope: WindowScope) { val pack = LocalGameInstanceState - val background by pack.instance.config.getBackground() + val background by remember { pack.instance.config.getBackgroundAsState() } AnimatedVisibility(background != null, enter = fadeIn(), exit = fadeOut()) { if (background == null) return@AnimatedVisibility windowScope.WindowDraggableArea { @@ -75,9 +76,9 @@ fun BoxScope.SlightBackgroundTint(modifier: Modifier = Modifier) { @Composable fun LogoLarge(modifier: Modifier) { - val state = LocalLaunchyState + LocalLaunchyState val pack = LocalGameInstanceState - val painter by pack.instance.config.getLogo() + val painter by remember { pack.instance.config.getLogoAsState() } AnimatedVisibility( painter != null, enter = fadeIn() + expandVertically(clip = false) + fadeIn(),