Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
ios: button mapping card and button test on the Controllers page
Haseenesssa7e301fda1f1
diff --git a/frontend-ios/README.md b/frontend-ios/README.mdindex 27c17b6f..7f881a2a 100644--- a/frontend-ios/README.md+++ b/frontend-ios/README.md@@ -33,7 +33,7 @@ All boundary types are in `Sources/ShellUI/ShellInputs.swift` and `ShellArtwork.- `ShellActions`: selection, Play, setting changes, game-data and cloud-folder requests, reset, log, app update and Back. The game ID is always passed.- `ShellInput`: an optional semantic controller event with an increasing sequence and the device that sent it (`InputDevice`: a controller family or the keyboard), so the hints draw that device's glyphs.-`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also edits global physical-controller button mappings, including Swap A and B. These affect games only. Shell menus keep A to confirm and B to go back. Each game's Controller settings can follow global, override individual buttons, disable a button, or explicitly turn the swap off. The demo uses it, the real shell can too.+`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also opens a Button mapping card for the global physical-controller button mappings, including Swap A and B, laid out like the language list: the rows with their values, and a row's options in place of them once picked. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the first controller as it is pressed (hold B to close). Shell menus keep A to confirm and B to go back. Each game's settings have one Button mapping row that opens the same card for that game, which can follow global, override individual buttons, disable a button, or explicitly turn the swap off. The demo uses it, the real shell can too.```swiftLibraryView(@@ -106,6 +106,6 @@ Manrope and its SIL OFL licence are bundled and registered at runtime, with theSeven sample games. With `--real-art` the demo reads real Switch art at runtime from where the Mac launcher keeps it: the banner cache in the host's `~/Library/Application Support/NS Port Builder/artwork/<TITLEID>.jpg` and this checkout's `docs/images`, which the Simulator can read. `--art-dir <folder>` (repeatable) names other folders. A sample entry whose art is found becomes that real game (name and title ID in `SampleData.swift`). Without the files every entry stays fictional, with a square icon drawn in `SampleArt.swift`, so the demo and its tests work on any machine. No picture is part of this package, and `.gitignore` keeps them out.-Other launch arguments: `--screen library|settings|needs-data|needs-update|broken|empty|controllers|controllers-empty|focus`, `--games <n>`, `--select <id>`, `--input-test` (on-screen controller buttons) and `--fold-test` (the foldable stand-in: the running shell in a frame that switches between a 1.4:1 folded size and a larger unfolded one, `--unfolded` to start open).+Other launch arguments: `--screen library|settings|needs-data|needs-update|broken|empty|controllers|controllers-empty|controllers-mapping|controllers-test|focus`, `--games <n>`, `--select <id>`, `--input-test` (on-screen controller buttons) and `--fold-test` (the foldable stand-in: the running shell in a frame that switches between a 1.4:1 folded size and a larger unfolded one, `--unfolded` to start open).`UITests/` checks navigation, controller input, setting edits, rotation and the fold. `ShellCaptureTests` captures every screen. With `TEST_RUNNER_SHOT_DIR` set it also writes the PNGs to that folder, and `TEST_RUNNER_SHOT_REAL_ART=1` launches the demo with `--real-art`.diff --git a/frontend-ios/Sources/ShellControllers/GamepadAdapter.swift b/frontend-ios/Sources/ShellControllers/GamepadAdapter.swiftindex c3f2f443..a9d40adc 100644--- a/frontend-ios/Sources/ShellControllers/GamepadAdapter.swift+++ b/frontend-ios/Sources/ShellControllers/GamepadAdapter.swift@@ -21,6 +21,14 @@ public struct ConnectedController: Equatable, Sendable {@MainActor public final class GamepadAdapter {public var onInput: (ShellInput.Action, InputDevice) -> Void = { _, _ in }public var onControllersChange: ([ConnectedController]) -> Void = { _ in }+ /// Every state of any controller, for the button test. Nil (the default) reports none. Set, it reports the state of+ /// the first controller at once, then each change of whichever controller moved.+ public var onSnapshot: ((PadSnapshot) -> Void)? {+ didSet {+ guard let onSnapshot, let pad = GCController.controllers().first else { return }+ onSnapshot(Self.snapshot(of: pad.physicalInputProfile, name: Self.name(of: pad)))+ }+ }private var mapper = PadMapper()private var observers: [NSObjectProtocol] = []@@ -75,9 +83,14 @@ public struct ConnectedController: Equatable, Sendable {for pad in GCController.controllers() {let id = Self.id(of: pad)let family = ControllerFamily(productCategory: pad.productCategory)+ let name = Self.name(of: pad)pad.physicalInputProfile.valueDidChangeHandler = { [weak self] profile, _ inlet state = Self.state(of: profile)- MainActor.assumeIsolated { self?.read(state, controller: id, family: family) }+ let snapshot = Self.snapshot(of: profile, name: name)+ MainActor.assumeIsolated {+ self?.onSnapshot?(snapshot)+ self?.read(state, controller: id, family: family)+ }}}publish()@@ -97,6 +110,32 @@ public struct ConnectedController: Equatable, Sendable {return PadState(x: x, y: y, buttons: buttons)}+ private nonisolated static func name(of pad: GCController) -> String { pad.vendorName ?? pad.productCategory }++ /// Everything the button test draws, by GameController's names: buttonA is the bottom face button on the drawing.+ private nonisolated static func snapshot(of pad: GCPhysicalInputProfile, name: String) -> PadSnapshot {+ func pressed(_ name: String) -> Bool { pad.buttons[name]?.isPressed ?? false }+ let names: [(String, PadElement)] = [(GCInputButtonA, .a), (GCInputButtonB, .b), (GCInputButtonX, .x), (GCInputButtonY, .y),+ (GCInputLeftShoulder, .leftBumper), (GCInputRightShoulder, .rightBumper),+ (GCInputLeftTrigger, .leftTrigger), (GCInputRightTrigger, .rightTrigger),+ (GCInputLeftThumbstickButton, .leftStick), (GCInputRightThumbstickButton, .rightStick),+ (GCInputButtonOptions, .view), (GCInputButtonMenu, .menu), (GCInputButtonHome, .home)]+ var held = Set(names.filter { pressed($0.0) }.map(\.1))+ if let dpad = pad.dpads[GCInputDirectionPad] {+ if dpad.up.isPressed { held.insert(.up) }+ if dpad.down.isPressed { held.insert(.down) }+ if dpad.left.isPressed { held.insert(.left) }+ if dpad.right.isPressed { held.insert(.right) }+ }+ func stick(_ name: String) -> CGPoint {+ guard let s = pad.dpads[name] else { return .zero }+ return CGPoint(x: Double(s.xAxis.value), y: Double(s.yAxis.value))+ }+ return PadSnapshot(name: name, pressed: held, leftStick: stick(GCInputLeftThumbstick), rightStick: stick(GCInputRightThumbstick),+ leftTrigger: Double(pad.buttons[GCInputLeftTrigger]?.value ?? 0),+ rightTrigger: Double(pad.buttons[GCInputRightTrigger]?.value ?? 0))+ }+private func read(_ state: PadState, controller: String, family: ControllerFamily) {let (pressed, released) = mapper.changes(controller: controller, state: state)for action in released where repeating?.action == action && repeating?.controller == controller { stopRepeat() }diff --git a/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift b/frontend-ios/Sources/ShellDemo/ShellDemoApp.swiftindex 035e3e6b..5b7eba5d 100644--- a/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift+++ b/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift@@ -21,6 +21,7 @@ import ShellControllers/// The demo owns sample values. None of this state or callback simulation is part of ShellUI.struct DemoScreen: View {@State private var padMap = PadMap()+ @State private var padSnapshot: PadSnapshot?@State private var games = SampleData.games@State private var notice: String?@State private var input: ShellInput?@@ -84,7 +85,12 @@ struct DemoScreen: View {initialDetailOpen: scenario == "settings",initialControllersOpen: scenario.hasPrefix("controllers"),initialShellSettingsOpen: scenario == "shell-settings",- initialFocusVisible: scenario == "focus", globalPadMap: padMap)+ initialFocusVisible: scenario == "focus", globalPadMap: padMap,+ // The test's screen shows a few buttons held until a real controller moves.+ padSnapshot: padSnapshot ?? (scenario == "controllers-test"+ ? PadSnapshot(name: "Demo", pressed: [.a, .leftBumper, .up], leftStick: CGPoint(x: 0.6, y: 0.5), rightTrigger: 0.7) : nil),+ initialPadMapping: scenario == "controllers-mapping" ? ControllersView.mappingID : nil,+ initialButtonTestOpen: scenario == "controllers-test")}/// A stand-in for the foldable while no Simulator runtime for it is installed: the same running shell in a frame@@ -168,7 +174,11 @@ struct DemoScreen: View {onClearShellCloud: { ShellSettingsStore.current.clearCloudSavesFolderName() },onGlobalPadMapChange: { button, value inif button == "swapAB" { padMap.setSwapAB(value == "1") } else { padMap.set(button, to: value) }- }, onGlobalPadMapReset: { padMap = PadMap() })+ }, onGlobalPadMapReset: { padMap = PadMap() },+ onButtonTest: { open in+ gamepads.onSnapshot = open ? { padSnapshot = $0 } : nil+ if !open { padSnapshot = nil }+ })}}diff --git a/frontend-ios/Sources/ShellHost/GamePadMapStore.swift b/frontend-ios/Sources/ShellHost/GamePadMapStore.swiftindex f8b1126d..714f3bcf 100644--- a/frontend-ios/Sources/ShellHost/GamePadMapStore.swift+++ b/frontend-ios/Sources/ShellHost/GamePadMapStore.swift@@ -16,6 +16,7 @@ public struct GamePadMapStore {return "custom"}public func change(_ setting: String, value: String) {+ if setting == PadMappingRows.resetID { reset(); return }var map = entriesif setting == "pad.swapAB" {switch value {diff --git a/frontend-ios/Sources/ShellHost/ShellHostModel.swift b/frontend-ios/Sources/ShellHost/ShellHostModel.swiftindex 91c52ce2..c69c6bfc 100644--- a/frontend-ios/Sources/ShellHost/ShellHostModel.swift+++ b/frontend-ios/Sources/ShellHost/ShellHostModel.swift@@ -59,6 +59,8 @@ public struct ShellHostConfig: Sendable {public var log: LogPresentation?public private(set) var globalPadMap = PadMap()+ /// The last controller state, sent only while the button test is open.+ public private(set) var padSnapshot: PadSnapshot?@ObservationIgnored private let config: ShellHostConfig@ObservationIgnored private let launcher: any GameLauncher@@ -299,7 +301,8 @@ public struct ShellHostConfig: Sendable {else { self.shellSettings.setPadButton(setting, to: value) }self.refreshAll()},- onGlobalPadMapReset: { [weak self] in self?.shellSettings.resetPadMap(); self?.refreshAll() })+ onGlobalPadMapReset: { [weak self] in self?.shellSettings.resetPadMap(); self?.refreshAll() },+ onButtonTest: { [weak self] open in self?.buttonTest(open) })}public func change(_ id: String, setting: String, value: String) {@@ -460,6 +463,12 @@ public struct ShellHostConfig: Sendable {public func stopControllers() { adapter.stop() }+ /// The button test opened or closed: the adapter reports every controller state in between.+ public func buttonTest(_ open: Bool) {+ adapter.onSnapshot = open ? { [weak self] in self?.padSnapshot = $0 } : nil+ if !open { padSnapshot = nil }+ }+static func info(for c: ConnectedController) -> ControllerInfo {ControllerInfo(id: c.id, name: c.name, player: hostText("Player \(c.player)"), batteryPercent: c.batteryPercent, charging: c.charging)}diff --git a/frontend-ios/Sources/ShellHost/ShellHostView.swift b/frontend-ios/Sources/ShellHost/ShellHostView.swiftindex dc1cabbd..45802e41 100644--- a/frontend-ios/Sources/ShellHost/ShellHostView.swift+++ b/frontend-ios/Sources/ShellHost/ShellHostView.swift@@ -16,7 +16,8 @@ public struct ShellHostView: View {public var body: some View {LibraryView(games: model.details, controllers: model.controllers, actions: model.actions, input: model.input,- initialSelection: initialSelection, initialDetailOpen: initialDetailOpen, globalPadMap: model.globalPadMap)+ initialSelection: initialSelection, initialDetailOpen: initialDetailOpen, globalPadMap: model.globalPadMap,+ padSnapshot: model.padSnapshot).sheet(item: $model.log) { LogView(log: $0) }.alert(Text(verbatim: hostText("Shell")), isPresented: Binding(get: { model.notice != nil }, set: { if !$0 { model.notice = nil } })) {Button(hostText("OK")) { model.notice = nil }diff --git a/frontend-ios/Sources/ShellUI/ButtonTestView.swift b/frontend-ios/Sources/ShellUI/ButtonTestView.swiftnew file mode 100644index 00000000..6c216ecb--- /dev/null+++ b/frontend-ios/Sources/ShellUI/ButtonTestView.swift@@ -0,0 +1,256 @@+import SwiftUI++/// The button test: an Xbox controller drawn whole, each button lighting up while it is held, the sticks moving and the+/// triggers filling as they are pulled. Every button belongs to the test while it is open, so a controller closes it by+/// holding B. Touch closes it with ×, a keyboard with Escape.+struct ButtonTestView: View {+ let snapshot: PadSnapshot?+ let close: () -> Void+ /// How long B is held to close.+ static let holdToClose: Double = 1.5+ @State private var holding = false+ @State private var holdTask: Task<Void, Never>?+ @Environment(\.accessibilityReduceMotion) private var reduceMotion++ var body: some View {+ VStack(alignment: .leading, spacing: 0) {+ HStack(alignment: .center, spacing: 12) {+ VStack(alignment: .leading, spacing: 2) {+ Text(ShellStrings.text("Button test")).shellType(ShellType.flowTitle(20)).lineLimit(1)+ .accessibilityAddTraits(.isHeader).accessibilityIdentifier("buttonTest.title")+ Text(snapshot.map { $0.name.isEmpty ? ShellStrings.text("Controller") : $0.name } ?? ShellStrings.text("Press any button on a controller"))+ .shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).lineLimit(1)+ }+ Spacer(minLength: 8)+ Button(action: close) {+ Image(systemName: "xmark").font(.system(size: 14, weight: .semibold)).frame(width: 44, height: 44)+ .background(.white.opacity(0.08), in: Circle()).contentShape(Circle())+ }+ .buttonStyle(.plain)+ .accessibilityLabel(ShellStrings.text("Close"))+ .accessibilityIdentifier("buttonTest.close")+ .shellTarget("test.close", radius: 22, action: close)+ }+ .padding(.horizontal, 20).padding(.top, 14).padding(.bottom, 8)+ Rectangle().fill(ShellPalette.hairline).frame(height: 1)+ XboxControllerDiagram(snapshot: snapshot ?? PadSnapshot())+ .aspectRatio(XboxControllerDiagram.design.width / XboxControllerDiagram.design.height, contentMode: .fit)+ .frame(maxWidth: .infinity)+ .padding(.horizontal, 24).padding(.top, 22).padding(.bottom, 10)+ .accessibilityElement(children: .ignore)+ .accessibilityLabel(ShellStrings.text("Controller"))+ .accessibilityValue(pressedText)+ .accessibilityIdentifier("buttonTest.diagram")+ Text(pressedText).shellText(14.5, .semibold).foregroundStyle(ShellPalette.cream)+ .lineLimit(2).frame(maxWidth: .infinity, minHeight: 40).multilineTextAlignment(.center)+ .padding(.horizontal, 20)+ .accessibilityIdentifier("buttonTest.pressed")+ HStack(spacing: 10) {+ ZStack {+ Circle().stroke(.white.opacity(0.15), lineWidth: 3)+ Circle().trim(from: 0, to: holding ? 1 : 0).stroke(ShellPalette.cream, style: StrokeStyle(lineWidth: 3, lineCap: .round))+ .rotationEffect(.degrees(-90))+ Text(verbatim: "B").font(ShellFonts.fixed(10, weight: .bold))+ }.frame(width: 22, height: 22).accessibilityHidden(true)+ Text(ShellStrings.text("Hold B to close")).shellText(13, .medium, relativeTo: .footnote).foregroundStyle(.white.opacity(0.6))+ }+ .frame(maxWidth: .infinity).padding(.bottom, 18).padding(.top, 4)+ }+ .frame(maxWidth: 620)+ .background(Color(red: 0.075, green: 0.075, blue: 0.082), in: RoundedRectangle(cornerRadius: 26))+ .overlay(RoundedRectangle(cornerRadius: 26).strokeBorder(.white.opacity(0.10)))+ .shadow(color: .black.opacity(0.5), radius: 40)+ .accessibilityElement(children: .contain)+ .accessibilityAddTraits(.isModal)+ .accessibilityIdentifier("buttonTest")+ .onChange(of: snapshot?.pressed.contains(.b) ?? false) { _, held in held ? startHold() : stopHold() }+ .onDisappear { holdTask?.cancel() }+ }++ private var pressedText: String {+ let pressed = PadElement.allCases.filter { snapshot?.pressed.contains($0) == true }.map(XboxControllerDiagram.name)+ return pressed.isEmpty ? ShellStrings.text("No button held") : pressed.joined(separator: " + ")+ }++ private func startHold() {+ withAnimation(.linear(duration: Self.holdToClose)) { holding = true }+ holdTask?.cancel()+ holdTask = Task {+ try? await Task.sleep(for: .seconds(Self.holdToClose))+ if !Task.isCancelled { close() }+ }+ }+ private func stopHold() {+ holdTask?.cancel()+ withAnimation(reduceMotion ? nil : .easeOut(duration: 0.2)) { holding = false }+ }+}++/// An Xbox controller in outline, drawn in a 320 × 220 design space and scaled to fit. Held buttons light up: the face+/// buttons in their own colours, everything else in cream.+struct XboxControllerDiagram: View {+ let snapshot: PadSnapshot+ static let design = CGSize(width: 320, height: 220)++ static func name(_ element: PadElement) -> String {+ switch element {+ case .a: "A"+ case .b: "B"+ case .x: "X"+ case .y: "Y"+ case .leftBumper: "LB"+ case .rightBumper: "RB"+ case .leftTrigger: "LT"+ case .rightTrigger: "RT"+ case .leftStick: "LS"+ case .rightStick: "RS"+ case .view: "View"+ case .menu: "Menu"+ case .home: "Xbox"+ case .up: ShellStrings.text("D-pad up")+ case .down: ShellStrings.text("D-pad down")+ case .left: ShellStrings.text("D-pad left")+ case .right: ShellStrings.text("D-pad right")+ }+ }++ var body: some View {+ GeometryReader { geometry in+ let s = min(geometry.size.width / Self.design.width, geometry.size.height / Self.design.height)+ ZStack(alignment: .topLeading) {+ trigger(.leftTrigger, value: snapshot.leftTrigger, x: 62, s: s)+ trigger(.rightTrigger, value: snapshot.rightTrigger, x: 216, s: s)+ bumper(.leftBumper, x: 52, s: s)+ bumper(.rightBumper, x: 196, s: s)+ ControllerBody()+ .fill(Color.white.opacity(0.06))+ .overlay(ControllerBody().stroke(Color.white.opacity(0.35), lineWidth: max(1, 1.6 * s)))+ .frame(width: Self.design.width * s, height: Self.design.height * s)+ stick(.leftStick, at: CGPoint(x: 88, y: 92), offset: snapshot.leftStick, s: s)+ stick(.rightStick, at: CGPoint(x: 202, y: 140), offset: snapshot.rightStick, s: s)+ dpad(center: CGPoint(x: 118, y: 140), s: s)+ face(.y, at: CGPoint(x: 240, y: 70), color: Color(red: 0.98, green: 0.80, blue: 0.20), s: s)+ face(.x, at: CGPoint(x: 219, y: 92), color: Color(red: 0.25, green: 0.55, blue: 1.0), s: s)+ face(.b, at: CGPoint(x: 261, y: 92), color: Color(red: 0.95, green: 0.30, blue: 0.28), s: s)+ face(.a, at: CGPoint(x: 240, y: 114), color: Color(red: 0.35, green: 0.80, blue: 0.30), s: s)+ small(.view, symbol: "rectangle.on.rectangle", at: CGPoint(x: 138, y: 92), s: s)+ small(.menu, symbol: "line.3.horizontal", at: CGPoint(x: 182, y: 92), s: s)+ home(at: CGPoint(x: 160, y: 60), s: s)+ }+ .frame(width: Self.design.width * s, height: Self.design.height * s)+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ }+ }++ private func held(_ e: PadElement) -> Bool { snapshot.pressed.contains(e) }++ private func place(_ view: some View, center: CGPoint, size: CGSize, s: CGFloat) -> some View {+ view.frame(width: size.width * s, height: size.height * s)+ .position(x: center.x * s, y: center.y * s)+ }++ private func trigger(_ e: PadElement, value: Double, x: CGFloat, s: CGFloat) -> some View {+ let on = held(e) || value > 0.05+ let shape = UnevenRoundedRectangle(topLeadingRadius: 10 * s, bottomLeadingRadius: 3 * s, bottomTrailingRadius: 3 * s, topTrailingRadius: 10 * s)+ return place(+ ZStack(alignment: .bottom) {+ shape.fill(Color.white.opacity(0.06))+ shape.fill(ShellPalette.cream.opacity(0.9)).scaleEffect(x: 1, y: max(0, min(1, held(e) && value < 0.05 ? 1 : value)), anchor: .bottom)+ shape.stroke(Color.white.opacity(on ? 0.9 : 0.35), lineWidth: max(1, 1.4 * s))+ Text(Self.name(e)).font(ShellFonts.fixed(9 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))+ .frame(maxHeight: .infinity)+ },+ center: CGPoint(x: x + 21, y: 13), size: CGSize(width: 42, height: 22), s: s)+ }++ private func bumper(_ e: PadElement, x: CGFloat, s: CGFloat) -> some View {+ let on = held(e)+ return place(+ ZStack {+ Capsule().fill(on ? ShellPalette.cream : Color.white.opacity(0.06))+ Capsule().stroke(Color.white.opacity(on ? 0.9 : 0.35), lineWidth: max(1, 1.4 * s))+ Text(Self.name(e)).font(ShellFonts.fixed(8 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))+ },+ center: CGPoint(x: x + 36, y: 32), size: CGSize(width: 72, height: 12), s: s)+ }++ private func stick(_ e: PadElement, at c: CGPoint, offset: CGPoint, s: CGFloat) -> some View {+ let on = held(e)+ let moved = hypot(offset.x, offset.y) > 0.15+ return ZStack {+ place(Circle().fill(Color.black.opacity(0.35)).overlay(Circle().stroke(Color.white.opacity(0.25), lineWidth: max(1, s))),+ center: c, size: CGSize(width: 46, height: 46), s: s)+ place(Circle().fill(on ? ShellPalette.cream : Color(white: moved ? 0.42 : 0.26))+ .overlay(Circle().stroke(Color.white.opacity(on || moved ? 0.9 : 0.4), lineWidth: max(1, 1.4 * s))),+ center: CGPoint(x: c.x + offset.x * 10, y: c.y - offset.y * 10), size: CGSize(width: 30, height: 30), s: s)+ }+ }++ private func dpad(center c: CGPoint, s: CGFloat) -> some View {+ let arms: [(PadElement, CGFloat, CGFloat)] = [(.up, 0, -12), (.down, 0, 12), (.left, -12, 0), (.right, 12, 0)]+ return ZStack {+ place(RoundedRectangle(cornerRadius: 3 * s).fill(Color.white.opacity(0.10)), center: c, size: CGSize(width: 12, height: 12), s: s)+ ForEach(arms, id: \.0) { e, dx, dy in+ place(RoundedRectangle(cornerRadius: 3 * s).fill(held(e) ? ShellPalette.cream : Color.white.opacity(0.10))+ .overlay(RoundedRectangle(cornerRadius: 3 * s).stroke(Color.white.opacity(held(e) ? 0.9 : 0.35), lineWidth: max(1, s))),+ center: CGPoint(x: c.x + dx, y: c.y + dy), size: CGSize(width: 12, height: 12), s: s)+ }+ }+ }++ private func face(_ e: PadElement, at c: CGPoint, color: Color, s: CGFloat) -> some View {+ let on = held(e)+ return place(+ ZStack {+ Circle().fill(on ? color : Color.black.opacity(0.35))+ Circle().stroke(on ? Color.white : color.opacity(0.8), lineWidth: max(1, 1.5 * s))+ Text(Self.name(e)).font(ShellFonts.fixed(11 * s, weight: .heavy)).foregroundStyle(on ? .black : color)+ }+ .shadow(color: on ? color.opacity(0.8) : .clear, radius: 8 * s),+ center: c, size: CGSize(width: 20, height: 20), s: s)+ }++ private func small(_ e: PadElement, symbol: String, at c: CGPoint, s: CGFloat) -> some View {+ let on = held(e)+ return place(+ ZStack {+ Circle().fill(on ? ShellPalette.cream : Color.black.opacity(0.35))+ Circle().stroke(Color.white.opacity(on ? 0.9 : 0.35), lineWidth: max(1, s))+ Image(systemName: symbol).font(.system(size: 6 * s, weight: .bold)).foregroundStyle(on ? .black : .white.opacity(0.7))+ },+ center: c, size: CGSize(width: 14, height: 14), s: s)+ }++ private func home(at c: CGPoint, s: CGFloat) -> some View {+ let on = held(.home)+ return place(+ ZStack {+ Circle().fill(on ? ShellPalette.cream : Color.black.opacity(0.35))+ Circle().stroke(Color.white.opacity(on ? 0.9 : 0.45), lineWidth: max(1, 1.4 * s))+ Image(systemName: "xmark").font(.system(size: 8 * s, weight: .heavy)).foregroundStyle(on ? .black : .white.opacity(0.75))+ },+ center: c, size: CGSize(width: 22, height: 22), s: s)+ }+}++/// The outline of an Xbox controller: a broad top, the two grips curving down and in, a shallow bottom between them.+private struct ControllerBody: Shape {+ func path(in rect: CGRect) -> Path {+ let sx = rect.width / XboxControllerDiagram.design.width, sy = rect.height / XboxControllerDiagram.design.height+ func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: rect.minX + x * sx, y: rect.minY + y * sy) }+ var path = Path()+ path.move(to: p(160, 46))+ path.addCurve(to: p(262, 44), control1: p(200, 46), control2: p(236, 36))+ path.addCurve(to: p(310, 150), control1: p(292, 54), control2: p(304, 100))+ path.addCurve(to: p(268, 212), control1: p(318, 196), control2: p(296, 220))+ path.addCurve(to: p(214, 168), control1: p(244, 206), control2: p(232, 172))+ path.addCurve(to: p(160, 162), control1: p(196, 164), control2: p(178, 162))+ path.addCurve(to: p(106, 168), control1: p(142, 162), control2: p(124, 164))+ path.addCurve(to: p(52, 212), control1: p(88, 172), control2: p(76, 206))+ path.addCurve(to: p(10, 150), control1: p(24, 220), control2: p(2, 196))+ path.addCurve(to: p(58, 44), control1: p(16, 100), control2: p(28, 54))+ path.addCurve(to: p(160, 46), control1: p(84, 36), control2: p(120, 46))+ path.closeSubpath()+ return path+ }+}diff --git a/frontend-ios/Sources/ShellUI/ChoicePicker.swift b/frontend-ios/Sources/ShellUI/ChoicePicker.swiftindex 90f62fcf..2bc6b16d 100644--- a/frontend-ios/Sources/ShellUI/ChoicePicker.swift+++ b/frontend-ios/Sources/ShellUI/ChoicePicker.swift@@ -73,7 +73,6 @@ struct ChoicePickerView: View {let request: ChoiceRequestlet pick: (String) -> Voidlet close: () -> Void- private var prefix: String { request.gameID == ControllersView.mappingID ? "ctl.pick." : "pick." }@Environment(\.accessibilityReduceMotion) private var reduceMotion@Environment(\.shellFocus) private var focus@@ -109,7 +108,7 @@ struct ChoicePickerView: View {.buttonStyle(.plain).accessibilityLabel(ShellStrings.text("Close")).accessibilityIdentifier("choice.close")- .shellTarget("\(prefix)close", radius: 22, action: close)+ .shellTarget("pick.close", radius: 22, action: close)}.padding(.horizontal, 20).padding(.top, 14).padding(.bottom, 8)Rectangle().fill(ShellPalette.hairline).frame(height: 1)@@ -117,11 +116,11 @@ struct ChoicePickerView: View {ScrollViewReader { proxy inScrollView { list }.scrollIndicators(.hidden)- .onAppear { proxy.scrollTo("\(prefix)\(request.row.value)", anchor: .center) }+ .onAppear { proxy.scrollTo("pick.\(request.row.value)", anchor: .center) }.onChange(of: focus.id) { _, id in- guard let id, id.hasPrefix(prefix) else { return }+ guard let id, id.hasPrefix("pick.") else { return }withAnimation(reduceMotion ? nil : .easeOut(duration: 0.15)) {- proxy.scrollTo(id, anchor: id == "\(prefix)close" ? .top : .center)+ proxy.scrollTo(id, anchor: id == "pick.close" ? .top : .center)}}}@@ -150,7 +149,7 @@ struct ChoicePickerView: View {.accessibilityLabel(option.label).accessibilityAddTraits(chosen ? .isSelected : []).accessibilityIdentifier("choice.option.\(option.id)")- .shellTarget("\(prefix)\(option.id)", radius: 10) { pick(option.id) }+ .shellTarget("pick.\(option.id)", radius: 10) { pick(option.id) }}}.padding(10)@@ -161,6 +160,7 @@ struct ChoicePickerView: View {struct ChoiceValueRow: View {let row: SettingRowlet valueLabel: String+ var hint = ShellStrings.text("Opens the list of choices")let open: () -> Voidvar body: some View {Button(action: open) {@@ -186,6 +186,6 @@ struct ChoiceValueRow: View {.buttonStyle(.plain).accessibilityLabel(row.label).accessibilityValue(valueLabel)- .accessibilityHint(ShellStrings.text("Opens the list of choices"))+ .accessibilityHint(hint)}}diff --git a/frontend-ios/Sources/ShellUI/ControllersView.swift b/frontend-ios/Sources/ShellUI/ControllersView.swiftindex 6b784cb8..091fb2d9 100644--- a/frontend-ios/Sources/ShellUI/ControllersView.swift+++ b/frontend-ios/Sources/ShellUI/ControllersView.swift@@ -2,19 +2,15 @@ import SwiftUI/// Connected controllers with their player and battery, and the buttons the shell listens to.public struct ControllersView: View {- static let mappingID = "global-pad"+ /// The ID the shell's own button mapping goes by where a game's ID would.+ public static let mappingID = "global-pad"public var padMap: PadMap- public var onChange: (String, String) -> Void- public var onReset: () -> Void@Environment(\.shellFocus) private var focus@Environment(\.accessibilityReduceMotion) private var reduceMotionpublic var controllers: [ControllerInfo]public var onBack: () -> Void- public init(controllers: [ControllerInfo], onBack: @escaping () -> Void = {}, padMap: PadMap = PadMap(),- onChange: @escaping (String, String) -> Void = { _, _ in }, onReset: @escaping () -> Void = {}) {+ public init(controllers: [ControllerInfo], onBack: @escaping () -> Void = {}, padMap: PadMap = PadMap()) {self.padMap = padMap- self.onChange = onChange- self.onReset = onResetself.controllers = controllersself.onBack = onBack}@@ -69,7 +65,7 @@ public struct ControllersView: View {.scrollIndicators(.hidden).ignoresSafeArea(edges: .bottom).onChange(of: focus.id) { _, id in- guard let id, id.hasPrefix("ctl."), !id.hasPrefix("ctl.pick.") else { return }+ guard let id, id.hasPrefix("ctl.") else { return }withAnimation(reduceMotion ? nil : .easeOut(duration: 0.15)) {proxy.scrollTo(id, anchor: id == "ctl.close" ? .top : .center)}@@ -78,22 +74,12 @@ public struct ControllersView: View {}.foregroundStyle(.white).preferredColorScheme(.dark)}+ /// The mapping and the test, each a compact row that opens a card of its own.private var mapping: some View {VStack(alignment: .leading, spacing: 14) {SectionHeading(title: ShellStrings.text("Button mapping"))- let swap = SettingRow(id: "swapAB", label: ShellStrings.text("Swap A and B"),- note: ShellStrings.text("Only affects physical controllers in games, not shell menus. Each game can override these settings."),- kind: .toggle(on: "1", off: "0"), value: padMap.swapAB ? "1" : "0")- SettingControl(gameID: Self.mappingID, row: swap, targetPrefix: "ctl.row.") { onChange("swapAB", $0) }- .accessibilityIdentifier("ctl.swapAB").id("ctl.row.swapAB")- ForEach(PadMap.buttons, id: \.self) { button in- let row = SettingRow(id: button, label: PadMap.label(button), kind: .choice(PadMap.options), value: padMap.output(for: button))- SettingControl(gameID: Self.mappingID, row: row, targetPrefix: "ctl.row.") { onChange(button, $0) }- .accessibilityIdentifier("ctl.\(button)").id("ctl.row.\(button)")- }- Button(action: onReset) { Text(ShellStrings.text("Reset to default")) }- .buttonStyle(ChipButtonStyle()).accessibilityIdentifier("ctl.reset")- .shellTarget("ctl.reset", action: onReset).id("ctl.reset")+ PadMappingEntryRow(gameID: Self.mappingID, rows: PadMappingRows.global(padMap), targetID: "ctl.mapping").id("ctl.mapping")+ ButtonTestEntryRow().id("ctl.test")}}@@ -105,6 +91,18 @@ public struct ControllersView: View {}}+/// The row that opens the button test.+private struct ButtonTestEntryRow: View {+ @Environment(\.shellOpenButtonTest) private var openTest+ var body: some View {+ let row = SettingRow(id: "buttonTest", label: ShellStrings.text("Button test"),+ note: ShellStrings.text("See each button light up as you press it."), kind: .choice([]), value: "")+ ChoiceValueRow(row: row, valueLabel: "", hint: ShellStrings.text("Opens the button test")) { openTest?() }+ .shellTarget("ctl.test", radius: 11) { openTest?() }+ .accessibilityIdentifier("buttonTest.open")+ }+}+private struct ControllerRow: View {let controller: ControllerInfo@Environment(\.dynamicTypeSize) private var typeSizediff --git a/frontend-ios/Sources/ShellUI/GameDetailView.swift b/frontend-ios/Sources/ShellUI/GameDetailView.swiftindex b869d6c5..e40da0a0 100644--- a/frontend-ios/Sources/ShellUI/GameDetailView.swift+++ b/frontend-ios/Sources/ShellUI/GameDetailView.swift@@ -20,10 +20,15 @@ public struct GameDetailView: View {if showsHeader || showsPrimaryAction { header }ForEach(detail.sections) { section ingroup(section.title) {- ForEach(section.rows) { row in- // Equatable on its row: a change re-renders the changed row only, not every row of the game.- SettingControl(gameID: detail.id, row: row) { actions.onChange(detail.id, row.id, $0) }.equatable()- if row.id != section.rows.last?.id { divider }+ // The button mapping is one row here and opens a card of its own, as a long choice list does.+ if section.id == PadMappingRows.sectionID {+ PadMappingEntryRow(gameID: detail.id, rows: section.rows, targetID: "set.row.padMapping")+ } else {+ ForEach(section.rows) { row in+ // Equatable on its row: a change re-renders the changed row only, not every row of the game.+ SettingControl(gameID: detail.id, row: row) { actions.onChange(detail.id, row.id, $0) }.equatable()+ if row.id != section.rows.last?.id { divider }+ }}}}diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex 48bacdd7..7b1cc926 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -32,6 +32,8 @@ public struct LibraryView: View {public let games: [GameDetail]public let controllers: [ControllerInfo]public let globalPadMap: PadMap+ /// The controller's state while the button test is open, from the host.+ public let padSnapshot: PadSnapshot?public var actions: ShellActionspublic var input: ShellInput?@State private var selectedID: String?@@ -42,6 +44,9 @@ public struct LibraryView: View {@State private var helpGameID: String?/// The choice whose option list is open.@State private var choice: ChoiceRequest?+ /// The button-mapping card, while open.+ @State private var padMapping: PadMappingState?+ @State private var buttonTestOpen: Bool@State private var focus: FocusAppearance@State private var targets = FocusTargetBuffer()@State private var settingsPosition = ScrollPosition()@@ -62,10 +67,14 @@ public struct LibraryView: View {public init(games: [GameDetail], controllers: [ControllerInfo] = [], actions: ShellActions = ShellActions(),input: ShellInput? = nil, initialSelection: String? = nil, initialDetailOpen: Bool = false,initialControllersOpen: Bool = false, initialShellSettingsOpen: Bool = false, initialFocusVisible: Bool = false,- globalPadMap: PadMap = PadMap()) {+ globalPadMap: PadMap = PadMap(), padSnapshot: PadSnapshot? = nil,+ initialPadMapping: String? = nil, initialButtonTestOpen: Bool = false) {self.games = gamesself.controllers = controllersself.globalPadMap = globalPadMap+ self.padSnapshot = padSnapshot+ _padMapping = State(initialValue: initialPadMapping.map { PadMappingState(gameID: $0) })+ _buttonTestOpen = State(initialValue: initialButtonTestOpen)self.actions = actionsself.input = inputlet first = initialSelection ?? games.first?.id@@ -131,7 +140,7 @@ public struct LibraryView: View {.opacity(settingsOpen ? 1 : 0).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing).allowsHitTesting(settingsOpen)- .accessibilityHidden(!settingsOpen || choice != nil)+ .accessibilityHidden(!settingsOpen || choice != nil || padMapping != nil).accessibilityAddTraits(settingsOpen ? .isModal : []).transformPreference(FocusTargets.self) { if !settingsOpen { $0.removeAll() } }}@@ -152,9 +161,8 @@ public struct LibraryView: View {if controllersOpen {Color.black.opacity(0.55 * (1 - min(1, edgeDrag / min(width, 520)))).ignoresSafeArea().accessibilityHidden(true).onTapGesture { back() }- ControllersView(controllers: controllers, onBack: back, padMap: globalPadMap,- onChange: actions.onGlobalPadMapChange, onReset: actions.onGlobalPadMapReset)- .accessibilityHidden(choice != nil)+ ControllersView(controllers: controllers, onBack: back, padMap: globalPadMap)+ .accessibilityHidden(choice != nil || padMapping != nil || buttonTestOpen).frame(width: min(width, 520)).frame(maxHeight: .infinity).background { ShellPalette.background.ignoresSafeArea() }@@ -186,19 +194,42 @@ public struct LibraryView: View {.frame(maxWidth: .infinity, maxHeight: .infinity).transition(.opacity.combined(with: .scale(scale: 0.96)))}+ if let padMapping {+ Color.black.opacity(0.55).ignoresSafeArea().accessibilityHidden(true)+ .onTapGesture { closePadMapping() }+ .transition(.opacity)+ PadMappingCard(title: padMappingTitle(padMapping.gameID), rows: padMappingRows(padMapping.gameID), openRow: padMapping.row,+ open: openPadRow, pick: pickPadValue, backToList: closePadRow, reset: resetPadMapping, close: closePadMapping)+ .padding(.horizontal, 16).padding(.vertical, 12)+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .transition(.opacity.combined(with: .scale(scale: 0.96)))+ }+ if buttonTestOpen {+ Color.black.opacity(0.7).ignoresSafeArea().accessibilityHidden(true)+ .onTapGesture { closeButtonTest() }+ .transition(.opacity)+ ButtonTestView(snapshot: padSnapshot, close: closeButtonTest)+ .padding(.horizontal, 16).padding(.vertical, 12)+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .transition(.opacity.combined(with: .scale(scale: 0.96)))+ }}.transformPreference(FocusTargets.self) { values invalues = values.filter { target in- if let choice { return target.id.hasPrefix(choice.gameID == ControllersView.mappingID ? "ctl.pick." : "pick.") }+ if buttonTestOpen { return target.id.hasPrefix("test.") }+ if padMapping != nil { return target.id.hasPrefix("map.") }+ if choice != nil { return target.id.hasPrefix("pick.") }if controllersOpen { return target.id.hasPrefix("ctl.") }if shellSettingsOpen { return target.id.hasPrefix("shs.") }if helpGameID != nil { return target.id.hasPrefix("help.") }return !target.id.hasPrefix("ctl.") && !target.id.hasPrefix("help.") && !target.id.hasPrefix("pick.") && !target.id.hasPrefix("shs.")+ && !target.id.hasPrefix("map.") && !target.id.hasPrefix("test.")}}.coordinateSpace(name: "shell").background {- EdgeSwipeBack(enabled: (settingsOpen || controllersOpen || shellSettingsOpen) && choice == nil && helpGameID == nil,+ EdgeSwipeBack(enabled: (settingsOpen || controllersOpen || shellSettingsOpen) && choice == nil && helpGameID == nil+ && padMapping == nil && !buttonTestOpen,changed: { edgeDrag = $0 },ended: { finishEdgeSwipe(travel: $0, velocity: $1, span: controllersOpen || shellSettingsOpen ? min(width, 520) : pane) },cancelled: cancelEdgeSwipe)@@ -213,7 +244,11 @@ public struct LibraryView: View {.animation(reduceMotion ? nil : .smooth(duration: 0.3), value: shellSettingsOpen).animation(reduceMotion ? nil : .smooth(duration: 0.25), value: helpGameID).animation(reduceMotion ? nil : .smooth(duration: 0.25), value: choice)+ .animation(reduceMotion ? nil : .smooth(duration: 0.25), value: padMapping)+ .animation(reduceMotion ? nil : .smooth(duration: 0.25), value: buttonTestOpen).environment(\.shellPickChoice, { request in openChoice(request) })+ .environment(\.shellOpenPadMapping, { id in openPadMapping(id) })+ .environment(\.shellOpenButtonTest, { openButtonTest() }).environment(\.shellShowHelp, { game in openHelp(game.id) }).environment(\.shellFocus, focus).environment(\.shellInputDevice, device)@@ -362,25 +397,72 @@ public struct LibraryView: View {noteTouch()returnFocus = focus.idchoice = request- focus.id = (request.gameID == ControllersView.mappingID ? "ctl.pick." : "pick.") + request.row.value+ focus.id = "pick." + request.row.value}private func closeChoice() {guard let request = choice else { return }choice = nil- focus.id = (request.gameID == ControllersView.mappingID ? "ctl.row." : request.gameID == ShellSettingsRows.gameID ? ShellSettingsRows.targetPrefix : "set.row.") + request.row.id+ focus.id = (request.gameID == ShellSettingsRows.gameID ? ShellSettingsRows.targetPrefix : "set.row.") + request.row.id}private func pickChoice(_ value: String) {noteTouch()guard let request = choice else { return }if value != request.row.value {- if request.gameID == ControllersView.mappingID { actions.onGlobalPadMapChange(request.row.id, value) }- else if request.gameID == ShellSettingsRows.gameID { ShellSettingsRows.apply(request.row.id, value: value, to: .current) }+ if request.gameID == ShellSettingsRows.gameID { ShellSettingsRows.apply(request.row.id, value: value, to: .current) }else { actions.onChange(request.gameID, request.row.id, value) }}closeChoice()}+ // The mapping card: the shell's map or a game's, a row's options in place of the rows once one is picked.+ private func padMappingRows(_ id: String) -> [SettingRow] {+ if id == ControllersView.mappingID { return PadMappingRows.global(globalPadMap) }+ return games.first { $0.id == id }.map(PadMappingRows.game) ?? []+ }+ private func padMappingTitle(_ id: String) -> String {+ if id == ControllersView.mappingID { return ShellStrings.text("For every game") }+ return games.first { $0.id == id }?.game.title ?? ""+ }+ private func openPadMapping(_ id: String) {+ noteTouch()+ returnFocus = focus.id+ padMapping = PadMappingState(gameID: id)+ focus.id = "map.row." + (padMappingRows(id).first?.id ?? "")+ }+ private func closePadMapping() { padMapping = nil; focus.id = returnFocus }+ private func openPadRow(_ row: String) {+ noteTouch()+ padMapping?.row = row+ focus.id = "map.opt." + (padMappingRows(padMapping?.gameID ?? "").first { $0.id == row }?.value ?? "")+ }+ private func closePadRow() {+ guard let row = padMapping?.row else { return }+ padMapping?.row = nil+ focus.id = "map.row." + row+ }+ private func pickPadValue(_ row: String, _ value: String) {+ noteTouch()+ guard let id = padMapping?.gameID else { return }+ if id == ControllersView.mappingID { actions.onGlobalPadMapChange(row, value) } else { actions.onChange(id, row, value) }+ closePadRow()+ }+ private func resetPadMapping() {+ noteTouch()+ guard let id = padMapping?.gameID else { return }+ if id == ControllersView.mappingID { actions.onGlobalPadMapReset() } else { actions.onChange(id, PadMappingRows.resetID, "") }+ focus.id = "map.row." + (padMappingRows(id).first?.id ?? "")+ }+ private func openButtonTest() { noteTouch(); buttonTestOpen = true; focus.id = "test.close"; actions.onButtonTest(true) }+ private func closeButtonTest() {+ guard buttonTestOpen else { return }+ buttonTestOpen = false+ actions.onButtonTest(false)+ focus.id = "ctl.test"+ }private func back() {- if choice != nil { closeChoice() }+ if buttonTestOpen { closeButtonTest() }+ else if padMapping?.row != nil { closePadRow() }+ else if padMapping != nil { closePadMapping() }+ else if choice != nil { closeChoice() }else if helpGameID != nil { closeHelp() }else if controllersOpen { controllersOpen = false; focus.id = "lib.controllers" }else if shellSettingsOpen { closeShellSettings() }@@ -390,6 +472,8 @@ public struct LibraryView: View {private func handle(_ action: ShellInput.Action, from source: InputDevice) {gate.handling = truedefer { gate.handling = false }+ // Every controller button belongs to the button test while it is open: it closes on B held, touch or Escape.+ if buttonTestOpen, case .controller = source { return }if device != source { device = source }if touchMode { touchMode = false }focus.visible = true@@ -422,7 +506,9 @@ public struct LibraryView: View {if let id = focus.id, id.hasPrefix("lib.tile.") { select(String(id.dropFirst("lib.tile.".count))) }}private var defaultFocus: String? {- if let choice { return (choice.gameID == ControllersView.mappingID ? "ctl.pick." : "pick.") + choice.row.value }+ if buttonTestOpen { return "test.close" }+ if let padMapping { return padMapping.row == nil ? "map.close" : "map.back" }+ if let choice { return "pick." + choice.row.value }if helpGameID != nil { return "help.done" }if controllersOpen { return "ctl.close" }if shellSettingsOpen { return "shs.close" }diff --git a/frontend-ios/Sources/ShellUI/PadMappingView.swift b/frontend-ios/Sources/ShellUI/PadMappingView.swiftnew file mode 100644index 00000000..a4772436--- /dev/null+++ b/frontend-ios/Sources/ShellUI/PadMappingView.swift@@ -0,0 +1,242 @@+import SwiftUI++/// The open button-mapping card: whose map it is (`ControllersView.mappingID` for the shell's, else a game's ID) and the+/// row whose options are showing, nil for the list of rows.+struct PadMappingState: Equatable {+ let gameID: String+ var row: String?+}++private struct ShellOpenPadMappingKey: EnvironmentKey {+ nonisolated(unsafe) static let defaultValue: ((String) -> Void)? = nil+}+private struct ShellOpenButtonTestKey: EnvironmentKey {+ nonisolated(unsafe) static let defaultValue: (() -> Void)? = nil+}+extension EnvironmentValues {+ /// Opens the button-mapping card for the shell (`ControllersView.mappingID`) or a game. The library provides it.+ var shellOpenPadMapping: ((String) -> Void)? {+ get { self[ShellOpenPadMappingKey.self] }+ set { self[ShellOpenPadMappingKey.self] = newValue }+ }+ /// Opens the button test. The library provides it.+ var shellOpenButtonTest: (() -> Void)? {+ get { self[ShellOpenButtonTestKey.self] }+ set { self[ShellOpenButtonTestKey.self] = newValue }+ }+}++/// The rows of a mapping, shared by the card and the compact row that opens it. A row's `fromShell` means it does what it+/// would do anyway: the default for the shell's map, the shell's choice for a game's.+public enum PadMappingRows {+ /// The shell's map as rows: Swap A and B, then the 16 buttons.+ static func global(_ map: PadMap) -> [SettingRow] {+ let swap = SettingRow(id: "swapAB", label: ShellStrings.text("Swap A and B"),+ note: ShellStrings.text("Only affects physical controllers in games, not shell menus. Each game can override these settings."),+ kind: .choice([SettingOption("0", ShellStrings.text("Off")), SettingOption("1", ShellStrings.text("On"))]),+ value: map.swapAB ? "1" : "0", fromShell: !map.swapAB)+ return [swap] + PadMap.buttons.map { button in+ SettingRow(id: button, label: PadMap.label(button), kind: .choice(PadMap.options), value: map.output(for: button),+ fromShell: map.output(for: button) == button)+ }+ }+ /// A game's rows, as the host puts them in its "pad" section.+ static func game(_ detail: GameDetail) -> [SettingRow] {+ detail.sections.first { $0.id == sectionID }?.rows ?? []+ }+ static let sectionID = "pad"+ /// The setting a game's card sends to forget the game's own mapping.+ public static let resetID = "pad.reset"+ static func valueLabel(_ row: SettingRow) -> String {+ if case .choice(let options) = row.kind { return options.first { $0.id == row.value }?.label ?? row.value }+ return row.value+ }+ /// The compact row's value: nothing changed, or how much.+ static func summary(_ rows: [SettingRow], game: Bool) -> String {+ let changed = Set(rows.filter { !$0.fromShell }.map(\.id))+ guard let swap = rows.first, !changed.isEmpty else { return ShellStrings.text(game ? "Follow global" : "Default") }+ // Swapping A and B changes the rows of A and B too: only those three changed reads as the swap's own value.+ if changed.contains(swap.id) && changed.isSubset(of: Set(rows.prefix(3).map(\.id))) { return swap.label + ": " + valueLabel(swap) }+ return ShellStrings.text("Custom")+ }+}++/// The compact row that opens the mapping card, in the Controllers page and in a game's settings.+struct PadMappingEntryRow: View {+ let gameID: String+ let rows: [SettingRow]+ var targetID: String+ @Environment(\.shellOpenPadMapping) private var openMapping+ var body: some View {+ let isGame = gameID != ControllersView.mappingID+ let row = SettingRow(id: "padMapping", label: ShellStrings.text("Button mapping"),+ note: ShellStrings.text(isGame ? "Overrides the global mapping for this game only." : "What each button of a physical controller sends in games."),+ kind: .choice([]), value: "")+ ChoiceValueRow(row: row, valueLabel: PadMappingRows.summary(rows, game: isGame), hint: ShellStrings.text("Opens the button mapping")) {+ openMapping?(gameID)+ }+ .shellTarget(targetID, radius: 11) { openMapping?(gameID) }+ .accessibilityIdentifier("padMapping.open")+ }+}++/// The button mapping in a card of its own, as a long choice list is: the rows with their current values, and a row's+/// options in place of the rows once it is picked. D-pad and keys move through `map.` targets, A picks, B goes back to+/// the rows and then closes.+struct PadMappingCard: View {+ let title: String+ let rows: [SettingRow]+ let openRow: String?+ let open: (String) -> Void+ let pick: (String, String) -> Void+ let backToList: () -> Void+ let reset: () -> Void+ let close: () -> Void+ @Environment(\.accessibilityReduceMotion) private var reduceMotion+ @Environment(\.shellFocus) private var focus++ private var shown: SettingRow? { openRow.flatMap { id in rows.first { $0.id == id } } }++ var body: some View {+ ViewThatFits(in: .vertical) {+ content(scrolls: false)+ content(scrolls: true)+ }+ .frame(maxWidth: 460)+ .background(Color(red: 0.075, green: 0.075, blue: 0.082), in: RoundedRectangle(cornerRadius: 26))+ .overlay(RoundedRectangle(cornerRadius: 26).strokeBorder(.white.opacity(0.10)))+ .shadow(color: .black.opacity(0.5), radius: 40)+ .accessibilityElement(children: .contain)+ .accessibilityAddTraits(.isModal)+ .accessibilityIdentifier("padMapping.card")+ }++ private func content(scrolls: Bool) -> some View {+ VStack(alignment: .leading, spacing: 0) {+ header+ Rectangle().fill(ShellPalette.hairline).frame(height: 1)+ if scrolls {+ ScrollViewReader { proxy in+ ScrollView { body(of: shown) }+ .scrollIndicators(.hidden)+ .onAppear { if let id = focus.id { proxy.scrollTo(id, anchor: .center) } }+ .onChange(of: focus.id) { _, id in+ guard let id, id.hasPrefix("map.") else { return }+ withAnimation(reduceMotion ? nil : .easeOut(duration: 0.15)) {+ proxy.scrollTo(id, anchor: id == "map.close" || id == "map.back" ? .top : .center)+ }+ }+ }+ } else {+ body(of: shown)+ }+ }+ }++ private var header: some View {+ HStack(alignment: .center, spacing: 12) {+ if shown != nil {+ Button(action: backToList) {+ Image(systemName: "chevron.left").font(.system(size: 14, weight: .semibold)).frame(width: 44, height: 44)+ .background(.white.opacity(0.08), in: Circle()).contentShape(Circle())+ }+ .buttonStyle(.plain)+ .accessibilityLabel(ShellStrings.text("Button mapping"))+ .accessibilityIdentifier("padMapping.back")+ .shellTarget("map.back", radius: 22, action: backToList)+ }+ VStack(alignment: .leading, spacing: 2) {+ Text(shown?.label ?? ShellStrings.text("Button mapping")).shellType(ShellType.flowTitle(20)).lineLimit(2)+ .accessibilityAddTraits(.isHeader).accessibilityIdentifier("padMapping.title")+ Text(shown == nil ? title : ShellStrings.text("Sends in games")).shellType(ShellType.note)+ .foregroundStyle(.white.opacity(0.5)).lineLimit(2)+ }+ Spacer(minLength: 8)+ Button(action: close) {+ Image(systemName: "xmark").font(.system(size: 14, weight: .semibold)).frame(width: 44, height: 44)+ .background(.white.opacity(0.08), in: Circle()).contentShape(Circle())+ }+ .buttonStyle(.plain)+ .accessibilityLabel(ShellStrings.text("Close"))+ .accessibilityIdentifier("padMapping.close")+ .shellTarget("map.close", radius: 22, action: close)+ }+ .padding(.horizontal, 20).padding(.top, 14).padding(.bottom, 8)+ }++ @ViewBuilder private func body(of row: SettingRow?) -> some View {+ if let row { options(row) } else { list }+ }++ private var list: some View {+ VStack(alignment: .leading, spacing: 4) {+ ForEach(rows) { row in+ rowButton(row)+ if row.id == rows.first?.id {+ if !row.note.isEmpty {+ Text(row.note).shellType(ShellType.note).foregroundStyle(.white.opacity(0.45))+ .fixedSize(horizontal: false, vertical: true).padding(.horizontal, 14).padding(.bottom, 8)+ }+ Text(ShellStrings.text("Buttons").uppercased()).shellText(10.5, .bold, relativeTo: .caption2).tracking(1.4)+ .foregroundStyle(.white.opacity(0.45)).padding(.horizontal, 14).padding(.top, 6).padding(.bottom, 2)+ .accessibilityAddTraits(.isHeader)+ }+ }+ Button(action: reset) { Text(ShellStrings.text("Reset to default")) }+ .buttonStyle(ChipButtonStyle())+ .disabled(rows.allSatisfy(\.fromShell))+ .accessibilityIdentifier("padMapping.reset")+ .shellTarget("map.reset", enabled: !rows.allSatisfy(\.fromShell), action: reset)+ .padding(.horizontal, 6).padding(.top, 10)+ }+ .padding(10)+ }++ private func rowButton(_ row: SettingRow) -> some View {+ let changed = !row.fromShell+ return Button { open(row.id) } label: {+ HStack(spacing: 12) {+ Text(row.label).shellText(15, .medium).fixedSize(horizontal: false, vertical: true)+ Spacer(minLength: 8)+ Text(PadMappingRows.valueLabel(row)).shellText(14.5, changed ? .bold : .medium)+ .foregroundStyle(changed ? ShellPalette.cream : .white.opacity(0.5)).multilineTextAlignment(.trailing)+ Image(systemName: "chevron.right").font(.system(size: 13, weight: .bold)).foregroundStyle(.white.opacity(0.4))+ .accessibilityHidden(true)+ }+ .padding(.horizontal, 14).padding(.vertical, 8).frame(minHeight: 44)+ .background(.white.opacity(changed ? 0.07 : 0.0), in: RoundedRectangle(cornerRadius: 10))+ .contentShape(RoundedRectangle(cornerRadius: 10))+ }+ .buttonStyle(.plain)+ .accessibilityLabel(row.label)+ .accessibilityValue(PadMappingRows.valueLabel(row))+ .accessibilityIdentifier("padMapping.row.\(row.id)")+ .shellTarget("map.row.\(row.id)", radius: 10) { open(row.id) }+ }++ private func options(_ row: SettingRow) -> some View {+ let options: [SettingOption] = if case .choice(let o) = row.kind { o } else { [] }+ return VStack(spacing: 4) {+ ForEach(options) { option in+ let chosen = row.value == option.id+ Button { pick(row.id, option.id) } label: {+ HStack(spacing: 12) {+ Text(option.label).shellText(15, chosen ? .bold : .medium).fixedSize(horizontal: false, vertical: true)+ Spacer(minLength: 8)+ if chosen { Image(systemName: "checkmark").font(.system(size: 14, weight: .bold)).accessibilityHidden(true) }+ }+ .padding(.horizontal, 14).padding(.vertical, 8).frame(minHeight: 44)+ .foregroundStyle(chosen ? ShellPalette.cream : .white.opacity(0.8))+ .background(.white.opacity(chosen ? 0.09 : 0.0), in: RoundedRectangle(cornerRadius: 10))+ .contentShape(RoundedRectangle(cornerRadius: 10))+ }+ .buttonStyle(.plain)+ .accessibilityLabel(option.label)+ .accessibilityAddTraits(chosen ? .isSelected : [])+ .accessibilityIdentifier("padMapping.option.\(option.id)")+ .shellTarget("map.opt.\(option.id)", radius: 10) { pick(row.id, option.id) }+ }+ }+ .padding(10)+ }+}diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstringsindex f426cde9..9c2b2c21 100644--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings@@ -1248,6 +1248,262 @@}}}+ },+ "Follow global": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Follow global"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "跟随全局"+ }+ }+ }+ },+ "Default": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Default"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "默认"+ }+ }+ }+ },+ "Custom": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Custom"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "自定义"+ }+ }+ }+ },+ "Overrides the global mapping for this game only.": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Overrides the global mapping for this game only."+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "仅为这个游戏覆盖全局映射。"+ }+ }+ }+ },+ "What each button of a physical controller sends in games.": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "What each button of a physical controller sends in games."+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "设置实体手柄的每个按键在游戏中对应哪个键。"+ }+ }+ }+ },+ "Opens the button mapping": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Opens the button mapping"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "打开按键映射"+ }+ }+ }+ },+ "Sends in games": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Sends in games"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "在游戏中对应"+ }+ }+ }+ },+ "Buttons": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Buttons"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "按键"+ }+ }+ }+ },+ "Button test": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Button test"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "按键测试"+ }+ }+ }+ },+ "See each button light up as you press it.": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "See each button light up as you press it."+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "按下按键时,对应的位置会亮起。"+ }+ }+ }+ },+ "Opens the button test": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Opens the button test"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "打开按键测试"+ }+ }+ }+ },+ "Controller": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Controller"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "手柄"+ }+ }+ }+ },+ "Press any button on a controller": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Press any button on a controller"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "按下手柄上的任意按键"+ }+ }+ }+ },+ "No button held": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "No button held"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "没有按下按键"+ }+ }+ }+ },+ "Hold B to close": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Hold B to close"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "按住 B 关闭"+ }+ }+ }+ },+ "For every game": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "For every game"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "适用于所有游戏"+ }+ }+ }}},"version": "1.0"diff --git a/frontend-ios/Sources/ShellUI/ShellInputs.swift b/frontend-ios/Sources/ShellUI/ShellInputs.swiftindex b5782fc7..d99bcea3 100644--- a/frontend-ios/Sources/ShellUI/ShellInputs.swift+++ b/frontend-ios/Sources/ShellUI/ShellInputs.swift@@ -1,4 +1,5 @@import Foundation+import CoreGraphics/// The caller supplies display data. These types never load, validate, or store game data.public enum GameState: Equatable, Sendable {@@ -156,6 +157,31 @@ public struct ShellInput: Equatable, Sendable {}}+/// A controller element the button test lights up, named by its place on an Xbox controller (GameController's names).+public enum PadElement: String, CaseIterable, Sendable {+ case a, b, x, y, leftBumper, rightBumper, leftTrigger, rightTrigger, leftStick, rightStick, view, menu, home, up, down, left, right+}++/// A controller's whole state for the button test: what is held, the sticks from -1 to 1 (up is positive) and the+/// triggers from 0 to 1. The host sends it only while the test is open.+public struct PadSnapshot: Equatable, Sendable {+ public var name: String+ public var pressed: Set<PadElement>+ public var leftStick: CGPoint+ public var rightStick: CGPoint+ public var leftTrigger: Double+ public var rightTrigger: Double+ public init(name: String = "", pressed: Set<PadElement> = [], leftStick: CGPoint = .zero, rightStick: CGPoint = .zero,+ leftTrigger: Double = 0, rightTrigger: Double = 0) {+ self.name = name+ self.pressed = pressed+ self.leftStick = leftStick+ self.rightStick = rightStick+ self.leftTrigger = leftTrigger+ self.rightTrigger = rightTrigger+ }+}+/// All effects leave the package through these closures. The game ID is always explicit.public struct ShellActions {public var onSelect: (String) -> Void@@ -176,6 +202,8 @@ public struct ShellActions {public var onClearShellCloud: () -> Voidpublic var onGlobalPadMapChange: (String, String) -> Voidpublic var onGlobalPadMapReset: () -> Void+ /// The button test opened (true) or closed: the host sends `PadSnapshot`s only in between.+ public var onButtonTest: (Bool) -> Voidpublic init(onSelect: @escaping (String) -> Void = { _ in }, onPlay: @escaping (String) -> Void = { _ in },onChange: @escaping (String, String, String) -> Void = { _, _, _ in },onPickGameData: @escaping (String) -> Void = { _ in }, onUseAppData: @escaping (String) -> Void = { _ in },@@ -186,7 +214,7 @@ public struct ShellActions {onUseShellCloud: @escaping (String) -> Void = { _ in }, onClearShellData: @escaping () -> Void = {},onClearShellCloud: @escaping () -> Void = {},onGlobalPadMapChange: @escaping (String, String) -> Void = { _, _ in },- onGlobalPadMapReset: @escaping () -> Void = {}) {+ onGlobalPadMapReset: @escaping () -> Void = {}, onButtonTest: @escaping (Bool) -> Void = { _ in }) {self.onSelect = onSelectself.onPlay = onPlayself.onChange = onChange@@ -205,5 +233,6 @@ public struct ShellActions {self.onClearShellCloud = onClearShellCloudself.onGlobalPadMapChange = onGlobalPadMapChangeself.onGlobalPadMapReset = onGlobalPadMapReset+ self.onButtonTest = onButtonTest}}diff --git a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swiftindex 9ff88f9a..3280b4a4 100644--- a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift@@ -95,6 +95,9 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { date#expect(store.entries.isEmpty)model.change(Fixtures.orbit, setting: "pad.swapAB", value: "on")#expect(store.swapValue == "on")+ // The mapping card's reset forgets the game's mapping only, not its other settings.+ model.change(Fixtures.orbit, setting: PadMappingRows.resetID, value: "")+ #expect(store.entries.isEmpty && store.swapValue == "follow")}@Test func profilePadMapRowWinsShellMapping() throws {diff --git a/frontend-ios/Tests/ShellUITests/PadMapTests.swift b/frontend-ios/Tests/ShellUITests/PadMapTests.swiftindex bc3091d9..c7721a69 100644--- a/frontend-ios/Tests/ShellUITests/PadMapTests.swift+++ b/frontend-ios/Tests/ShellUITests/PadMapTests.swift@@ -30,4 +30,26 @@ import Testingmap.setSwapAB(false)#expect(map.envValue == "X=none")}+ @Test func globalRowsMarkWhatDiffersFromTheDefault() {+ var map = PadMap()+ let untouched = PadMappingRows.global(map).allSatisfy { $0.fromShell }+ #expect(untouched)+ #expect(PadMappingRows.summary(PadMappingRows.global(map), game: false) == "Default")+ map.setSwapAB(true)+ let rows = PadMappingRows.global(map)+ let ids = Array(rows.map { $0.id }.prefix(3)), changed = rows.filter { !$0.fromShell }.map { $0.id }+ #expect(ids == ["swapAB", "A", "B"])+ #expect(changed == ["swapAB", "A", "B"])+ #expect(PadMappingRows.summary(rows, game: false) == "Swap A and B: On")+ map.set("X", to: "none")+ #expect(PadMappingRows.summary(PadMappingRows.global(map), game: false) == "Custom")+ }+ @Test func aGameWithoutItsOwnMappingFollowsGlobal() {+ let rows = [SettingRow(id: "pad.swapAB", label: "Swap A and B", kind: .choice([]), value: "follow", fromShell: true),+ SettingRow(id: "pad.A", label: "A", kind: .choice([]), value: "follow", fromShell: true)]+ #expect(PadMappingRows.summary(rows, game: true) == "Follow global")+ var custom = rows+ custom[1].fromShell = false+ #expect(PadMappingRows.summary(custom, game: true) == "Custom")+ }}diff --git a/frontend-ios/UITests/ShellCaptureTests.swift b/frontend-ios/UITests/ShellCaptureTests.swiftindex f3d6bb6d..f1a8fa80 100644--- a/frontend-ios/UITests/ShellCaptureTests.swift+++ b/frontend-ios/UITests/ShellCaptureTests.swift@@ -57,21 +57,37 @@ import XCTestshot("shell-settings")}- /// The two mapping entry points, including the real host's per-game rows.+ /// The mapping rows in Controllers and in a game's settings, the card each opens, a button's options and the test.func testCapturePadMapping() {XCUIDevice.shared.orientation = .portrait+ func reveal(_ element: XCUIElement) {+ XCTAssertTrue(element.waitForExistence(timeout: 5))+ for _ in 0..<5 where !element.isHittable { app.scrollViews.element(boundBy: app.scrollViews.count - 1).swipeUp() }+ XCTAssertTrue(element.isHittable)+ }launch(["--screen", "controllers"])- let globalSwap = app.descendants(matching: .any).matching(identifier: "ctl.swapAB").firstMatch- XCTAssertTrue(globalSwap.waitForExistence(timeout: 5))- for _ in 0..<3 where !globalSwap.isHittable { app.scrollViews.element(boundBy: app.scrollViews.count - 1).swipeUp() }- XCTAssertTrue(globalSwap.isHittable)+ let open = app.descendants(matching: .any).matching(identifier: "padMapping.open").firstMatch+ reveal(open)shot("controllers-button-mapping")+ open.tap()+ XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "padMapping.card").firstMatch.waitForExistence(timeout: 5))+ sleep(1)+ shot("controllers-button-mapping-card")+ app.buttons["padMapping.row.A"].tap()+ XCTAssertTrue(app.buttons["padMapping.option.B"].waitForExistence(timeout: 5))+ sleep(1)+ shot("controllers-button-mapping-options")+ launch(["--screen", "controllers-test"])+ XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "buttonTest").firstMatch.waitForExistence(timeout: 5))+ shot("controllers-button-test")launch(["--host", "--screen", "settings", "--select", "0100000000010000"])- let gameSwap = app.descendants(matching: .any).matching(identifier: "setting.pad.swapAB").firstMatch- XCTAssertTrue(gameSwap.waitForExistence(timeout: 5))- for _ in 0..<5 where !gameSwap.isHittable { app.scrollViews.element(boundBy: app.scrollViews.count - 1).swipeUp() }- XCTAssertTrue(gameSwap.isHittable)+ let game = app.descendants(matching: .any).matching(identifier: "padMapping.open").firstMatch+ reveal(game)shot("game-controller-mapping")+ game.tap()+ XCTAssertTrue(app.buttons["padMapping.row.pad.swapAB"].waitForExistence(timeout: 5))+ sleep(1)+ shot("game-controller-mapping-card")}func testCaptureMatrix() {