Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Mark Switch 2 games in the library and on the Builds page

v0lumehi334a69e25d51
diff --git a/frontend/Sources/NX2Apple/LauncherView+Library.swift b/frontend/Sources/NX2Apple/LauncherView+Library.swift
index 39a47c4d..b80323c7 100644
--- a/frontend/Sources/NX2Apple/LauncherView+Library.swift
+++ b/frontend/Sources/NX2Apple/LauncherView+Library.swift
@@ -248,6 +248,13 @@ extension LauncherView {
.font(prominent ? .manrope(12, .bold) : .manrope(13, .medium))
.tracking(prominent ? 1.3 : 0) // the eyebrow: the same face, in tracked capitals
.foregroundStyle(color)
+ if GameFolder.profileIsSwitch2(game.titleID, engineRoot: EngineLayout.root(m.repo.path)) { // #445
+ Text(loc.t("switch2.badge"))
+ .font(.manrope(prominent ? 11 : 10.5, .bold)).foregroundStyle(LauncherPalette.cream.opacity(0.85))
+ .padding(.horizontal, 7).padding(.vertical, 2)
+ .overlay(Capsule().strokeBorder(LauncherPalette.cream.opacity(0.35)))
+ .help(loc.t("switch2.help"))
+ }
if !building && toolsAge.older.contains(game.id) { // a quiet note beside the status, not a warning
Text("· " + loc.t(prominent ? "library.olderTools" : "library.olderToolsShort"))
.font(.manrope(prominent ? 13 : 12)).foregroundStyle(.secondary).lineLimit(1)
diff --git a/frontend/Sources/NX2Apple/Library.swift b/frontend/Sources/NX2Apple/Library.swift
index b1baffbc..7e1cfc09 100644
--- a/frontend/Sources/NX2Apple/Library.swift
+++ b/frontend/Sources/NX2Apple/Library.swift
@@ -384,6 +384,19 @@ final class GameLibrary: ObservableObject {
while let url = e.nextObject() as? URL {
if (try? url.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true {
let name = url.lastPathComponent.lowercased()
+ // A game folder (a Switch 2 game's base/, updates/, dlc/, GameFolder.swift) is one game: its folder is its input,
+ // and its 80,000 files are not walked.
+ if GameFolder.isCandidate(url.path) {
+ e.skipDescendants()
+ if case .success(let f) = GameFolder.scan(url.path), result[f.titleIDHex] == nil {
+ var game = LibraryGame(titleID: f.titleIDHex, name: title(for: url.path, repo: repo, titleID: f.titleIDHex))
+ game.inputs = [GameLibrary.folderInput: [url.path], "base": [f.basePath]]
+ game.sourceFolder = url.path
+ game.outputDirectory = url.path
+ result[f.titleIDHex] = game
+ }
+ continue
+ }
if e.level >= 4 || name.hasSuffix(".app") || name.hasSuffix("_build") || name.hasSuffix("-work") || name.hasSuffix("_survey") || ["romfs", "extract", "tools", "venv", "archive", "harness", "runs", "shader", "node_modules"].contains(name) { e.skipDescendants() }
continue
}
diff --git a/frontend/Sources/NXCore/GameFolder.swift b/frontend/Sources/NXCore/GameFolder.swift
index f970aef5..952e0a6b 100644
--- a/frontend/Sources/NXCore/GameFolder.swift
+++ b/frontend/Sources/NXCore/GameFolder.swift
@@ -132,6 +132,18 @@ package enum GameFolder {
return name.isEmpty ? nil : name
}
+ /// Whether the engine's profile is a Switch 2 game's. No profile key says so yet (#445 asks upstream for one): every Switch 2
+ /// profile at seedds/nxnative 641d148 names it in its first line, "# Donkey Kong Bananza (Switch 2, update v458752)", and the
+ /// launcher reads that. The `04` start of their title IDs is not used: it is an observation, not a rule.
+ package static func profileIsSwitch2(_ titleID: String, engineRoot: String) -> Bool {
+ guard !engineRoot.isEmpty, titleID.count == 16,
+ let handle = FileHandle(forReadingAtPath: engineRoot + "/dm/games/" + titleID.uppercased() + "/game.tsv") else { return false }
+ defer { try? handle.close() }
+ let head = String(decoding: handle.readData(ofLength: 512), as: UTF8.self)
+ guard let first = head.split(separator: "\n", maxSplits: 1).first, first.hasPrefix("#") else { return false }
+ return first.contains("(Switch 2")
+ }
+
private static func isFile(_ path: String) -> Bool {
var d: ObjCBool = false
return FileManager.default.fileExists(atPath: path, isDirectory: &d) && !d.boolValue
diff --git a/frontend/Sources/NXLauncher/TargetCard.swift b/frontend/Sources/NXLauncher/TargetCard.swift
index dbb64785..2b2e880b 100644
--- a/frontend/Sources/NXLauncher/TargetCard.swift
+++ b/frontend/Sources/NXLauncher/TargetCard.swift
@@ -17,6 +17,16 @@ package struct TargetCard: View {
targetCard(BuildTarget.mac, symbol: "desktopcomputer", title: "build.mac", note: "build.macNote")
targetCard(BuildTarget.ios, symbol: "iphone", title: "build.ios", note: "build.iosNote")
}
+ // A Switch 2 game (#445): how far the engine's support goes, for the chosen target. Nothing is blocked: the engine
+ // builds both, and one Switch 2 game ran on an iPhone, but no target is tested for every game.
+ if build.isSwitch2Game {
+ HStack(alignment: .top, spacing: 10) {
+ Image(systemName: "info.circle").font(.system(size: 13)).foregroundStyle(LauncherPalette.cream.opacity(0.7))
+ Text(loc.t(build.target == BuildTarget.mac ? "switch2.noteMac" : "switch2.noteIOS"))
+ .font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ }
+ .padding(.horizontal, 4).padding(.top, 2)
+ }
// A Mac app runs on this Mac's GPU, which always decodes BC textures: the switch is the iPhone's only.
if build.target != BuildTarget.mac {
VStack(spacing: 0) {
diff --git a/frontend/Sources/NXModel/BuildStore+GameFolder.swift b/frontend/Sources/NXModel/BuildStore+GameFolder.swift
index bc5ac803..79cfe1ed 100644
--- a/frontend/Sources/NXModel/BuildStore+GameFolder.swift
+++ b/frontend/Sources/NXModel/BuildStore+GameFolder.swift
@@ -87,6 +87,12 @@ extension BuildStore {
/// The game's title ID as 16 hex digits, when the inputs tell it.
package var gameTitleID: String? { gameFolder?.titleIDHex ?? TitleID.parse(basePath).map { String(format: "%016llX", $0) } }
+ /// The chosen game is a Switch 2 game by its engine profile (GameFolder.profileIsSwitch2): the Builds page says how far the engine's support goes.
+ package var isSwitch2Game: Bool {
+ guard let tid = gameTitleID else { return false }
+ return GameFolder.profileIsSwitch2(tid, engineRoot: EngineLayout.root(repo.path))
+ }
+
/// A name for the game in messages and the shared app: the profile's for a game folder (it has no control data), else the base package's file name.
package var gameName: String {
if let f = gameFolder {
diff --git a/frontend/Tests/NX2AppleTests/FrenchLocalizationTests.swift b/frontend/Tests/NX2AppleTests/FrenchLocalizationTests.swift
index 35c701c1..81641455 100644
--- a/frontend/Tests/NX2AppleTests/FrenchLocalizationTests.swift
+++ b/frontend/Tests/NX2AppleTests/FrenchLocalizationTests.swift
@@ -18,6 +18,7 @@ final class FrenchLocalizationTests: IsolatedDefaultsTestCase {
"controls.fn.B", "controls.fn.X", "controls.fn.Y", "controls.fn.L", "controls.fn.R",
"controls.fn.ZL", "controls.fn.ZR", "controls.fn.Plus", "controls.fn.Minus", "launch.mods",
"pad.options", "engine.channel.stable", "launch.opt.DM_PRESENT_UPSCALE.off", "launch.opt.DM_PRESENT_UPSCALE.metalfx", "launch.opt.DM_UPSCALER.metalfx", "key.tab",
+ "switch2.badge", // the console's name
]
func testNothingIsLeftInEnglishButTheListedNames() {
diff --git a/frontend/Tests/NX2AppleTests/GameFolderCaptureTests.swift b/frontend/Tests/NX2AppleTests/GameFolderCaptureTests.swift
index 15c49b4e..a5ec6e2a 100644
--- a/frontend/Tests/NX2AppleTests/GameFolderCaptureTests.swift
+++ b/frontend/Tests/NX2AppleTests/GameFolderCaptureTests.swift
@@ -42,8 +42,48 @@ final class GameFolderCaptureTests: IsolatedDefaultsTestCase {
return Data(d)
}
+ /// The library folder scan finds a game folder as one game, keyed by its title ID, with the folder as its input (#512).
+ func testTheLibraryScanFindsAGameFolder() {
+ let root = NSTemporaryDirectory() + "gamefolder-library-" + UUID().uuidString
+ defer { try? FileManager.default.removeItem(atPath: root) }
+ let folders = Self.makeFolders(in: root)
+ let games = GameLibrary.sourceGames(in: URL(fileURLWithPath: root), repo: folders.engine)
+ XCTAssertEqual(games.map(\.titleID), ["040074A01BF12000"])
+ XCTAssertEqual(games.first?.name, "Donkey Kong Bananza", "the profile's name")
+ let real = { (p: String) in URL(fileURLWithPath: p).resolvingSymlinksInPath().path } // the enumerator hands out /private/var/…
+ XCTAssertEqual(games.first?.inputs[GameLibrary.folderInput]?.map(real), [real(folders.game)])
+ XCTAssertEqual(games.first.map { real($0.sourceFolder) }, real(folders.game))
+ }
+
// MARK: Visual QA (matched by --filter testRenderLauncherForVisualQA)
+ @MainActor func testRenderLauncherForVisualQAGameFolderLibrary() throws {
+ guard let directory = ProcessInfo.processInfo.environment["NX_LAUNCHER_CAPTURE_DIR"] else { throw XCTSkip("Set NX_LAUNCHER_CAPTURE_DIR to capture native views") }
+ let output = URL(fileURLWithPath: directory)
+ try FileManager.default.createDirectory(at: output, withIntermediateDirectories: true)
+ let root = NSTemporaryDirectory() + "gamefolder-capture-" + UUID().uuidString
+ defer { try? FileManager.default.removeItem(atPath: root) }
+ let folders = Self.makeFolders(in: root)
+ NSApplication.shared.setActivationPolicy(.accessory)
+ let stores = LauncherStores(defaults: testDefaults); let model = stores.build
+ stores.repo.path = folders.engine
+ model.lang = CaptureLanguage.current(.en)
+ let library = GameLibrary(file: URL(fileURLWithPath: root + "/preview.json"))
+ model.scan(folder: folders.game)
+ _ = library.rememberInputs(model)
+ library.selectedID = library.games.first?.id
+ let host = NSHostingView(rootView: LauncherView(stores: stores, library: library, initialPage: .library, performStartupChecks: false))
+ let window = OffscreenWindow(size: NSSize(width: 1440, height: 1024), styleMask: [.titled, .closable, .resizable])
+ window.contentView = host
+ window.orderFront(nil)
+ RunLoop.main.run(until: Date().addingTimeInterval(0.8))
+ host.layoutSubtreeIfNeeded()
+ let rep = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))
+ host.cacheDisplay(in: host.bounds, to: rep)
+ try XCTUnwrap(rep.representation(using: .png, properties: [:])).write(to: output.appendingPathComponent("library-game-folder.png"))
+ window.orderOut(nil)
+ }
+
@MainActor func testRenderLauncherForVisualQAGameFolder() throws {
guard let directory = ProcessInfo.processInfo.environment["NX_LAUNCHER_CAPTURE_DIR"] else { throw XCTSkip("Set NX_LAUNCHER_CAPTURE_DIR to capture native views") }
let output = URL(fileURLWithPath: directory)
diff --git a/frontend/Tests/NX2AppleTests/GermanLocalizationTests.swift b/frontend/Tests/NX2AppleTests/GermanLocalizationTests.swift
index 8da0dc27..fa8dc40e 100644
--- a/frontend/Tests/NX2AppleTests/GermanLocalizationTests.swift
+++ b/frontend/Tests/NX2AppleTests/GermanLocalizationTests.swift
@@ -20,6 +20,7 @@ final class GermanLocalizationTests: IsolatedDefaultsTestCase {
"controls.fn.ZL", "controls.fn.ZR", "controls.fn.Plus", "controls.fn.Minus", "launch.mods",
"update.pill", "launch.opt.DM_OPMODE.0", "launch.opt.DM_PRESENT_UPSCALE.off",
"launch.opt.DM_FPS_TARGET.30", "launch.opt.DM_FPS_TARGET.60", "launch.opt.DM_PRESENT_UPSCALE.metalfx", "launch.opt.DM_UPSCALER.metalfx",
+ "switch2.badge", // the console's name
]
func testGermanIsNotLeftInEnglish() {
diff --git a/frontend/Tests/NXCoreTests/GameFolderTests.swift b/frontend/Tests/NXCoreTests/GameFolderTests.swift
index e3de64b8..31350e20 100644
--- a/frontend/Tests/NXCoreTests/GameFolderTests.swift
+++ b/frontend/Tests/NXCoreTests/GameFolderTests.swift
@@ -131,6 +131,22 @@ final class GameFolderTests: XCTestCase {
}
}
+extension GameFolderTests {
+ /// No profile key says "Switch 2" yet: the first line of every Switch 2 profile at seedds/nxnative 641d148 does (#445).
+ func testTheProfilesFirstLineTellsASwitch2Game() {
+ let engine = root + "/engine"
+ write("engine/dm/games/040074A01BF12000/game.tsv", Data("# Donkey Kong Bananza (Switch 2, update v458752). In bring-up\ntitle_id\t040074A01BF12000\n".utf8))
+ write("engine/dm/games/0100F2C0115B6000/game.tsv", Data("# The Legend of Zelda: Tears of the Kingdom (update v1.4.2)\n# mentions (Switch 2 Edition) later\n".utf8))
+ write("engine/dm/games/0100000000010000/game.tsv", Data("title_id\t0100000000010000\n# (Switch 2\n".utf8))
+ XCTAssertTrue(GameFolder.profileIsSwitch2("040074A01BF12000", engineRoot: engine))
+ XCTAssertTrue(GameFolder.profileIsSwitch2("040074a01bf12000", engineRoot: engine))
+ XCTAssertFalse(GameFolder.profileIsSwitch2("0100F2C0115B6000", engineRoot: engine), "only the first line counts")
+ XCTAssertFalse(GameFolder.profileIsSwitch2("0100000000010000", engineRoot: engine), "only a comment line counts")
+ XCTAssertFalse(GameFolder.profileIsSwitch2("0400000000000000", engineRoot: engine), "no profile")
+ XCTAssertFalse(GameFolder.profileIsSwitch2("040074A01BF12000", engineRoot: ""))
+ }
+}
+
extension Result {
var failureValue: Failure? { if case .failure(let e) = self { return e }; return nil }
}
diff --git a/frontend/l10n/de.json b/frontend/l10n/de.json
index ca869894..2b66b223 100644
--- a/frontend/l10n/de.json
+++ b/frontend/l10n/de.json
@@ -1260,6 +1260,10 @@
"status.installFirst": "Installiere zuerst die oben fehlenden Abhängigkeiten",
"status.needInputs": "Basisspiel und prod.keys fehlen noch",
"status.output": "Ausgabe: %@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "Ein Switch 2-Spiel. Die Unterstützung der Engine für Switch 2-Spiele ist neu.",
+ "switch2.noteIOS": "Ein Switch 2-Spiel. Auf iPhone und iPad sind Switch 2-Spiele kaum getestet. Ein Build startet auf deinem Gerät vielleicht nicht, und das Spiel braucht viel Speicher.",
+ "switch2.noteMac": "Ein Switch 2-Spiel. Die Unterstützung der Engine dafür ist neu, und jedes Spiel wird noch angepasst. Es läuft auf dem Mac, Teile funktionieren vielleicht noch nicht.",
"target.hint.ios": "Eine IPA für ein iPhone wird gebaut",
"target.hint.mac": "Eine per Doppelklick startbare Mac-App wird gebaut",
"target.ios": "Ziel: iPhone-IPA",
diff --git a/frontend/l10n/en.json b/frontend/l10n/en.json
index e078ef49..34e1d2f8 100644
--- a/frontend/l10n/en.json
+++ b/frontend/l10n/en.json
@@ -1386,6 +1386,10 @@
"status.installFirst": "Install the missing dependencies above first",
"status.needInputs": "Still need the base game and prod.keys",
"status.output": "Output: %@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "A Switch 2 game. The engine's support for Switch 2 games is new.",
+ "switch2.noteIOS": "A Switch 2 game. On iPhone and iPad, Switch 2 games are barely tested. A build may not start on your device, and the game needs a lot of memory.",
+ "switch2.noteMac": "A Switch 2 game. The engine's support for these is new, and each game is still being brought up. It plays on the Mac, with parts that may not work yet.",
"target.hint.ios": "Building an IPA for an iPhone",
"target.hint.mac": "Building a double-clickable Mac app",
"target.ios": "Output: iPhone IPA",
diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.json
index 2e69f71d..41100d84 100644
--- a/frontend/l10n/fr.json
+++ b/frontend/l10n/fr.json
@@ -1262,6 +1262,10 @@
"status.installFirst": "Installez d’abord les dépendances manquantes ci-dessus",
"status.needInputs": "Il manque encore le jeu de base et prod.keys",
"status.output": "Sortie : %@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "Un jeu Switch 2. La prise en charge des jeux Switch 2 par le moteur est récente.",
+ "switch2.noteIOS": "Un jeu Switch 2. Sur iPhone et iPad, les jeux Switch 2 sont à peine testés. Une compilation peut ne pas démarrer sur votre appareil, et le jeu demande beaucoup de mémoire.",
+ "switch2.noteMac": "Un jeu Switch 2. Le moteur les prend en charge depuis peu, et chaque jeu est encore en cours d'adaptation. Il tourne sur le Mac, certaines parties peuvent ne pas encore fonctionner.",
"target.hint.ios": "Compilation d’une IPA pour iPhone",
"target.hint.mac": "Compilation d’une app Mac à double-cliquer",
"target.ios": "Sortie : IPA iPhone",
diff --git a/frontend/l10n/it.json b/frontend/l10n/it.json
index ff22112e..084e177f 100644
--- a/frontend/l10n/it.json
+++ b/frontend/l10n/it.json
@@ -1263,6 +1263,10 @@
"status.installFirst": "Prima installa le dipendenze mancanti qui sopra",
"status.needInputs": "Mancano ancora il gioco base e prod.keys",
"status.output": "Destinazione: %@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "Un gioco Switch 2. Il supporto del motore per i giochi Switch 2 è nuovo.",
+ "switch2.noteIOS": "Un gioco Switch 2. Su iPhone e iPad i giochi Switch 2 sono appena testati. Una build potrebbe non avviarsi sul tuo dispositivo, e il gioco richiede molta memoria.",
+ "switch2.noteMac": "Un gioco Switch 2. Il motore li supporta da poco, e ogni gioco è ancora in fase di adattamento. Gira sul Mac, alcune parti potrebbero non funzionare ancora.",
"target.hint.ios": "Compilazione di un IPA per iPhone",
"target.hint.mac": "Compilazione di un’app per Mac da aprire con doppio clic",
"target.ios": "Destinazione: IPA per iPhone",
diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.json
index 931fe699..af6ddbe4 100644
--- a/frontend/l10n/sv.json
+++ b/frontend/l10n/sv.json
@@ -1100,6 +1100,10 @@
"status.installFirst": "Installera först de saknade beroendena ovan.",
"status.needInputs": "Grundspelet och prod.keys saknas fortfarande",
"status.output": "Utdata: %@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "Ett Switch 2-spel. Motorns stöd för Switch 2-spel är nytt.",
+ "switch2.noteIOS": "Ett Switch 2-spel. På iPhone och iPad är Switch 2-spel knappt testade. Ett bygge kanske inte startar på din enhet, och spelet behöver mycket minne.",
+ "switch2.noteMac": "Ett Switch 2-spel. Motorns stöd för dem är nytt, och varje spel håller fortfarande på att anpassas. Det går att spela på Macen, men delar kanske inte fungerar än.",
"target.hint.ios": "Bygger en IPA för iPhone",
"target.hint.mac": "Bygger en Mac-app som kan öppnas med dubbelklick",
"target.ios": "Utdata: iPhone-IPA",
diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.json
index b6deb1d3..dec2b504 100644
--- a/frontend/l10n/zh.json
+++ b/frontend/l10n/zh.json
@@ -1387,6 +1387,10 @@
"status.installFirst": "先安装上方缺失的依赖",
"status.needInputs": "还需要选择游戏本体和 prod.keys",
"status.output": "输出:%@",
+ "switch2.badge": "Switch 2",
+ "switch2.help": "Switch 2 游戏。引擎对 Switch 2 游戏的支持是新加入的。",
+ "switch2.noteIOS": "Switch 2 游戏。在 iPhone 和 iPad 上,Switch 2 游戏几乎没有测试过。构建出来的游戏可能无法在你的设备上启动,而且游戏需要很多内存。",
+ "switch2.noteMac": "Switch 2 游戏。引擎对这类游戏的支持是新加入的,每个游戏都还在适配中。它可以在 Mac 上玩,但有些部分可能还不能正常工作。",
"target.hint.ios": "构建 iPhone 用的 IPA",
"target.hint.mac": "构建可直接双击运行的 Mac App",
"target.ios": "输出:iPhone IPA",