Skip to content

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

Console mode: calm focus animation, glyphs and buttons by label, margins, Starting backdrop

v0lumehi4ad3e8153d35
diff --git a/frontend/Sources/NSPortBuilder/ConsoleControllersView.swift b/frontend/Sources/NSPortBuilder/ConsoleControllersView.swift
index 434a10be..86b5e478 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleControllersView.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleControllersView.swift
@@ -139,7 +139,7 @@ struct ConsoleToastView: View {
}
.buttonStyle(.plain).accessibilityLabel(String(format: t("console.player"), player))
.accessibilityAddTraits(state.assigningPlayer == player ? .isSelected : [])
- .padTarget("console.player.\(player)", scope: scope, activate: { driver.requestPlayer(player) })
+ .padTarget("console.player.\(player)", scope: scope, radius: 12, activate: { driver.requestPlayer(player) })
}
}
if let player = state.assigningPlayer {
@@ -168,11 +168,11 @@ struct ConsoleToastView: View {
}
Spacer(minLength: 0)
}
- let layout = compact ? AnyLayout(VStackLayout(alignment: .leading, spacing: 10)) : AnyLayout(HStackLayout(spacing: 10))
- layout {
- action(id: controller.id + ".identify", label: t(state.identifyingControllerID == controller.id ? "console.identifying" : "console.identify"), symbol: "wave.3.right") { driver.identify(controllerID: controller.id) }
- action(id: controller.id + ".assign", label: t("console.assign"), symbol: "person.crop.circle.badge.plus") { driver.requestAssignment(controllerID: controller.id) }
- action(id: controller.id + ".disconnect", label: t("console.disconnect"), symbol: "xmark.circle") { driver.disconnect(controllerID: controller.id) }
+ // Three equal tiles: the icon above a label that wraps between words only (and shrinks a little rather than break a word).
+ HStack(spacing: 10) {
+ tile(id: controller.id + ".identify", label: t(state.identifyingControllerID == controller.id ? "console.identifying" : "console.identify"), symbol: "wave.3.right") { driver.identify(controllerID: controller.id) }
+ tile(id: controller.id + ".assign", label: t("console.assign"), symbol: "person.crop.circle.badge.plus") { driver.requestAssignment(controllerID: controller.id) }
+ tile(id: controller.id + ".disconnect", label: t("console.disconnect"), symbol: "xmark.circle") { driver.disconnect(controllerID: controller.id) }
}
if state.isPreview, state.assigningPlayer != nil, state.assigningControllerID == nil || state.assigningControllerID == controller.id {
action(id: controller.id + ".press", label: t("console.mockPress"), symbol: "hand.tap") {
@@ -182,6 +182,20 @@ struct ConsoleToastView: View {
}
.padding(20).background(LauncherPalette.surface, in: RoundedRectangle(cornerRadius: 16))
}
+ private func tile(id: String, label: String, symbol: String, perform: @escaping () -> Void) -> some View {
+ Button(action: perform) {
+ VStack(spacing: 8) {
+ Image(systemName: symbol).font(.system(size: compact ? 20 : 24)).accessibilityHidden(true)
+ Text(label).font(.manrope(compact ? 14 : 17, .semibold)).multilineTextAlignment(.center)
+ .lineLimit(2).minimumScaleFactor(0.7).fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(maxWidth: .infinity, minHeight: compact ? 88 : 96).padding(.horizontal, 6)
+ .background(.white.opacity(0.045), in: RoundedRectangle(cornerRadius: 10)).contentShape(RoundedRectangle(cornerRadius: 10))
+ }
+ .buttonStyle(.plain)
+ .padTarget("console.controller." + id, scope: scope, radius: 10, activate: perform)
+ .accessibilityLabel(label)
+ }
private func action(id: String, label: String, value: String? = nil, symbol: String, adjust: ((Int) -> Void)? = nil, perform: @escaping () -> Void) -> some View {
Button(action: perform) {
VStack(alignment: .leading, spacing: 8) {
@@ -209,12 +223,13 @@ struct ConsoleToastView: View {
Spacer()
Button(action: close) { Image(systemName: "xmark").frame(width: 48, height: 48) }
.buttonStyle(.plain).accessibilityLabel(L10n.string("console.close", lang))
- .padTarget("console.sheet.close", scope: "console.controllers", activate: close)
+ .padTarget("console.sheet.close", scope: "console.controllers", radius: 24, activate: close)
}.padding(24)
ConsoleControllerList(driver: driver, lang: lang, compact: true)
}
.frame(minWidth: 360, idealWidth: 580, maxWidth: 580, minHeight: 600, idealHeight: 720, maxHeight: 720).background(LauncherPalette.background).preferredColorScheme(.dark)
.foregroundStyle(.white).padScope("console.controllers", pad)
+ .environment(\.padRingStyle, .hug)
.onAppear { pad.scope = "console.controllers"; pad.focused = "console.controller.merge" }
.overlay(alignment: .bottom) { if let toast = driver.state.toast { ConsoleToastView(toast: toast) } }
.background(ConsoleKeyboardInput { input in
diff --git a/frontend/Sources/NSPortBuilder/ConsoleEntryView.swift b/frontend/Sources/NSPortBuilder/ConsoleEntryView.swift
index f3eceee0..05ea23f2 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleEntryView.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleEntryView.swift
@@ -48,6 +48,7 @@ struct ConsoleConnectionPrompt: View {
.padding(24)
}
.padScope("console.entry", pad)
+ .environment(\.padRingStyle, .hug)
.background(ConsoleKeyboardInput { input in
pad.show(default: "console.entry.enter")
switch input {
diff --git a/frontend/Sources/NSPortBuilder/ConsoleGlyphs.swift b/frontend/Sources/NSPortBuilder/ConsoleGlyphs.swift
index 06817e85..abf2f2c0 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleGlyphs.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleGlyphs.swift
@@ -1,12 +1,13 @@
import GameController
import SwiftUI
-/// The button glyphs the console mode shows, for the input used last. The launcher's controller navigation is by position
-/// (Gamepad.swift: Action.a is GameController's buttonB, the east face button, Action.b is buttonA at the south, Y is buttonX at
-/// the west, and + is buttonMenu), so each action resolves to a physical element and the glyph is whatever that element is
-/// printed with on the controller: Apple's per-element `sfSymbolsName`, a per-family table when the controller reports none, a
-/// key cap for the keyboard, and our own neutral letter when nothing is known. The Controls page's layout (By label, #70) only
-/// changes what a game receives (DM_PAD_MAP), never what the launcher's menus do, so it does not move these glyphs. No logos.
+/// The button glyphs the console mode shows, for the input used last. The launcher reads the face buttons by label
+/// (`LauncherGamepad.face`): Play is GameController's buttonA, Back is buttonB, Controllers is buttonY and options is
+/// buttonMenu. GameController documents the diamond as A at the bottom, B right, X left, Y top (GCExtendedGamepad.h), so on a
+/// DualSense A is the cross, B the circle, X the square and Y the triangle. The glyph is the element's own `sfSymbolsName`
+/// (input remapping included), a per-family table when it reports none, a key cap for the keyboard, and our own neutral letter
+/// when nothing is known. The Controls page's layout (By label) only changes what a game receives (DM_PAD_MAP), so it does not
+/// move these glyphs. No logos.
struct ConsoleGlyphs: Equatable {
enum Family: Equatable {
case xbox, playStation, nintendo, keyboard, neutral
@@ -20,16 +21,25 @@ struct ConsoleGlyphs: Equatable {
else { self = .neutral }
}
}
- /// A physical button, by position.
- enum Element: Hashable { case east, south, west, north, menu }
+ /// A button as GameController names it.
+ enum Element: Hashable { case a, b, x, y, menu }
enum Role {
case activate, back, options, controllers
var element: Element {
switch self {
- case .activate: return .east
- case .back: return .south
+ case .activate: return Self.element(of: .a)
+ case .back: return Self.element(of: .b)
case .options: return .menu
- case .controllers: return .west
+ case .controllers: return Self.element(of: .y)
+ }
+ }
+ /// The element that performs a launcher action, taken from the one mapping Gamepad.swift reads, so glyph and button cannot differ.
+ private static func element(of action: LauncherGamepad.Action) -> Element {
+ switch LauncherGamepad.face(for: action) {
+ case .a?: return .a
+ case .b?: return .b
+ case .x?: return .x
+ case .y?, nil: return .y
}
}
var keyCap: String {
@@ -57,9 +67,9 @@ struct ConsoleGlyphs: Equatable {
/// What a family's elements are printed with, for a controller that reports no symbol of its own.
static func table(_ family: Family) -> [Element: String] {
switch family {
- case .xbox: return [.east: "b.circle", .south: "a.circle", .west: "x.circle", .north: "y.circle", .menu: "line.3.horizontal.circle"]
- case .playStation: return [.east: "circle.circle", .south: "xmark.circle", .west: "square.circle", .north: "triangle.circle", .menu: "line.3.horizontal.circle"]
- case .nintendo: return [.east: "a.circle", .south: "b.circle", .west: "y.circle", .north: "x.circle", .menu: "plus.circle"]
+ case .xbox: return [.a: "a.circle", .b: "b.circle", .x: "x.circle", .y: "y.circle", .menu: "line.3.horizontal.circle"]
+ case .playStation: return [.a: "xmark.circle", .b: "circle.circle", .x: "square.circle", .y: "triangle.circle", .menu: "line.3.horizontal.circle"]
+ case .nintendo: return [.a: "a.circle", .b: "b.circle", .x: "x.circle", .y: "y.circle", .menu: "plus.circle"]
case .keyboard, .neutral: return [:]
}
}
@@ -69,7 +79,7 @@ struct ConsoleGlyphs: Equatable {
init(controller: GCController) {
family = Family(category: controller.productCategory)
if let pad = controller.extendedGamepad {
- let elements: [(Element, GCControllerButtonInput)] = [(.east, pad.buttonB), (.south, pad.buttonA), (.west, pad.buttonX), (.north, pad.buttonY), (.menu, pad.buttonMenu)]
+ let elements: [(Element, GCControllerButtonInput)] = [(.a, pad.buttonA), (.b, pad.buttonB), (.x, pad.buttonX), (.y, pad.buttonY), (.menu, pad.buttonMenu)]
for (element, button) in elements { if let name = button.sfSymbolsName { reported[element] = name } }
}
}
diff --git a/frontend/Sources/NSPortBuilder/ConsoleView.swift b/frontend/Sources/NSPortBuilder/ConsoleView.swift
index a49fb970..820b9d13 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleView.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleView.swift
@@ -81,6 +81,7 @@ enum ConsoleInput {
.tint(LauncherPalette.cream)
.preferredColorScheme(.dark)
.environmentObject(pad)
+ .environment(\.padRingStyle, .hug)
.background(ConsoleKeyboardInput(perform: { input in glyphs = .keyboard; handle(input) }).frame(width: 0, height: 0))
.onReceive(inputs, perform: handle)
.onChange(of: scope) { _ in resetFocus() }
@@ -90,14 +91,14 @@ enum ConsoleInput {
.onChange(of: pad.focused) { id in
if let id, id.hasPrefix("console.game.") { driver.focus(String(id.dropFirst("console.game.".count))) }
}
- .animation(.easeOut(duration: 0.22), value: state.focusedGame?.id)
.animation(.easeOut(duration: 0.18), value: state.presentedSheet)
.animation(.easeOut(duration: 0.18), value: state.toast?.id)
.animation(.easeOut(duration: 0.22), value: state.startingGameID)
}
private func backdrop(size: CGSize) -> some View {
- ZStack {
+ let starting = state.startingGame != nil // the cover fills the window, soft and darkened (a static blur: Reduce Motion changes nothing here)
+ return ZStack {
LauncherPalette.background
if let game = state.startingGame ?? state.focusedGame {
Group {
@@ -105,10 +106,12 @@ enum ConsoleInput {
else { LinearGradient(colors: ConsolePlaceholder.colors(for: game.title), startPoint: .topLeading, endPoint: .bottomTrailing) }
}
.frame(width: size.width, height: size.height)
- .blur(radius: 70).drawingGroup().opacity(0.30).id(game.id).transition(.opacity)
+ .blur(radius: starting ? 36 : 70).drawingGroup().opacity(starting ? 1 : 0.30).id(game.id).transition(.opacity)
}
- LinearGradient(colors: [.black.opacity(0.10), LauncherPalette.background.opacity(0.95)], startPoint: .top, endPoint: .bottom)
+ if starting { Color.black.opacity(0.32) } // a scrim keeps the Starting text readable on any cover
+ if !starting { LinearGradient(colors: [.black.opacity(0.10), LauncherPalette.background.opacity(0.95)], startPoint: .top, endPoint: .bottom) }
}
+ .animation(.easeInOut(duration: reduceMotion ? 0.01 : 0.38), value: (state.startingGame ?? state.focusedGame)?.id) // the art cross-fades, slowly and softly
.clipped().ignoresSafeArea().accessibilityHidden(true)
}
@@ -122,6 +125,9 @@ enum ConsoleInput {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: compact || size.height < 900 ? 24 : 32) {
if let game = state.focusedGame {
+ // A fixed-height slot: the old and the new title overlap and cross-fade in place (0.15 s), so nothing slides
+ // and the row below never moves, whatever the title's length.
+ ZStack(alignment: .bottomLeading) {
VStack(alignment: .leading, spacing: compact ? 14 : 20) {
Text(t("console.library")).font(.manrope(compact ? 14 : 18, .semibold))
.tracking(2).foregroundStyle(LauncherPalette.cream.opacity(0.75))
@@ -129,7 +135,8 @@ enum ConsoleInput {
.tracking(-1.6).lineLimit(2).fixedSize(horizontal: false, vertical: true)
.accessibilityAddTraits(.isHeader)
HStack(spacing: 12) {
- Text(String(format: t("console.version"), game.version)).foregroundStyle(.white.opacity(0.6))
+ Text(String(format: t("console.version"), game.version)).monospacedDigit().lineLimit(1)
+ .foregroundStyle(.white.opacity(0.6)).frame(width: compact ? 118 : 176, alignment: .leading) // fixed, so the badges stay put
ForEach(game.platforms, id: \.self) { platform in
Text(t(platform.labelKey)).font(.manrope(compact ? 13 : 17, .semibold))
.padding(.horizontal, 12).padding(.vertical, 5)
@@ -138,8 +145,11 @@ enum ConsoleInput {
}
.font(.manrope(compact ? 14 : 18))
}
+ .id(game.id).transition(.opacity)
+ }
+ .animation(.easeInOut(duration: 0.15), value: game.id)
.padding(.horizontal, inset)
- .frame(minHeight: compact ? 165 : size.height < 900 ? 140 : 195, alignment: .bottomLeading)
+ .frame(height: compact ? 175 : 100 + 2.4 * min(64, size.width / 24), alignment: .bottomLeading)
}
gameRow(size: size, compact: compact, inset: inset)
}
@@ -159,7 +169,6 @@ enum ConsoleInput {
Spacer(minLength: 0)
ConsoleControllerChips(controllers: state.controllers, merged: state.padMerge, lang: lang, compact: compact) { driver.openControllers() }
.frame(maxWidth: CGFloat(max(1, state.controllers.count)) * (compact ? 120 : 150))
- ConsoleGlyphView(glyph: glyphs.glyph(for: .controllers), size: compact ? 18 : 22).foregroundStyle(.white.opacity(0.6)) // the button that opens the Controllers sheet
Text(state.time, style: .time).font(.manrope(compact ? 17 : 22, .medium)).monospacedDigit()
.foregroundStyle(.white.opacity(0.65)).fixedSize()
}
@@ -167,7 +176,7 @@ enum ConsoleInput {
}
private func gameRow(size: CGSize, compact: Bool, inset: CGFloat) -> some View {
- let width: CGFloat = compact ? size.width - 70 : min(470, size.width * 0.32)
+ let width: CGFloat = compact ? size.width - inset * 2 - 16 : min(470, size.width * 0.32)
return ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: compact ? 22 : 28) {
@@ -177,19 +186,22 @@ enum ConsoleInput {
ConsoleGameTile(game: game, selected: selected, compact: compact, lang: lang)
.frame(width: width)
.scaleEffect(selected && !reduceMotion ? 1.025 : 1)
+ .animation(.easeOut(duration: 0.15), value: selected)
.contentShape(RoundedRectangle(cornerRadius: 18))
}
.buttonStyle(.plain)
- .padTarget("console.game." + game.id, scope: "console", radius: 18, activate: { driver.play(game.id) })
+ .padTarget("console.game." + game.id, scope: "console", radius: 16, activate: { driver.play(game.id) })
.accessibilityLabel(game.title + ", " + t(game.status.labelKey))
.accessibilityHint(t("console.playHint"))
.accessibilityAddTraits(selected ? .isSelected : [])
}
}
- .padding(.horizontal, inset).padding(.vertical, 12)
+ .padding(.horizontal, 8).padding(.vertical, 12) // room for the focused tile's small scale inside the clip
}
+ .padding(.horizontal, inset - 8) // the scroll area is the page margin, so tiles clip there and the title lines up with the first tile
.onChange(of: state.focusedGame?.id) { id in
- if let id { withAnimation(.easeOut(duration: reduceMotion ? 0 : 0.22)) { proxy.scrollTo("console.game." + id, anchor: .center) } }
+ // a new focus replaces the running scroll, it does not queue
+ if let id { withAnimation(.easeInOut(duration: reduceMotion ? 0 : 0.25)) { proxy.scrollTo("console.game." + id, anchor: .center) } }
}
.onAppear { if let id = state.focusedGame?.id { proxy.scrollTo("console.game." + id, anchor: .center) } }
}
diff --git a/frontend/Sources/NSPortBuilder/Gamepad.swift b/frontend/Sources/NSPortBuilder/Gamepad.swift
index 4de3dbf7..30368cb7 100644
--- a/frontend/Sources/NSPortBuilder/Gamepad.swift
+++ b/frontend/Sources/NSPortBuilder/Gamepad.swift
@@ -2,9 +2,11 @@ import AppKit
import GameController
/// A game controller drives the launcher, so a Mac on a TV needs no keyboard (PadFocus moves the focus). The buttons are
-/// named as the game names them, by position (dm/host/front_mac.m pad_read): A on the right, B at the bottom, X at the
-/// top, Y on the left. The D-pad or left stick moves (held, it repeats), A activates, B goes back, X opens the selected
-/// game's launch options, L and R switch the pages. Input counts only while the launcher is the active app: a game it
+/// named by what is printed on them, which is how GameController reports them (see `face`): the A button activates, B goes
+/// back, X opens the selected game's launch options and Y opens the Manage menu. On an Xbox or PlayStation controller A is the
+/// bottom button (the cross), on a Nintendo-layout controller it is the one on the right, as its player expects. This is the
+/// menus only: what a game receives is the Controls page's layout (By label or By position, #70), which this does not change.
+/// The D-pad or left stick moves (held, it repeats), L and R switch the pages. Input counts only while the launcher is the active app: a game it
/// started is in front then, and GameController gives a controller's input to the app in front, so the launcher never
/// acts behind a running game.
final class LauncherGamepad: ObservableObject {
@@ -12,6 +14,20 @@ final class LauncherGamepad: ObservableObject {
@Published private(set) var connected = false
var perform: (Action) -> Void = { _ in }
+ /// The GameController button an action reads, in one place (the glyphs of the console mode follow it). GameController names
+ /// the face buttons by label: buttonA is the bottom of Apple's diamond (GCExtendedGamepad.h), which is A on an Xbox
+ /// controller and the cross on a DualSense, and a Nintendo-layout controller reports the button printed A (on the right) as
+ /// buttonA too (seedds/nxnative#382). So one mapping gives every family its own confirm button.
+ enum Face { case a, b, x, y }
+ static func face(for action: Action) -> Face? {
+ switch action {
+ case .a: return .a
+ case .b: return .b
+ case .x: return .x
+ case .y: return .y
+ default: return nil
+ }
+ }
private var held: Set<String> = [] // edges, not levels: one press, one action
private var observers: [NSObjectProtocol] = []
private var repeatTimer: Timer?
@@ -38,8 +54,8 @@ final class LauncherGamepad: ObservableObject {
let y = pad.dpad.yAxis.value != 0 ? pad.dpad.yAxis.value : pad.leftThumbstick.yAxis.value
let state: [(String, Bool, Action)] = [
("left", x < -0.5, .left), ("right", x > 0.5, .right), ("up", y > 0.5, .up), ("down", y < -0.5, .down),
- ("a", pad.buttonB.isPressed, .a), ("b", pad.buttonA.isPressed, .b), // by position: right A, bottom B, top X, left Y
- ("x", pad.buttonY.isPressed, .x), ("y", pad.buttonX.isPressed, .y),
+ ("a", pad.buttonA.isPressed, .a), ("b", pad.buttonB.isPressed, .b), // by label, see `face`
+ ("x", pad.buttonX.isPressed, .x), ("y", pad.buttonY.isPressed, .y),
("l", pad.leftShoulder.isPressed, .l), ("r", pad.rightShoulder.isPressed, .r),
("plus", pad.buttonMenu.isPressed, .plus), // the console mode's options; the desktop ignores it
]
diff --git a/frontend/Sources/NSPortBuilder/PadFocus.swift b/frontend/Sources/NSPortBuilder/PadFocus.swift
index 27ed677b..0498b9d5 100644
--- a/frontend/Sources/NSPortBuilder/PadFocus.swift
+++ b/frontend/Sources/NSPortBuilder/PadFocus.swift
@@ -80,16 +80,28 @@ extension View {
}
}
+/// How the focus ring sits on a control. The desktop launcher draws it 4 points outside. The console mode draws it on the
+/// control's own edge, in the control's own shape (`radius`), so there is no gap and layout never changes with focus.
+enum PadRingStyle { case outset, hug }
+private struct PadRingStyleKey: EnvironmentKey { static let defaultValue = PadRingStyle.outset }
+extension EnvironmentValues {
+ var padRingStyle: PadRingStyle {
+ get { self[PadRingStyleKey.self] }
+ set { self[PadRingStyleKey.self] = newValue }
+ }
+}
+
private struct PadTargetModifier: ViewModifier {
let id: String, scope: String, radius: CGFloat
let handlers: PadFocus.Handlers
@EnvironmentObject private var focus: PadFocus
+ @Environment(\.padRingStyle) private var ringStyle
func body(content: Content) -> some View {
focus.register(id, handlers)
let on = focus.visible && focus.focused == id
return content
- .overlay(RoundedRectangle(cornerRadius: radius).strokeBorder(LauncherPalette.cream, lineWidth: on ? 2 : 0).padding(-4).allowsHitTesting(false))
+ .overlay(RoundedRectangle(cornerRadius: radius).strokeBorder(LauncherPalette.cream, lineWidth: on ? 2 : 0).padding(ringStyle == .hug ? 0 : -4).allowsHitTesting(false))
.background(GeometryReader { g in
Color.clear.preference(key: PadTargetKey.self, value: [.init(id: id, frame: g.frame(in: .named("pad." + scope)))])
})
diff --git a/frontend/Tests/NSPortBuilderTests/ConsolePadTests.swift b/frontend/Tests/NSPortBuilderTests/ConsolePadTests.swift
index f6cbf6ed..6c6a9818 100644
--- a/frontend/Tests/NSPortBuilderTests/ConsolePadTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ConsolePadTests.swift
@@ -95,7 +95,7 @@ final class ConsolePadTests: XCTestCase {
let repo = BuildModel.findRepo()
for (sizeName, width, height) in [("1920", CGFloat(1920), CGFloat(1080)), ("compact", 390, 844)] {
for (name, scenario, family) in [("home", MockConsoleDriver.Scenario.full, ConsoleGlyphs.Family.xbox), ("home-dualsense", .full, .playStation),
- ("controllers", .controllersMixed, .xbox), ("options", .full, .xbox), ("empty", .empty, .xbox)] {
+ ("controllers", .controllersMixed, .xbox), ("options", .full, .xbox), ("empty", .empty, .xbox), ("starting", .starting, .xbox)] {
let driver = MockConsoleDriver(scenario: scenario, lang: .en, animated: false, artworkRepo: repo.isEmpty ? nil : repo)
if name == "options" { driver.openOptions("demo.0") }
let host = NSHostingView(rootView: ConsoleView(driver: driver, lang: .en, glyphs: .init(family: family)).transaction { $0.disablesAnimations = true }.frame(width: width, height: height))
@@ -121,33 +121,55 @@ final class ConsolePadTests: XCTestCase {
for (category, family) in cases { XCTAssertEqual(ConsoleGlyphs.Family(category: category), family, category ?? "nil") }
}
- /// Actions resolve to the physical buttons Gamepad.swift reads (east confirms, south backs out, menu opens options, west opens
- /// Controllers), then to what the controller prints there.
+ /// Actions resolve to GameController's elements (A confirms, B backs out, Y opens Controllers, menu opens options), then to
+ /// what the controller prints there. On a DualSense A is the cross, B the circle and Y the triangle.
func testGlyphsFollowTheControllerInUse() {
- XCTAssertEqual(ConsoleGlyphs.Role.activate.element, .east)
- XCTAssertEqual(ConsoleGlyphs.Role.back.element, .south)
+ XCTAssertEqual(ConsoleGlyphs.Role.activate.element, .a)
+ XCTAssertEqual(ConsoleGlyphs.Role.back.element, .b)
XCTAssertEqual(ConsoleGlyphs.Role.options.element, .menu)
- XCTAssertEqual(ConsoleGlyphs.Role.controllers.element, .west)
+ XCTAssertEqual(ConsoleGlyphs.Role.controllers.element, .y)
let xbox = ConsoleGlyphs(family: .xbox)
- XCTAssertEqual(xbox.glyph(for: .activate), .symbol("b.circle"), "Xbox: the east button reads B")
- XCTAssertEqual(xbox.glyph(for: .back), .symbol("a.circle"))
+ XCTAssertEqual(xbox.glyph(for: .activate), .symbol("a.circle"))
+ XCTAssertEqual(xbox.glyph(for: .back), .symbol("b.circle"))
+ XCTAssertEqual(xbox.glyph(for: .controllers), .symbol("y.circle"))
let ps = ConsoleGlyphs(family: .playStation)
- XCTAssertEqual(ps.glyph(for: .activate), .symbol("circle.circle"))
- XCTAssertEqual(ps.glyph(for: .back), .symbol("xmark.circle"))
- XCTAssertEqual(ps.glyph(for: .controllers), .symbol("square.circle"))
+ XCTAssertEqual(ps.glyph(for: .activate), .symbol("xmark.circle"), "Play is the cross")
+ XCTAssertEqual(ps.glyph(for: .back), .symbol("circle.circle"), "Back is the circle")
+ XCTAssertEqual(ps.glyph(for: .controllers), .symbol("triangle.circle"), "Controllers is the triangle")
let nintendo = ConsoleGlyphs(family: .nintendo)
XCTAssertEqual(nintendo.glyph(for: .activate), .symbol("a.circle"))
+ XCTAssertEqual(nintendo.glyph(for: .controllers), .symbol("y.circle"))
XCTAssertEqual(nintendo.glyph(for: .options), .symbol("plus.circle"))
}
func testReportedSymbolWinsAndFallbacksAreNeutral() {
- let reported = ConsoleGlyphs(family: .xbox, reported: [.east: "custom.symbol"])
+ let reported = ConsoleGlyphs(family: .xbox, reported: [.a: "custom.symbol"])
XCTAssertEqual(reported.glyph(for: .activate), .symbol("custom.symbol"))
- XCTAssertEqual(reported.glyph(for: .back), .symbol("a.circle"), "an element it does not report uses the family table")
+ XCTAssertEqual(reported.glyph(for: .back), .symbol("b.circle"), "an element it does not report uses the family table")
XCTAssertEqual(ConsoleGlyphs.neutral.glyph(for: .activate), .letter("A"))
XCTAssertEqual(ConsoleGlyphs.neutral.glyph(for: .options), .letter("+"))
XCTAssertEqual(ConsoleGlyphs.keyboard.glyph(for: .activate), .key("Return"))
XCTAssertEqual(ConsoleGlyphs.keyboard.glyph(for: .back), .key("Esc"))
- XCTAssertEqual(ConsoleGlyphs(family: .keyboard, reported: [.east: "x"]).glyph(for: .activate), .key("Return"))
+ XCTAssertEqual(ConsoleGlyphs(family: .keyboard, reported: [.a: "x"]).glyph(for: .activate), .key("Return"))
+ }
+
+ /// One mapping serves every family: GameController reports Xbox and PlayStation buttons by position (A is the bottom button,
+ /// the cross) and a Nintendo-layout controller by its printed label (A on the right). The glyph is that same element.
+ func testConfirmAndBackFollowTheLabelOnEveryFamily() {
+ XCTAssertEqual(LauncherGamepad.face(for: .a), .a)
+ XCTAssertEqual(LauncherGamepad.face(for: .b), .b)
+ XCTAssertEqual(LauncherGamepad.face(for: .x), .x)
+ XCTAssertEqual(LauncherGamepad.face(for: .y), .y)
+ XCTAssertNil(LauncherGamepad.face(for: .left))
+ XCTAssertNil(LauncherGamepad.face(for: .l))
+ for family in [ConsoleGlyphs.Family.xbox, .playStation, .nintendo] {
+ let glyphs = ConsoleGlyphs(family: family)
+ guard case .symbol(let confirm) = glyphs.glyph(for: .activate), case .symbol(let back) = glyphs.glyph(for: .back) else { return XCTFail("\(family)") }
+ XCTAssertEqual(confirm, ConsoleGlyphs.table(family)[.a], "\(family)")
+ XCTAssertEqual(back, ConsoleGlyphs.table(family)[.b], "\(family)")
+ }
+ // Nintendo layout: Play shows A and Back shows B (not B and A)
+ XCTAssertEqual(ConsoleGlyphs(family: .nintendo).glyph(for: .activate), .symbol("a.circle"))
+ XCTAssertEqual(ConsoleGlyphs(family: .nintendo).glyph(for: .back), .symbol("b.circle"))
}
}