Feat/store game artwork (#976)

This commit is contained in:
FX1922 authored and GitHub committed 2026-10-17 01:19:02 -04:00
1 parent fb0f73e300
commit dc7ed61d38
11 files changed
+119 -17

No files matched your search

@@ -168,5 +168,6 @@ class AddedGameArtLookupTest {
@Test fun eachSlotAsksItsOwnEndpoint() {
assertEquals("heroes/game/5?nsfw=false&humor=false", SteamGridDb.path(5, AddedGameArt.Slot.BACKGROUND))
assertEquals("grids/game/5?dimensions=600x900&nsfw=false&humor=false", SteamGridDb.path(5, AddedGameArt.Slot.COVER))
assertEquals("grids/game/5?dimensions=460x215,920x430&nsfw=false&humor=false", SteamGridDb.path(5, AddedGameArt.Slot.WIDE))
}
}
@@ -44,6 +44,20 @@ class SteamGridTest {
assertFalse(File(grid, "620p.png").exists())
}
@Test fun aWideCoverGoesToTheUnsuffixedGridFileAndComesBackFromSteam() {
File(LinuxRuntime.rootDir(app), "root/.local/share/Steam/userdata/123/config").mkdirs()
val picked = image("wide.png", 14)
assertTrue(SteamGameArt.choose(app, game(), AddedGameArt.Slot.WIDE, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path)))
assertEquals(14L, File(grid, "620.png").length())
assertFalse(File(grid, "620p.png").exists())
assertTrue(SteamGameArt.chosenFile(app, 620, AddedGameArt.Slot.WIDE)!!.name.matches(Regex("chosen-header-\\d+\\.png")))
assertNull(SteamGameArt.chosenFile(app, 620, AddedGameArt.Slot.COVER))
File(grid, "620.png").delete()
assertTrue(SteamGrid.sync(app, listOf(target())))
assertNull(SteamGameArt.chosenFile(app, 620, AddedGameArt.Slot.WIDE))
}
@Test fun artSetInSteamIsTakenOverAndRemovingItInSteamDropsIt() {
File(LinuxRuntime.rootDir(app), "root/.local/share/Steam/userdata/123/config").mkdirs()
grid.mkdirs()
@@ -0,0 +1,56 @@
package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
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 StoreGameArtTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@Before fun setUp() {
AddedGamesPublisher.now = true
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
}
private fun install(store: Store, id: String, title: String): File {
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.installRoot(app), store), StoreInstallRoot.folderName(title, id))
File(folder, "Game.exe").apply { parentFile!!.mkdirs(); writeText("game") }
StoreGameSidecar(store, id, title, "Game.exe").write(folder)
return folder
}
@Test fun anArtChoiceOnAStoreGameIsKeptShownAndResetsWithoutTouchingItsTitle() {
for ((store, id, title) in listOf(Triple(Store.GOG, "1207658924", "Heroes III"), Triple(Store.EPIC, "abc", "Celeste"), Triple(Store.AMAZON, "amzn1.x", "Yakuza 0"))) {
val folder = install(store, id, title)
val image = File(tmp.root, "$id.png").apply { writeBytes(ByteArray(9) { 1 }) }
val option = AddedGameArt.Option(AddedGameArt.FILE, image.path, image.path)
assertTrue(AddedGameEdits.setArt(app, folder.path, AddedGameArt.Slot.COVER, option))
val game = AddedGames.single(app, folder.path)!!
assertEquals(title, game.name)
assertEquals(store.id, game.source)
val shown = Library.addedGame(app, game)
assertEquals(AddedGameArt.chosen(AddedGameArt.cacheDir(app, game), AddedGameArt.Slot.COVER), shown.art)
assertEquals(9L, shown.art?.length())
AddedGameEdits.resetArt(app, folder.path, AddedGameArt.Slot.COVER)
assertNull(AddedGameArt.chosen(AddedGameArt.cacheDir(app, game), AddedGameArt.Slot.COVER))
}
}
}