mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Merge pull request #38 from The412Banner/feat/duckstation-play
PS1 one-tap launch, one tile per disc, controller lands on the main button and first game
This commit is contained in:
commit
e4613d39ab
3 files changed
+115
-15
No files matched your search
@@ -104,7 +104,9 @@ object Library {
|
||||
// The root itself only one deep, for a file left loose there.
|
||||
val systemDirs = romsRoot.listFiles { f -> f.isDirectory && f.name.lowercase() in spec.folders }.orEmpty().toList()
|
||||
val dirs = LinkedHashSet<File>()
|
||||
for (top in systemDirs) top.walkTopDown().maxDepth(3).filter { it.isDirectory }.forEach { dirs.add(it) }
|
||||
// A BIOS folder holds the console's firmware, not games (psx/bios/SCPH1001.BIN).
|
||||
for (top in systemDirs) top.walkTopDown().maxDepth(3).onEnter { it.name.lowercase() !in firmwareFolders }
|
||||
.filter { it.isDirectory }.forEach { dirs.add(it) }
|
||||
dirs.add(romsRoot)
|
||||
// ...and not into another system's folder: a PS3 .iso in ps3/ is not a PS2 game.
|
||||
romsRoot.listFiles { f -> f.isDirectory && f.name.lowercase() !in systemFolders }?.forEach { dirs.add(it) }
|
||||
@@ -117,10 +119,15 @@ object Library {
|
||||
art = File(dir, "PS3_GAME/ICON0.PNG").takeIf { it.isFile }))
|
||||
continue
|
||||
}
|
||||
dir.listFiles()?.sortedBy { it.name.lowercase() }?.forEach { f ->
|
||||
val files = dir.listFiles()?.sortedBy { it.name.lowercase() }.orEmpty()
|
||||
// A disc sheet (.cue, .gdi) names its track files and a playlist (.m3u) its
|
||||
// discs: the sheet is the game, what it names is part of it. A .bin beside a
|
||||
// .cue of the same name is a track even when the sheet can't be read.
|
||||
val parts = files.filter { it.isFile && it.extension.lowercase() in sheetExts }.flatMap(::sheetParts).toSet()
|
||||
files.forEach { f ->
|
||||
val ext = f.extension.lowercase()
|
||||
// A .bin beside a .cue is a track, not a game.
|
||||
if (f.isFile && ext in spec.exts && !(ext == "bin" && File(dir, f.nameWithoutExtension + ".cue").isFile)) {
|
||||
if (f.isFile && ext in spec.exts && f.name.lowercase() !in parts &&
|
||||
!(ext == "bin" && File(dir, f.nameWithoutExtension + ".cue").isFile)) {
|
||||
val rel = f.relativeTo(romsRoot).path
|
||||
games.add(Rom(displayTitle(f.nameWithoutExtension.removeSuffix(".dec")), f, "/root/ROMs/$rel", spec.id))
|
||||
}
|
||||
@@ -134,6 +141,25 @@ object Library {
|
||||
}
|
||||
}
|
||||
|
||||
private val firmwareFolders = setOf("bios", "firmware")
|
||||
private val sheetExts = setOf("cue", "gdi", "m3u")
|
||||
|
||||
/** The file names (lower case) a .cue, .gdi or .m3u refers to, from its own folder. */
|
||||
private fun sheetParts(sheet: File): List<String> = runCatching {
|
||||
if (sheet.length() > 64 * 1024) return emptyList()
|
||||
sheet.readLines().mapNotNull { line ->
|
||||
val t = line.trim()
|
||||
when (sheet.extension.lowercase()) {
|
||||
// FILE "Tekken 3 (USA) (Track 1).bin" BINARY
|
||||
"cue" -> Regex("^FILE\\s+\"([^\"]+)\"", RegexOption.IGNORE_CASE).find(t)?.groupValues?.get(1)
|
||||
?: Regex("^FILE\\s+(\\S+)", RegexOption.IGNORE_CASE).find(t)?.groupValues?.get(1)
|
||||
// 1 0 4 2352 "track01.bin" 0 / 1 0 4 2352 track01.bin 0
|
||||
"gdi" -> Regex("\"([^\"]+)\"").find(t)?.groupValues?.get(1) ?: t.split(Regex("\\s+")).getOrNull(4)
|
||||
else -> t.takeIf { it.isNotEmpty() && !it.startsWith("#") }
|
||||
}
|
||||
}.map { File(it.replace('\\', '/')).name.lowercase() }
|
||||
}.getOrDefault(emptyList())
|
||||
|
||||
/**
|
||||
* What RPCS3 has installed on its own HDD - packages (PSN games) land in dev_hdd0/game/<ID>
|
||||
* with a PARAM.SFO for the title and an EBOOT to boot - as RPCS3's own file list would show
|
||||
|
||||
@@ -273,6 +273,10 @@ private class FrontFocus {
|
||||
val items = HashMap<String, FocusRequester>()
|
||||
val attached = HashMap<String, Int>()
|
||||
var last: String? = null
|
||||
// The first tile of the page's grid: Down from the page's buttons goes to it, not to whichever
|
||||
// tile happens to sit under the button.
|
||||
val firstTile = FocusRequester()
|
||||
var firstTileAttached = 0
|
||||
fun paneEntry(): FocusRequester {
|
||||
val id = last
|
||||
return when {
|
||||
@@ -285,6 +289,24 @@ private class FrontFocus {
|
||||
companion object { const val PRIMARY = "\u0000primary" }
|
||||
}
|
||||
|
||||
/** Down from this button goes to the first tile of the page's grid, when there is one. */
|
||||
@Composable
|
||||
private fun Modifier.downToFirstTile(): Modifier {
|
||||
val ff = LocalFrontFocus.current ?: return this
|
||||
return this.focusProperties { down = if (ff.firstTileAttached > 0) ff.firstTile else FocusRequester.Default }
|
||||
}
|
||||
|
||||
/** Marks the first tile of the page's grid. */
|
||||
@Composable
|
||||
private fun Modifier.firstTile(): Modifier {
|
||||
val ff = LocalFrontFocus.current ?: return this
|
||||
DisposableEffect(Unit) {
|
||||
ff.firstTileAttached++
|
||||
onDispose { ff.firstTileAttached-- }
|
||||
}
|
||||
return this.focusRequester(ff.firstTile)
|
||||
}
|
||||
|
||||
/** Lets the pane come back to this control: it is remembered when focused. */
|
||||
@Composable
|
||||
private fun Modifier.paneItem(id: String): Modifier {
|
||||
@@ -328,7 +350,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
LaunchedEffect(s.isHomeApp) { if (!s.isHomeApp && selected == "android-apps") selected = "steam" }
|
||||
remember { Motion.scale = Settings.Global.getFloat(ctx.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f); true }
|
||||
|
||||
BoxWithConstraints(modifier = Modifier.fillMaxSize().background(colors.background).systemBarsPadding()) {
|
||||
var anyFocused by remember { mutableStateOf(false) }
|
||||
BoxWithConstraints(modifier = Modifier.fillMaxSize().background(colors.background).systemBarsPadding().onFocusChanged { anyFocused = it.hasFocus }) {
|
||||
val wide = maxWidth >= 640.dp
|
||||
val railSelection = when {
|
||||
s.pageKey == "performance" || s.pageKey == "protons" -> "setup"
|
||||
@@ -364,6 +387,17 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
kotlinx.coroutines.delay(100)
|
||||
}
|
||||
}
|
||||
// A tile or button that opens a page goes away with the page it was on, and focus with it;
|
||||
// the pad then had nothing to move from (a press landed back on the rail's first item). So
|
||||
// once the new page is in, a controller lands on its main button.
|
||||
val inputModeManager = LocalInputModeManager.current
|
||||
LaunchedEffect(selected, s.pageKey) {
|
||||
kotlinx.coroutines.delay(450)
|
||||
if (!anyFocused && inputModeManager.inputMode == InputMode.Keyboard) runCatching {
|
||||
if (frontFocus.primaryAttached > 0) frontFocus.primary.requestFocus()
|
||||
else frontFocus.railFor(railSelection).requestFocus()
|
||||
}
|
||||
}
|
||||
val back = if (wide) FocusDirection.Left else FocusDirection.Up
|
||||
val paneFocus = Modifier
|
||||
.focusProperties {
|
||||
@@ -998,7 +1032,7 @@ private fun PrimaryButton(text: String, enabled: Boolean = true, main: Boolean =
|
||||
frontFocus.primaryAttached++
|
||||
onDispose { frontFocus.primaryAttached-- }
|
||||
}
|
||||
val track = if (frontFocus == null) Modifier.paneItem("btn:$text") else Modifier
|
||||
val track = (if (frontFocus == null) Modifier.paneItem("btn:$text") else Modifier).downToFirstTile()
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src) && enabled
|
||||
val pressed by src.collectIsPressedAsState()
|
||||
@@ -1033,7 +1067,7 @@ internal fun SecondaryButton(text: String, enabled: Boolean = true, onClick: ()
|
||||
val edge by animateColorAsState(if (hot) pal.signal else pal.line2, Motion.tw(250), label = "secEdge")
|
||||
val fill by animateColorAsState(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f), Motion.tw(250), label = "secFill")
|
||||
Box(
|
||||
modifier = Modifier.paneItem("btn:$text").graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).border(1.dp, edge, Shape12)
|
||||
modifier = Modifier.paneItem("btn:$text").downToFirstTile().graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).border(1.dp, edge, Shape12)
|
||||
.alpha(if (enabled) 1f else 0.5f)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick)
|
||||
.controllerConfirm(enabled = enabled, onClick = onClick)
|
||||
@@ -1051,7 +1085,7 @@ private fun Cog(onClick: () -> Unit) {
|
||||
val edge by animateColorAsState(if (hot) pal.signal else pal.line2, Motion.tw(250), label = "cogEdge")
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem("cog").size(42.dp).clip(Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, Shape12)
|
||||
modifier = Modifier.paneItem("cog").downToFirstTile().size(42.dp).clip(Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, Shape12)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick),
|
||||
) { Icon(Icons.Filled.Settings, "Settings", tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(18.dp).rotate(rot)) }
|
||||
}
|
||||
@@ -1092,7 +1126,8 @@ private fun ArtGrid(tiles: List<Tile>, wide: Boolean = false) {
|
||||
for (t in row) key(t.key) {
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
Box(modifier = Modifier.width(tileWidth).zIndex(if (hot) 1f else 0f)) { GameTile(t, wide, square, src, hot, Modifier.paneItem("tile:" + t.key)) }
|
||||
val track = Modifier.paneItem("tile:" + t.key).then(if (t === tiles.first()) Modifier.firstTile() else Modifier)
|
||||
Box(modifier = Modifier.width(tileWidth).zIndex(if (hot) 1f else 0f)) { GameTile(t, wide, square, src, hot, track) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user