mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat: merge Games and store libraries into one Library and one game page (#1460)
This commit is contained in:
1 parent
0cf5b42788
commit
2a69505199
62 files changed
+3240
-1803
No files matched your search
@@ -7,6 +7,13 @@ class SortCatalogItemsTest {
|
||||
private fun item(id: String, title: String, size: Long = 0, releaseDate: String = "") =
|
||||
CatalogItem(Store.GOG, id, title, imageUrl = null, sizeBytes = size, releaseDate = releaseDate, owned = true)
|
||||
|
||||
private fun sortCatalogItems(
|
||||
items: List<CatalogItem>, sort: String,
|
||||
lastPlayed: (CatalogItem) -> Long = { 0L }, installedAt: (CatalogItem) -> Long = { 0L },
|
||||
) = sortGames(items, sort, { it.title }, { it.releaseDate }, lastPlayed, installedAt, { it.sizeBytes })
|
||||
|
||||
private fun retainCatalogOrder(items: List<CatalogItem>, previous: List<CatalogItem>) = retainOrder(items, previous) { it.key }
|
||||
|
||||
@Test fun titleOrderIsCaseInsensitiveAndDescendingIsItsMirror() {
|
||||
val items = listOf(item("1", "Zelda"), item("2", "alpha"), item("3", "Beta"))
|
||||
assertEquals(listOf("alpha", "Beta", "Zelda"), sortCatalogItems(items, "titleAsc").map { it.title })
|
||||
|
||||
@@ -16,17 +16,6 @@ import java.security.MessageDigest
|
||||
class EpicClientTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun game(appId: Int, source: String) =
|
||||
com.droiddeck.launcher.frontend.Library.SteamGame(appId, "g$appId", null, "internal", source = source)
|
||||
|
||||
@Test fun theLauncherSitsRightAboveTheFirstEpicGame() {
|
||||
val launcher = game(EpicClient.LAUNCHER_APP_ID, "epic")
|
||||
val games = listOf(game(1, "steam"), game(2, "epic"), game(3, "steam"), game(4, "epic"))
|
||||
assertEquals(listOf(1, 0, 2, 3, 4), EpicClient.withLauncher(games, launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 3, 0), EpicClient.withLauncher(listOf(games[0], games[2]), launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 2), EpicClient.withLauncher(games.take(2), null).map { it.appId })
|
||||
}
|
||||
|
||||
private fun added(name: String, source: String, storeId: String?) =
|
||||
com.droiddeck.launcher.frontend.AddedGames.Game(File(tmp.root, name), name, File(tmp.root, "$name/$name.exe"),
|
||||
"/root/Games/$name/$name.exe", "/root/Games/$name", 3_000_000_000L, 0L, emptyList(), source = source, storeId = storeId)
|
||||
|
||||
@@ -48,7 +48,7 @@ class GamesClientTagTest {
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalFrontFocus provides FrontFocus(), LocalNarrowPane provides narrow) {
|
||||
FocusGlideHost {
|
||||
GamesPage(FrontEndState(
|
||||
LibraryPage(FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = games, steamGamesX64 = x64, emulators = emptyList(), running = null,
|
||||
@@ -60,7 +60,7 @@ class GamesClientTagTest {
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
), selected = "app:440", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
), selected = "games", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class LibraryEntriesTest {
|
||||
private fun owned(store: Store, id: String, title: String = id) = CatalogItem(store, id, title, imageUrl = null, owned = true)
|
||||
|
||||
@Test fun anInstalledStoreGameClaimsItsOwnedProductSoItShowsOnce() {
|
||||
val games = listOf(
|
||||
Library.SteamGame(440, "Team Fortress 2", null, "Steam library"),
|
||||
Library.SteamGame(-5, "Cyberpunk", null, Library.ADDED, source = "gog", storeId = "1423049311"),
|
||||
)
|
||||
val library = mapOf(Store.GOG to listOf(owned(Store.GOG, "1423049311", "Cyberpunk 2077"), owned(Store.GOG, "1207658924", "Witcher")))
|
||||
val entries = libraryEntries(games, library, emptySet())
|
||||
assertEquals(listOf("app:440", "app:-5", "app:gog:1207658924"), entries.map { it.key })
|
||||
assertEquals("gog:1423049311", entries[1].item?.key)
|
||||
assertTrue(entries[1].installed)
|
||||
assertFalse(entries[2].installed)
|
||||
assertNull(entries[2].game)
|
||||
}
|
||||
|
||||
@Test fun theEpicLauncherIsNotAGame() {
|
||||
val launcher = Library.SteamGame(0, Library.EPIC_LAUNCHER_NAME, null, Library.EPIC_LAUNCHER)
|
||||
assertEquals(emptyList<String>(), libraryEntries(listOf(launcher), emptyMap(), emptySet()).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun aStoreInstallTheLibraryHasNotScannedYetCountsAsInstalled() {
|
||||
val entries = libraryEntries(emptyList(), mapOf(Store.EPIC to listOf(owned(Store.EPIC, "fn"))), setOf("epic:fn"))
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val entries = listOf("a", "b", "c", "d").map { LibraryEntry(it, "steam", it, null, null, installed = it == "b" || it == "d") }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(entries).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
|
||||
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
|
||||
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }
|
||||
GameRef.parse("app:gog:1207658924").let { assertEquals(Store.GOG, it.store); assertEquals("1207658924", it.storeId); assertNull(it.appId) }
|
||||
GameRef.parse("xbox:9NBLGGH4R315").let { assertEquals(Store.XBOX, it.store); assertEquals("9NBLGGH4R315", it.storeId) }
|
||||
GameRef.parse("app:nope:1").let { assertNull(it.store); assertNull(it.appId) }
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,4 @@ class StoreGridNavigationTest {
|
||||
assertEquals(10, storeGridNeighbor(6, 11, 4, 1, split = 6))
|
||||
assertNull(storeGridNeighbor(1, 11, 4, -1, split = 6))
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val items = listOf("a", "b", "c", "d").map { com.droiddeck.launcher.stores.CatalogItem(com.droiddeck.launcher.stores.Store.GOG, it, it, null) }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(items, setOf("d", "b")).map { it.id })
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StoreTabsTest {
|
||||
@Test fun libraryAndStoreAmazonLibraryOnly() {
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.GOG))
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.ITCH))
|
||||
assertEquals(listOf("library"), tabsFor(Store.AMAZON))
|
||||
assertEquals("library", tabFor(Store.AMAZON, "store"))
|
||||
assertEquals("library", tabFor(Store.GOG, "all"))
|
||||
assertEquals("library", tabFor(Store.EPIC, "installed"))
|
||||
assertEquals("store", tabFor(Store.GOG, "store"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user