mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
feat(recomps): filter by native builds and by original system
Nearly every recomp needs the player's own files, so that filter said nothing. The chips are now All, Installed, You own the game and Runs natively (arm64 Linux or an Android APK), with a row of the original systems found in the catalogs.
This commit is contained in:
1 parent
bc9a941b14
commit
c812290a9b
4 files changed
+59
-7
No files matched your search
@@ -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<RecompRow> = 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<RecompRow>): List<Pair<String, Int>> =
|
||||
rows.groupingBy { it.entry.origin }.eachCount().filter { (origin, n) -> origin.isNotEmpty() && n > 1 }
|
||||
.toList().sortedWith(compareByDescending<Pair<String, Int>> { 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<String?>(null) }
|
||||
var query by rememberSaveable { mutableStateOf("") }
|
||||
val rows = androidx.compose.runtime.remember(RecompsState.entries, RecompsState.data, RecompsState.installed, RecompsState.updates) {
|
||||
recompRows().sortedWith(compareBy<RecompRow> { 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
|
||||
|
||||
@@ -4408,7 +4408,8 @@
|
||||
<string name="recomps_lede">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.</string>
|
||||
<string name="recomps_filter_all">All</string>
|
||||
<string name="recomps_filter_owned">You own the game</string>
|
||||
<string name="recomps_filter_bring">Bring your own files</string>
|
||||
<string name="recomps_filter_native">Runs natively</string>
|
||||
<string name="recomps_every_system">Every system</string>
|
||||
<string name="recomps_filter_installed">Installed</string>
|
||||
<string name="recomps_empty">The recomp list couldn\'t be loaded.</string>
|
||||
<string name="recomps_none_here">Nothing here yet.</string>
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user