mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: the game page shows the game's logo
The hero on the Games page draws the game's logo instead of the plain title when there is one: Steam's cached logo.png or a chosen logo for Steam games, the resolved logo for added and store games. The title text stays as the fallback and as the logo's description for screen readers.
This commit is contained in:
1 parent
be384ca2a2
commit
8faf88de85
6 files changed
+108
-7
No files matched your search
@@ -1963,7 +1963,7 @@ class MainActivity : ComponentActivity() {
|
||||
steamGamesX64 = scannedX64
|
||||
steamGames = all.map { g ->
|
||||
val newer = current[g.appId]
|
||||
if (newer != null && g.library != Library.ADDED && steamArtRefreshes[g.appId] != artRefreshesAtStart[g.appId]) g.withArt(newer.art, newer.hero, newer.icon) else g
|
||||
if (newer != null && g.library != Library.ADDED && steamArtRefreshes[g.appId] != artRefreshesAtStart[g.appId]) g.withArt(newer.art, newer.hero, newer.icon, newer.logo) else g
|
||||
}
|
||||
shortcutLibraryScanning = false
|
||||
handleGameLink(all)
|
||||
|
||||
@@ -16,9 +16,10 @@ object Library {
|
||||
val icon: File? = null,
|
||||
val source: String = SOURCE_STEAM,
|
||||
val storeId: String? = null,
|
||||
val logo: File? = null,
|
||||
) {
|
||||
fun withArt(art: File?, hero: File?, icon: File?) =
|
||||
SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId)
|
||||
fun withArt(art: File?, hero: File?, icon: File?, logo: File? = this.logo) =
|
||||
SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId, logo)
|
||||
|
||||
val gameIdString: String get() = java.lang.Long.toUnsignedString(gameId)
|
||||
val profileKey: String get() = if (library == ADDED) java.lang.Integer.toUnsignedString(appId) else appId.toString()
|
||||
@@ -68,6 +69,7 @@ object Library {
|
||||
)
|
||||
private val STEAM_CAPSULES = listOf("library_capsule.jpg", "library_600x900.jpg")
|
||||
private val STEAM_HEROES = listOf("library_hero.jpg")
|
||||
internal val STEAM_LOGOS = listOf("logo.png")
|
||||
private val STEAM_ICON = Regex("[a-fA-F0-9]{40}\\.(jpg|png)")
|
||||
private val NAME = Regex("^\\s*\"name\"\\s*\"([^\"]*)\"", RegexOption.MULTILINE)
|
||||
private val STATE = Regex("^\\s*\"StateFlags\"\\s*\"(\\d+)\"", RegexOption.MULTILINE)
|
||||
@@ -131,6 +133,7 @@ object Library {
|
||||
protonPrefix = protonPrefix(context, appId.toLong(), library, roots),
|
||||
icon = steamCacheImage(cache, appId, listOf("icon.jpg", "icon.png"))
|
||||
?: File(cache, appId.toString()).listFiles()?.firstOrNull { it.isFile && STEAM_ICON.matches(it.name) },
|
||||
logo = steamCacheImage(cache, appId, STEAM_LOGOS),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -203,6 +206,7 @@ object Library {
|
||||
protonPrefix = protonPrefix(context, g.steamAppId?.toLong() ?: g.appId, libraries = roots),
|
||||
icon = art.icon?.takeIf { it.extension.lowercase() != "ico" },
|
||||
source = g.source, storeId = g.storeId,
|
||||
logo = art.logo,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ object LibraryCache {
|
||||
icon = o.file("icon"),
|
||||
source = o.optString("source").ifEmpty { if (o.getString("library") == Library.ADDED) Library.ADDED else Library.SOURCE_STEAM },
|
||||
storeId = o.optString("storeId").ifEmpty { null },
|
||||
logo = o.file("logo"),
|
||||
)
|
||||
} to x64
|
||||
}.getOrElse { e -> Log.w(TAG, "unreadable, ignored: ${e.message}"); Pair(emptyList(), false) }
|
||||
@@ -44,7 +45,7 @@ object LibraryCache {
|
||||
for (g in games) array.put(
|
||||
JSONObject().put("appId", g.appId).put("name", g.name).put("library", g.library).put("gameId", g.gameId)
|
||||
.put("lastPlayed", g.lastPlayed).putFile("art", g.art).putFile("hero", g.hero)
|
||||
.putFile("gameFiles", g.gameFiles).putFile("protonPrefix", g.protonPrefix).putFile("icon", g.icon)
|
||||
.putFile("gameFiles", g.gameFiles).putFile("protonPrefix", g.protonPrefix).putFile("icon", g.icon).putFile("logo", g.logo)
|
||||
.put("source", g.source).apply { g.storeId?.let { put("storeId", it) } },
|
||||
)
|
||||
val f = file(context)
|
||||
|
||||
@@ -22,10 +22,12 @@ object SteamGameArt {
|
||||
val cover = chosenFile(context, game.appId, AddedGameArt.Slot.COVER)
|
||||
val hero = chosenFile(context, game.appId, AddedGameArt.Slot.BACKGROUND)
|
||||
val icon = chosenFile(context, game.appId, AddedGameArt.Slot.ICON)
|
||||
if (cover == null && hero == null && icon == null) return game
|
||||
val logo = chosenFile(context, game.appId, AddedGameArt.Slot.LOGO)
|
||||
if (cover == null && hero == null && icon == null && logo == null) return game
|
||||
return Library.SteamGame(
|
||||
game.appId, game.name, cover ?: game.art, game.library, game.gameId,
|
||||
hero ?: game.hero, game.lastPlayed, game.gameFiles, game.protonPrefix, icon ?: game.icon, game.source, game.storeId,
|
||||
logo ?: game.logo,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@@ -324,11 +325,24 @@ private fun ColumnScope.GameHeroCopy(g: Library.SteamGame, titleSize: androidx.c
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
GameTitle(g, titleSize)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameTitle(g: Library.SteamGame, titleSize: androidx.compose.ui.unit.TextUnit) {
|
||||
val logo = g.logo
|
||||
var failed by remember(logo) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
if (logo != null && !failed) {
|
||||
AsyncImage(
|
||||
model = logo, contentDescription = g.name, contentScale = ContentScale.Fit, alignment = Alignment.CenterStart,
|
||||
onError = { failed = true },
|
||||
modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 2.2f).dp).widthIn(max = (titleSize.value * 9f).dp).testTag("game-logo"),
|
||||
)
|
||||
} else Text(
|
||||
g.name, fontSize = titleSize, lineHeight = titleSize * 1.15f, fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GameLogoTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Before fun noGamesFolders() {
|
||||
AddedGamesPublisher.now = true
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
SessionPrefs.setAddedGamesDirs(app, emptyList())
|
||||
}
|
||||
|
||||
private fun image(name: String) = File(tmp.root, name).apply { parentFile?.mkdirs(); writeBytes(ByteArray(8) { 1 }) }
|
||||
|
||||
@Test fun steamsCachedLogoIsFoundInTheAppFolderOrAHashedOne() {
|
||||
val cache = tmp.newFolder("librarycache")
|
||||
val logo = File(cache, "620/3f1c/logo.png").apply { parentFile?.mkdirs(); writeBytes(ByteArray(4) { 1 }) }
|
||||
assertEquals(logo, Library.steamCacheImage(cache, 620, Library.STEAM_LOGOS))
|
||||
File(cache, "730").mkdirs()
|
||||
File(cache, "730/logo.png").writeBytes(ByteArray(0))
|
||||
assertNull(Library.steamCacheImage(cache, 730, Library.STEAM_LOGOS))
|
||||
}
|
||||
|
||||
@Test fun aChosenLogoWinsOverSteamsAndKeepsTheRest() {
|
||||
val stock = image("logo.png")
|
||||
val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = stock)
|
||||
assertTrue(SteamGameArt.withOverrides(app, game) === game)
|
||||
val picked = image("mine.png")
|
||||
assertTrue(SteamGameArt.choose(app, game, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
val shown = SteamGameArt.withOverrides(app, game)
|
||||
assertTrue(shown.logo!!.name.startsWith("chosen-logo"))
|
||||
assertNull(shown.art)
|
||||
SteamGameArt.reset(app, game, AddedGameArt.Slot.LOGO)
|
||||
assertEquals(stock, SteamGameArt.withOverrides(app, game).logo)
|
||||
}
|
||||
|
||||
@Test fun anAddedGameShowsItsFolderLogoUnlessOneWasChosen() {
|
||||
val dir = tmp.newFolder("Celeste")
|
||||
val own = File(dir, "logo.png").apply { writeBytes(ByteArray(4) { 1 }) }
|
||||
val exe = File(dir, "Celeste.exe").apply { writeText("x") }
|
||||
val g = AddedGames.Game(dir, "Celeste", exe, "/g/Celeste.exe", "/g", 0x82000001L, 0x82000001L, emptyList(), source = "gog")
|
||||
assertEquals(own, Library.addedGame(app, g, emptyList()).logo)
|
||||
val picked = image("pick.png")
|
||||
assertTrue(AddedGameArt.choose(app, g, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
|
||||
assertTrue(Library.addedGame(app, g, emptyList()).logo!!.name.startsWith("chosen-logo"))
|
||||
val bare = AddedGames.Game(tmp.newFolder("Bare"), "Bare", exe, "/g/Bare.exe", "/g", 0x82000002L, 0x82000002L, emptyList())
|
||||
assertNull(Library.addedGame(app, bare, emptyList()).logo)
|
||||
}
|
||||
|
||||
@Test fun theLibraryCacheKeepsTheLogoAndReadsOlderEntries() {
|
||||
val logo = image("logo.png")
|
||||
val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = logo)
|
||||
LibraryCache.save(app, listOf(game, Library.SteamGame(730, "CS2", null, "Steam library")))
|
||||
val back = LibraryCache.load(app)
|
||||
assertEquals(logo, back[0].logo)
|
||||
assertNull(back[1].logo)
|
||||
assertEquals(logo, game.withArt(null, null, null).logo)
|
||||
val file = File(app.filesDir, "library-cache.json")
|
||||
file.writeText(JSONArray().put(JSONObject().put("appId", 1).put("name", "Old").put("library", "x").put("gameId", 1L)).toString())
|
||||
assertNull(LibraryCache.load(app).single().logo)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user