Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Launch options: the basic settings first, the rest under Advanced set…
…tings (#37)

The sheet listed every row of the app's launcher.json in one column of
sections (Game, Controls, Performance), so the settings a player changes
most sat among the ones only a tuning session needs. The basic ones come
first now, in their sections: frame rate, render scale, console mode,
language and rumble. The rest is behind an Advanced settings row that
says how many it holds and opens them in place.

Which rows are basic comes from the list when it says so (a row's level,
seedds/nxnative#399: settings.tsv's optional level column), else from
the launcher's own list of those five. Apps packed before the column
show the same split.

LaunchOptionsTests: the default split, and a level in launcher.json
winning over it.
  • Loading branch information
v0lumehi committed Oct 27, 2026
commit 52a3f54fd4bde4b2213bbc7f044b599c8bfff12a
63 changes: 50 additions & 13 deletions frontend/Sources/NSPortBuilder/LaunchOptionsView.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import AppKit
import 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: GameLibrary
let gameID: UUID
@Environment(\.dismiss) private var dismiss
@State private var advancedOpen = false

private 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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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) } }
}
Expand Down
7 changes: 6 additions & 1 deletion frontend/Sources/NSPortBuilder/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ struct LaunchSetting: Decodable, Identifiable {
let options: [[String]]? // choice: [value, label]
let min, max, step: Double? // range
let 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? = nil
var 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)
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions frontend/Sources/NSPortBuilder/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: %@ → %@"),
]

Expand Down
34 changes: 34 additions & 0 deletions frontend/Tests/NSPortBuilderTests/LaunchOptionsTests.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}