mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
fix(battlenet): use the right artwork for each game (#2092)
* fix(battlenet): use the right artwork for each game World of Warcraft: Forever took retail art and its logo from a loose name lookup, and only fetched its own art when the Store tab was opened. Shop pages also supplied trailer stills and seasonal promos. Each game now has chosen Blizzard key art with the shop page as a fallback, installed games fetch their art without opening the store, and lookups by name must match exactly. Art found by the old lookup is fetched again once. * fix(battlenet): keep cached art if the new art cannot be fetched Classic's variants fetch through the shared title, and a failing chosen image falls back to the shop page.
This commit is contained in:
1 parent
5cf69732ef
commit
f1c1ca59fe
7 files changed
+146
-19
No files matched your search
@@ -243,6 +243,8 @@ object AddedGameArt {
|
||||
val steam: (String, File, Set<Slot>) -> Boolean,
|
||||
val sgdbGame: (String, Int?, String) -> Int?,
|
||||
val sgdb: (String, Int, File, Set<Slot>) -> Boolean,
|
||||
val sgdbExactGame: (String, Int?, String) -> Int? = { _, _, _ -> null },
|
||||
val battleNetArt: (Context, BattleNet.Title) -> Boolean = { _, _ -> false },
|
||||
)
|
||||
|
||||
private val network = Sources(
|
||||
@@ -251,6 +253,8 @@ object AddedGameArt {
|
||||
steam = ::download,
|
||||
sgdbGame = SteamGridDb::gameId,
|
||||
sgdb = SteamGridDb::download,
|
||||
sgdbExactGame = SteamGridDb::exactGameId,
|
||||
battleNetArt = { context, title -> BattleNet.fetchCovers(context, listOf(BattleNet.artTitle(title))) },
|
||||
)
|
||||
|
||||
private val EXTRAS = setOf(Slot.LOGO, Slot.ICON)
|
||||
@@ -288,6 +292,9 @@ object AddedGameArt {
|
||||
var changed = false
|
||||
for (game in games) {
|
||||
if (forgetOtherAppsArt(context, game)) changed = true
|
||||
if (forgetNameMatchedBattleNetArt(context, game)) changed = true
|
||||
val battleNetTitle = game.storeId?.takeIf { game.source == Store.BATTLENET.id }?.let(BattleNet::title)
|
||||
if (battleNetTitle != null && runCatching { sources.battleNetArt(context, battleNetTitle) }.getOrDefault(false)) changed = true
|
||||
val cache = cacheDir(context, game)
|
||||
val start = missing(context, game)
|
||||
val again = refetch(cache) intersect start
|
||||
@@ -318,7 +325,7 @@ object AddedGameArt {
|
||||
if (need.isNotEmpty() && sgdbKey.isNotEmpty()) {
|
||||
if (sgdbDown) asked = false else try {
|
||||
val gridId = remembered(File(cache, "sgdb-id"), keyChangedAt) {
|
||||
sources.sgdbGame(sgdbKey, match.appId, game.name)?.toString()
|
||||
(if (battleNetTitle != null) sources.sgdbExactGame else sources.sgdbGame)(sgdbKey, match.appId, game.name)?.toString()
|
||||
}?.toIntOrNull()
|
||||
if (gridId != null && sources.sgdb(sgdbKey, gridId, cache, need)) changed = true
|
||||
} catch (e: Exception) {
|
||||
@@ -343,6 +350,21 @@ object AddedGameArt {
|
||||
if (slots.isEmpty()) File(cache, REFETCH).delete() else File(cache, REFETCH).writeText(slots.joinToString(",") { it.key })
|
||||
}
|
||||
|
||||
internal const val BATTLENET_ART_CHECKED = "battlenet-art-2"
|
||||
|
||||
internal fun forgetNameMatchedBattleNetArt(context: Context, game: AddedGames.Game): Boolean {
|
||||
val title = game.storeId?.takeIf { game.source == Store.BATTLENET.id }?.let(BattleNet::title) ?: return false
|
||||
val cache = cacheDir(context, game)
|
||||
val checked = File(cache, BATTLENET_ART_CHECKED)
|
||||
if (title.steam != null || checked.isFile) return false
|
||||
val dropped = EXTRAS.filter { File(cache, SteamGridDb.cacheName(it)).delete() }
|
||||
EXTRAS.forEach { File(cache, SteamGridDb.cacheName(it) + ".src").delete() }
|
||||
listOf("sgdb-id", EXTRAS_TRIED).forEach { File(cache, it).delete() }
|
||||
cache.mkdirs()
|
||||
checked.writeText("")
|
||||
return dropped.isNotEmpty()
|
||||
}
|
||||
|
||||
internal fun forgetOtherAppsArt(context: Context, game: AddedGames.Game): Boolean {
|
||||
val cache = cacheDir(context, game)
|
||||
val recorded = SteamMatch.get(context, game.folder.path)?.takeIf { it.appId != null }
|
||||
|
||||
@@ -70,15 +70,22 @@ object SteamGridDb {
|
||||
if (!tmp.renameTo(f)) { f.delete(); tmp.renameTo(f) }
|
||||
}
|
||||
|
||||
fun gameId(key: String, steamAppId: Int?, name: String): Int? {
|
||||
fun gameId(key: String, steamAppId: Int?, name: String): Int? = gameId(key, steamAppId, name, ::match)
|
||||
|
||||
fun exactGameId(key: String, steamAppId: Int?, name: String): Int? = gameId(key, steamAppId, name, ::exactMatch)
|
||||
|
||||
private fun gameId(key: String, steamAppId: Int?, name: String, pick: (String, List<Pair<Int, String>>) -> Int?): Int? {
|
||||
if (steamAppId != null) {
|
||||
json(key, "$API/games/steam/$steamAppId")?.optJSONObject("data")?.optInt("id")?.takeIf { it > 0 }?.let { return it }
|
||||
}
|
||||
val term = URLEncoder.encode(name, "UTF-8").replace("+", "%20")
|
||||
val results = json(key, "$API/search/autocomplete/$term")?.optJSONArray("data") ?: return null
|
||||
return match(name, (0 until results.length()).map { results.getJSONObject(it) }.map { it.optInt("id") to it.optString("name") })
|
||||
return pick(name, (0 until results.length()).map { results.getJSONObject(it) }.map { it.optInt("id") to it.optString("name") })
|
||||
}
|
||||
|
||||
internal fun exactMatch(name: String, results: List<Pair<Int, String>>): Int? =
|
||||
results.firstOrNull { (id, got) -> id > 0 && AddedGameArt.nameMatch(name, got) == 3 }?.first
|
||||
|
||||
internal fun match(name: String, results: List<Pair<Int, String>>): Int? =
|
||||
results.map { (id, got) -> id to AddedGameArt.nameMatch(name, got) }
|
||||
.filter { it.second > 0 && it.first > 0 }
|
||||
|
||||
Reference in new issue
Block a user