diff --git a/app/src/main/java/com/droiddeck/launcher/ui/RecompsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/RecompsPage.kt index 5348736ca7..cbdba874a7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/RecompsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/RecompsPage.kt @@ -51,7 +51,7 @@ import com.droiddeck.launcher.store.UserAppsState import com.droiddeck.launcher.stores.Store import com.droiddeck.launcher.stores.StoresState -internal enum class RecompFilter { ALL, OWNED, BRING, INSTALLED } +internal enum class RecompFilter { ALL, INSTALLED, OWNED, NATIVE } internal class RecompRow( val entry: RecompCatalog.Entry, val data: RecompData.State, val installed: RecompInstaller.Installed?, @@ -65,10 +65,19 @@ internal fun recompRows(): List = RecompsState.entries.map { e -> internal fun RecompRow.matches(filter: RecompFilter): Boolean = when (filter) { RecompFilter.ALL -> true RecompFilter.OWNED -> data is RecompData.State.Found || data is RecompData.State.Owned - RecompFilter.BRING -> data is RecompData.State.BringYourOwn RecompFilter.INSTALLED -> installed != null + RecompFilter.NATIVE -> (installed?.platform?.let { RecompCatalog.Platform.of(it) } ?: entry.preferred()?.platform) in NATIVE } +private val NATIVE = setOf(RecompCatalog.Platform.LINUX_ARM64, RecompCatalog.Platform.ANDROID) + +// The original systems present in the list, most entries first; a system with one entry is not worth a chip. +internal fun recompSystems(rows: List): List> = + rows.groupingBy { it.entry.origin }.eachCount().filter { (origin, n) -> origin.isNotEmpty() && n > 1 } + .toList().sortedWith(compareByDescending> { it.second }.thenBy { it.first }) + +private fun RecompRow.onSystem(system: String?) = system == null || entry.origin == system + // Installed first, then the ones whose game you already own, then the rest, each by popularity. internal fun RecompRow.rank(): Int = when { installed != null -> 0 @@ -100,12 +109,14 @@ internal fun RecompsPage(s: FrontEndState, a: FrontEndActions, onSelect: (String onDispose { lifecycle.removeObserver(observer) } } var filter by rememberSaveable { mutableStateOf(RecompFilter.ALL) } + var system by rememberSaveable { mutableStateOf(null) } var query by rememberSaveable { mutableStateOf("") } val rows = androidx.compose.runtime.remember(RecompsState.entries, RecompsState.data, RecompsState.installed, RecompsState.updates) { recompRows().sortedWith(compareBy { it.rank() }.thenByDescending { it.entry.popularity }.thenBy { it.entry.name.lowercase() }) } val searched = rows.filter { it.matches(query) } - val shown = searched.filter { it.matches(filter) } + val shown = searched.filter { it.matches(filter) && it.onSystem(system) } + val systems = recompSystems(searched.filter { it.matches(filter) }) BoxWithConstraints(modifier) { val columns = if (maxWidth >= 820.dp) 2 else 1 val full: androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope.() -> androidx.compose.foundation.lazy.grid.GridItemSpan = @@ -127,10 +138,17 @@ internal fun RecompsPage(s: FrontEndState, a: FrontEndActions, onSelect: (String ) Row(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(8.dp)) { RecompFilter.entries.forEach { f -> - val count = searched.count { it.matches(f) } + val count = searched.count { it.matches(f) && it.onSystem(system) } TabChip("${filterLabel(f)} · $count", filter == f, Modifier.testTag("recomps-filter-${f.name.lowercase()}")) { filter = f } } } + if (systems.size > 1) Row(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).padding(top = 8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp)) { + TabChip(stringResource(R.string.recomps_every_system), system == null, Modifier.testTag("recomps-system-all")) { system = null } + systems.forEach { (origin, n) -> + TabChip("$origin · $n", system == origin, Modifier.testTag("recomps-system-$origin")) { system = if (system == origin) null else origin } + } + } UserAppsState.lastError?.let { Box(Modifier.padding(top = 10.dp)) { Note(it) } } } } @@ -161,8 +179,8 @@ internal fun RecompsPage(s: FrontEndState, a: FrontEndActions, onSelect: (String private fun filterLabel(f: RecompFilter) = stringResource(when (f) { RecompFilter.ALL -> R.string.recomps_filter_all RecompFilter.OWNED -> R.string.recomps_filter_owned - RecompFilter.BRING -> R.string.recomps_filter_bring RecompFilter.INSTALLED -> R.string.recomps_filter_installed + RecompFilter.NATIVE -> R.string.recomps_filter_native }) @Composable diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6725b485b9..81c856277c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4408,7 +4408,8 @@ PC builds of classic games, made by recompiling or reimplementing them. DroidDeck installs the build and finds the game files you already own. It never downloads ROMs or game files. All You own the game - Bring your own files + Runs natively + Every system Installed The recomp list couldn\'t be loaded. Nothing here yet. diff --git a/app/src/test/java/com/droiddeck/launcher/ui/RecompFiltersTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/RecompFiltersTest.kt new file mode 100644 index 0000000000..cc39057eb9 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/RecompFiltersTest.kt @@ -0,0 +1,29 @@ +package com.droiddeck.launcher.ui + +import com.droiddeck.launcher.runtime.RecompCatalog +import com.droiddeck.launcher.runtime.RecompData +import org.junit.Assert.assertEquals +import org.junit.Test + +class RecompFiltersTest { + private fun row(id: String, origin: String, vararg platforms: RecompCatalog.Platform) = RecompRow( + RecompCatalog.Entry(id, id, id, origin, "recomp", "o/$id", "", "", null, platforms.map { RecompCatalog.Build(it, Regex("x")) }, + RecompCatalog.Data(RecompCatalog.DataKind.ROM, "rom"), listOf("recomp-launcher")), + RecompData.State.BringYourOwn(RecompCatalog.Data(RecompCatalog.DataKind.ROM, "rom")), null, null, + ) + + @Test fun nativeMeansTheBuildThatWouldInstallRunsWithoutFexOrProton() { + val rows = listOf( + row("arm", "N64", RecompCatalog.Platform.LINUX_ARM64, RecompCatalog.Platform.WINDOWS_X64), + row("apk", "N64", RecompCatalog.Platform.ANDROID, RecompCatalog.Platform.LINUX_X64), + row("fex", "PC", RecompCatalog.Platform.LINUX_X64), + row("wine", "Xbox 360", RecompCatalog.Platform.WINDOWS_X64), + ) + assertEquals(listOf("arm", "apk"), rows.filter { it.matches(RecompFilter.NATIVE) }.map { it.entry.id }) + } + + @Test fun systemChipsListOriginsByCountAndSkipSingletonsAndBlanks() { + val rows = listOf(row("a", "N64"), row("b", "N64"), row("c", "PS1"), row("d", "PS1"), row("e", "PS1"), row("f", "Wii"), row("g", ""), row("h", "")) + assertEquals(listOf("PS1" to 3, "N64" to 2), recompSystems(rows)) + } +} diff --git a/docs/development/recomps.md b/docs/development/recomps.md index 18c7e434b9..3d9a75e899 100644 --- a/docs/development/recomps.md +++ b/docs/development/recomps.md @@ -113,7 +113,11 @@ Console recomps are never matched, because no store sells their dumps. ## UI - **Top of the page:** a header, one line saying what the tab does, a search box (name, game, - origin, repo), and filter chips with counts: All, You own the game, Bring your own files, Installed. + origin, repo), filter chips with counts (All, Installed, You own the game, Runs natively), and a + row of system chips built from the origins in the list, with the most entries first. + - "Runs natively" means the build that would install is arm64 Linux or an Android APK. + - Almost every entry needs the player's own game files, so that is shown on each card, not offered + as a filter. - **List:** a lazy grid, two columns from 820 dp and one below, capped at 300 cards until the player searches. Cards are sorted installed first, then games installed from a store, then owned games, then the rest by download count.