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 shell: the mapping card goes without the controller drawing
Haseenesss984a64508f08
diff --git a/frontend-ios/README.md b/frontend-ios/README.mdindex f434d0f0..e8a97667 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 opens a Button mapping card for all games: on top the button test's controller drawing with the Switch names of its places, where a tap on a button opens its choices, a cream ring marks a changed button and a button held on a connected controller lights up, then Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. 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 all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). 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 all games: Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. 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 all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). The demo uses it, the real shell can too.```swiftLibraryView(diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex 9b764de9..eb5e2ef8 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -217,7 +217,6 @@ public struct LibraryView: View {.transition(.opacity)PadMappingCard(title: padMappingTitle(padMapping.gameID), rows: padMappingRows(padMapping.gameID),inherited: padMapping.gameID == ControllersView.mappingID ? nil : globalPadMap, openRow: padMapping.row,- held: padSnapshot?.pressed ?? [],open: openPadRow, pick: pickPadValue, backToList: closePadRow, reset: resetPadMapping, close: closePadMapping).padding(.horizontal, 16).padding(.vertical, 12).frame(maxWidth: .infinity, maxHeight: .infinity)@@ -457,18 +456,11 @@ public struct LibraryView: View {noteTouch()returnFocus = focus.idpadMapping = PadMappingState(gameID: id)- // A button held on a controller lights its place on the card's drawing, as in the button test.- actions.onButtonTest(true)// The swap's current segment, or the first button while a game's swap is neither on, off nor the shell's.let swap = padMappingRows(id).firstfocus.id = swap?.value == "custom" ? "map.row.pad.A" : "map.swap." + (swap?.value ?? "")}- private func closePadMapping() {- guard padMapping != nil else { return }- padMapping = nil- actions.onButtonTest(false)- focus.id = returnFocus- }+ private func closePadMapping() { padMapping = nil; focus.id = returnFocus }private func openPadRow(_ row: String) {noteTouch()padMapping?.row = rowdiff --git a/frontend-ios/Sources/ShellUI/PadMappingView.swift b/frontend-ios/Sources/ShellUI/PadMappingView.swiftindex 2358c914..68c397f2 100644--- a/frontend-ios/Sources/ShellUI/PadMappingView.swift+++ b/frontend-ios/Sources/ShellUI/PadMappingView.swift@@ -98,8 +98,6 @@ struct PadMappingCard: View {/// The shell's map, which a game's rows follow until they are changed. Nil on the shell's own card.var inherited: PadMap?let openRow: String?- /// The buttons held on a connected controller, lit on the drawing. Empty without one.- var held: Set<PadElement> = []let open: (String) -> Voidlet pick: (String, String) -> Voidlet backToList: () -> Void@@ -215,7 +213,6 @@ struct PadMappingCard: View {Text(ShellStrings.text(isGame ? "For this game only. A button left alone does what it does in all games.": "For controllers in games only. This app’s menus keep A to confirm and B to go back.")).shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).fixedSize(horizontal: false, vertical: true)- drawingif let swapRow { swap(swapRow) }ForEach(PadMap.groups, id: \.title) { group inVStack(alignment: .leading, spacing: 10) {@@ -239,34 +236,6 @@ struct PadMappingCard: View {.padding(.horizontal, 20).padding(.vertical, 18)}- /// The controller as the button test draws it, with the Switch names of its places. A tap on a button opens its choices,- /// as its row does. A cream ring marks a changed button, a button held on a connected controller lights up. The rows- /// below stay the way for a controller and say the same in words.- private var drawing: some View {- func row(_ e: PadElement) -> SettingRow? {- PadMap.button(at: e).flatMap { button in rows.first { PadMappingRows.button(of: $0) == button } }- }- let marked = Set(rows.filter { !$0.fromShell }.compactMap { PadMap.element(of: PadMappingRows.button(of: $0)) })- return VStack(spacing: 10) {- XboxControllerDiagram(snapshot: PadSnapshot(pressed: held), switchNames: true, marked: marked,- tap: { e in if let row = row(e) { open(row.id) } },- value: { e in- guard let row = row(e) else { return "" }- let sends = PadMap.label(PadMappingRows.output(of: row, inherited: inherited))- return row.fromShell ? sends : sends + ", " + ShellStrings.text("Changed")- })- .aspectRatio(XboxControllerDiagram.design.width / XboxControllerDiagram.design.height, contentMode: .fit)- .frame(maxWidth: 420)- .accessibilityElement(children: .contain)- .accessibilityLabel(ShellStrings.text("Controller"))- .accessibilityIdentifier("padMapping.drawing")- Text(ShellStrings.text("Tap a button to change what it sends."))- .shellType(ShellType.note).foregroundStyle(.white.opacity(0.45)).multilineTextAlignment(.center)- .fixedSize(horizontal: false, vertical: true)- }- .frame(maxWidth: .infinity)- }-/// Swap A and B: Off and On, and for a game first the shell's choice. Equal segments, stacked when they do not fit.private func swap(_ row: SettingRow) -> some View {// The shell's choice reads All games in a segment, short enough for three segments on a phone.diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstringsindex ebecb56c..cd80ebce 100644--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings@@ -5105,46 +5105,6 @@}}},- "Tap a button to change what it sends.": {- "localizations": {- "de": {- "stringUnit": {- "state": "translated",- "value": "Tippe auf eine Taste, um zu ändern, was sie auslöst."- }- },- "en": {- "stringUnit": {- "state": "translated",- "value": "Tap a button to change what it sends."- }- },- "fr": {- "stringUnit": {- "state": "translated",- "value": "Touchez un bouton pour changer ce qu’il envoie."- }- },- "it": {- "stringUnit": {- "state": "translated",- "value": "Tocca un tasto per cambiare cosa invia."- }- },- "sv": {- "stringUnit": {- "state": "translated",- "value": "Tryck på en knapp för att ändra vad den skickar."- }- },- "zh-Hans": {- "stringUnit": {- "state": "translated",- "value": "点按某个按键即可更改它对应的键。"- }- }- }- },"The first start waits a few minutes for it, once.": {"localizations": {"de": {diff --git a/frontend-ios/Sources/ShellUI/ShellInputs.swift b/frontend-ios/Sources/ShellUI/ShellInputs.swiftindex 4a91d475..4533d0ef 100644--- a/frontend-ios/Sources/ShellUI/ShellInputs.swift+++ b/frontend-ios/Sources/ShellUI/ShellInputs.swift@@ -214,7 +214,7 @@ public struct ShellActions {public var onClearShellCloud: () -> Voidpublic var onGlobalPadMapChange: (String, String) -> Voidpublic var onGlobalPadMapReset: () -> Void- /// The button test or the mapping card opened (true) or closed: the host sends `PadSnapshot`s only in between.+ /// The button test opened (true) or closed: the host sends `PadSnapshot`s only in between.public var onButtonTest: (Bool) -> Void/// Deletes the game's data on this device and takes it off the list. `saves`: its saves go too.public var onDeleteGame: (_ gameID: String, _ saves: Bool) -> Voiddiff --git a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swiftindex a05b0588..b2c1b5b2 100644--- a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift+++ b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift@@ -56,9 +56,8 @@ final class PadMappingCaptureTests: XCTestCase {}}- private func card(_ title: String, rows: [SettingRow], inherited: PadMap?, open: String? = nil,- held: Set<PadElement> = []) -> some View {- PadMappingCard(title: title, rows: rows, inherited: inherited, openRow: open, held: held, open: { _ in }, pick: { _, _ in },+ private func card(_ title: String, rows: [SettingRow], inherited: PadMap?, open: String? = nil) -> some View {+ PadMappingCard(title: title, rows: rows, inherited: inherited, openRow: open, open: { _ in }, pick: { _, _ in },backToList: {}, reset: {}, close: {}).padding(16).background(Color.black.opacity(0.55))@@ -78,8 +77,6 @@ final class PadMappingCaptureTests: XCTestCase {func testCaptureTheCardOfAGame() throws {try capture("pad-card-game", width: 512, card("Hades II", rows: gameRows, inherited: global))- // A controller's bottom face button held while the card is open: its place (B on a Switch) lights up.- try capture("pad-card-game-held", width: 512, card("Hades II", rows: gameRows, inherited: global, held: [.a]))try capture("pad-card-game-options", width: 512, card("Hades II", rows: gameRows, inherited: global, open: "pad.Y"))// A phone: the card at the width an iPhone gives it.try capture("pad-card-game-phone", width: 393, card("Hades II", rows: gameRows, inherited: global))diff --git a/frontend/l10n/de.json b/frontend/l10n/de.jsonindex 42b02c39..005d8d11 100644--- a/frontend/l10n/de.json+++ b/frontend/l10n/de.json@@ -657,7 +657,6 @@"ios.ui.padSwapAB": "A und B tauschen","ios.ui.padSwapNote": "Legt A auf die untere Taste, wo Xbox- und PlayStation-Controller bestätigen.","ios.ui.padSwapped": "A und B getauscht",- "ios.ui.padTapDrawing": "Tippe auf eine Taste, um zu ändern, was sie auslöst.","ios.ui.padTestNote": "Jede Taste leuchtet auf, wenn du sie drückst.","ios.ui.padTopButton": "Obere Taste","ios.ui.padUp": "Oben",diff --git a/frontend/l10n/en.json b/frontend/l10n/en.jsonindex 32e52638..8928a285 100644--- a/frontend/l10n/en.json+++ b/frontend/l10n/en.json@@ -758,7 +758,6 @@"ios.ui.padSwapAB": "Swap A and B","ios.ui.padSwapNote": "Puts A on the bottom button, where Xbox and PlayStation controllers confirm.","ios.ui.padSwapped": "A and B swapped",- "ios.ui.padTapDrawing": "Tap a button to change what it sends.","ios.ui.padTestNote": "See each button light up as you press it.","ios.ui.padTopButton": "Top button","ios.ui.padUp": "Up",diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.jsonindex 7509a532..41c3be2e 100644--- a/frontend/l10n/fr.json+++ b/frontend/l10n/fr.json@@ -659,7 +659,6 @@"ios.ui.padSwapAB": "Inverser A et B","ios.ui.padSwapNote": "Place A sur le bouton du bas, là où les manettes Xbox et PlayStation valident.","ios.ui.padSwapped": "A et B inversés",- "ios.ui.padTapDrawing": "Touchez un bouton pour changer ce qu’il envoie.","ios.ui.padTestNote": "Chaque bouton s’allume quand vous appuyez dessus.","ios.ui.padTopButton": "Bouton du haut","ios.ui.padUp": "Haut",diff --git a/frontend/l10n/it.json b/frontend/l10n/it.jsonindex b8907b36..8fc4abff 100644--- a/frontend/l10n/it.json+++ b/frontend/l10n/it.json@@ -660,7 +660,6 @@"ios.ui.padSwapAB": "Scambia A e B","ios.ui.padSwapNote": "Mette A sul tasto in basso, dove confermano i controller Xbox e PlayStation.","ios.ui.padSwapped": "A e B scambiati",- "ios.ui.padTapDrawing": "Tocca un tasto per cambiare cosa invia.","ios.ui.padTestNote": "Ogni tasto si illumina quando lo premi.","ios.ui.padTopButton": "Tasto in alto","ios.ui.padUp": "Su",diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.jsonindex 1312a647..90670aaf 100644--- a/frontend/l10n/sv.json+++ b/frontend/l10n/sv.json@@ -502,7 +502,6 @@"ios.ui.padSwapAB": "Byt A och B","ios.ui.padSwapNote": "Lägger A på den nedre knappen, där Xbox- och PlayStation-handkontroller bekräftar.","ios.ui.padSwapped": "A och B bytta",- "ios.ui.padTapDrawing": "Tryck på en knapp för att ändra vad den skickar.","ios.ui.padTestNote": "Se varje knapp lysa upp när du trycker på den.","ios.ui.padTopButton": "Övre knappen","ios.ui.padUp": "Upp",diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.jsonindex 4884f1c1..37a5e0cf 100644--- a/frontend/l10n/zh.json+++ b/frontend/l10n/zh.json@@ -759,7 +759,6 @@"ios.ui.padSwapAB": "交换 A 和 B","ios.ui.padSwapNote": "把 A 放到下方按键,与 Xbox 和 PlayStation 手柄的确认键位置一致。","ios.ui.padSwapped": "已交换 A 和 B",- "ios.ui.padTapDrawing": "点按某个按键即可更改它对应的键。","ios.ui.padTestNote": "按下按键时,对应的位置会亮起。","ios.ui.padTopButton": "上方按键","ios.ui.padUp": "上",