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
Launch options: the basic settings first, the rest under Advanced settings (#37)
v0lumehi52a3f54fd4bd
diff --git a/frontend/Sources/NSPortBuilder/LaunchOptionsView.swift b/frontend/Sources/NSPortBuilder/LaunchOptionsView.swiftindex 2d9f3e44..8321b664 100644--- a/frontend/Sources/NSPortBuilder/LaunchOptionsView.swift+++ b/frontend/Sources/NSPortBuilder/LaunchOptionsView.swift@@ -1,15 +1,20 @@+import AppKitimport SwiftUI/// A game's launch options: the settings its Mac app was packed with (dm/launcher.json), drawn as the-/// iPhone launcher draws them, one screen grouped by section. Play passes them to the app as its environment.+/// iPhone launcher draws them, grouped by section. The basic settings come first, and the rest+/// under Advanced settings. Play passes them to the app as its environment.struct LaunchOptionsView: View {@ObservedObject var m: BuildModel@ObservedObject var library: GameLibrarylet gameID: UUID@Environment(\.dismiss) private var dismiss+ @State private var advancedOpen = falseprivate var game: LibraryGame? { library.games.first { $0.id == gameID } }- private var settings: [LaunchSetting]? { game.flatMap { LaunchSetting.read(app: $0.appPath) } }+ private var settings: [LaunchSetting]? {+ game.flatMap { LaunchSetting.read(app: $0.appPath) }+ }var body: some View {VStack(alignment: .leading, spacing: 0) {@@ -24,20 +29,23 @@ struct LaunchOptionsView: View {if let settings, !settings.isEmpty, let game {ScrollView {VStack(alignment: .leading, spacing: 24) {- ForEach(sections(settings), id: \.self) { section in- let rows = settings.filter { $0.sectionTitle == section }- VStack(alignment: .leading, spacing: 10) {- Text(m.t("launch.section." + section)).font(.manrope(15, .semibold)).foregroundStyle(.secondary)- .padding(.leading, 2)- VStack(spacing: 0) {- ForEach(rows) { s in- row(s, game)- if s.id != rows.last?.id { Divider().opacity(0.25).padding(.leading, 18) }+ groups(settings.filter(\.isBasic), game)+ let advanced = settings.filter { !$0.isBasic }+ if !advanced.isEmpty {+ card {+ Button { withAnimation(.easeInOut(duration: 0.18)) { advancedOpen.toggle() } } label: {+ HStack(spacing: 8) {+ Text(m.t("launch.advanced")).font(.manrope(14, .medium))+ Image(systemName: "chevron.right").font(.system(size: 10, weight: .bold)).foregroundStyle(.secondary)+ .rotationEffect(.degrees(advancedOpen ? 90 : 0))+ Spacer()+ Text(String(format: m.t("launch.advancedCount"), advanced.count)).font(.manrope(12)).foregroundStyle(.secondary)}+ .padding(.horizontal, 18).frame(minHeight: 52).contentShape(Rectangle())}- .background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 14))- .overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.06)))+ .buttonStyle(.plain)}+ if advancedOpen { groups(advanced, game) }}}.padding(.horizontal, 30).padding(.bottom, 24)@@ -71,6 +79,35 @@ struct LaunchOptionsView: View {.tint(LauncherPalette.cream)}+ // ---- groups of settings ----++ @ViewBuilder private func groups(_ rows: [LaunchSetting], _ game: LibraryGame) -> some View {+ ForEach(sections(rows), id: \.self) { section in+ let inSection = rows.filter { $0.sectionTitle == section }+ VStack(alignment: .leading, spacing: 10) {+ heading(m.t("launch.section." + section))+ card {+ ForEach(inSection) { s in+ row(s, game)+ if s.id != inSection.last?.id { divider }+ }+ }+ }+ }+ }++ private func heading(_ text: String) -> some View {+ Text(text).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)+ }++ private func card<Content: View>(@ViewBuilder _ content: () -> Content) -> some View {+ VStack(spacing: 0, content: content)+ .background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 14))+ .overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.06)))+ }++ private var divider: some View { Divider().opacity(0.25).padding(.leading, 18) }+private func sections(_ settings: [LaunchSetting]) -> [String] {settings.reduce(into: []) { if !$0.contains($1.sectionTitle) { $0.append($1.sectionTitle) } }}diff --git a/frontend/Sources/NSPortBuilder/Library.swift b/frontend/Sources/NSPortBuilder/Library.swiftindex eb347e1a..ca74b5a4 100644--- a/frontend/Sources/NSPortBuilder/Library.swift+++ b/frontend/Sources/NSPortBuilder/Library.swift@@ -55,8 +55,13 @@ struct LaunchSetting: Decodable, Identifiable {let options: [[String]]? // choice: [value, label]let min, max, step: Double? // rangelet on, off: String? // toggle: the values the variable takes+ /// "basic" for a setting shown first (settings.tsv's level column, seedds/nxnative#399); without it, `basicByDefault` decides.+ var level: String? = nilvar id: String { env }var sectionTitle: String { section ?? "Game" }+ /// The rows the sheet shows first, as seedds/nxnative#374 groups them; the rest are under Advanced settings.+ static let basicByDefault: Set = ["DM_FPS_TARGET", "DM_RENDER_SCALE", "DM_OPMODE", "DM_LANG", "DM_RUMBLE"]+ var isBasic: Bool { level.map { $0 == "basic" } ?? Self.basicByDefault.contains(env) }var onValue: String { on ?? "1" }var offValue: String { off ?? "0" }func isDefault(_ v: String) -> Bool { // a range compares as numbers (a slider writes 1.00 for 1.0)@@ -72,7 +77,7 @@ struct LaunchSetting: Decodable, Identifiable {default: return true}}- enum CodingKeys: String, CodingKey { case env, kind, label, note, def = "default", section, options, min, max, step, on, off }+ enum CodingKeys: String, CodingKey { case env, kind, label, note, def = "default", section, options, min, max, step, on, off, level }private struct File: Decodable { let settings: [LaunchSetting] }/// The settings a Mac app was packed with; nil for an app packed before they were.diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex 45d826e3..e3b3982a 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -438,6 +438,8 @@ enum L10n {"controls.fn.LS": ("按下左摇杆", "Left stick press"),"controls.fn.RS": ("按下右摇杆", "Right stick press"),"controls.fn.Shake": ("摇动手柄", "Shake"),+ "launch.advanced": ("高级设置", "Advanced settings"),+ "launch.advancedCount": ("%ld 项", "%ld settings"),"msg.archiveLog": ("归档:%@ → %@", "Archive: %@ → %@"),]diff --git a/frontend/Tests/NSPortBuilderTests/LaunchOptionsTests.swift b/frontend/Tests/NSPortBuilderTests/LaunchOptionsTests.swiftnew file mode 100644index 00000000..96648ce6--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/LaunchOptionsTests.swift@@ -0,0 +1,34 @@+import XCTest+@testable import NSPortBuilder++/// Launch options beyond the app's own list: the basic / advanced split.+final class LaunchOptionsTests: XCTestCase {+ private var temporary: URL!++ override func setUpWithError() throws {+ temporary = FileManager.default.temporaryDirectory.appendingPathComponent("nxnative-launch-" + UUID().uuidString)+ try FileManager.default.createDirectory(at: temporary, withIntermediateDirectories: true)+ }++ override func tearDownWithError() throws { try FileManager.default.removeItem(at: temporary) }++ /// A Mac app with a launcher.json of the given rows.+ private func app(_ rows: String) throws -> String {+ let app = temporary.appendingPathComponent("Game.app")+ let dm = app.appendingPathComponent("Contents/Resources/dm")+ try FileManager.default.createDirectory(at: dm, withIntermediateDirectories: true)+ try #"{"game": "01007EF00011E000", "settings": [\#(rows)]}"#.write(to: dm.appendingPathComponent("launcher.json"), atomically: true, encoding: .utf8)+ return app.path+ }++ private let scale = #"{"env": "DM_RENDER_SCALE", "kind": "range", "label": "Render scale", "note": "", "default": "1.0", "section": "Game", "min": 0.5, "max": 1.0, "step": 0.05}"#+ private let hud = #"{"env": "DM_METAL_HUD", "kind": "toggle", "label": "Metal HUD", "note": "", "default": "0", "section": "Performance", "on": "1", "off": "0"}"#++ func testBasicRowsFirstTheRestAdvancedUnlessTheListSaysOtherwise() throws {+ let list = try XCTUnwrap(LaunchSetting.read(app: try app([scale, hud].joined(separator: ","))))+ XCTAssertEqual(list.filter(\.isBasic).map(\.env), ["DM_RENDER_SCALE"])+ XCTAssertEqual(list.filter { !$0.isBasic }.map(\.env), ["DM_METAL_HUD"])+ let leveled = hud.replacingOccurrences(of: #""off": "0"}"#, with: #""off": "0", "level": "basic"}"#)+ XCTAssertTrue(try XCTUnwrap(LaunchSetting.read(app: try app(leveled))).first!.isBasic, "a level in launcher.json (seedds/nxnative#399) wins over the default split")+ }+}