Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

+54 -4
View File
@@ -35,6 +35,24 @@ struct InputSettings: Codable, Equatable {
get { port == 0 ? right : left }
set { if port == 0 { right = newValue } else { left = newValue } }
}
/// An unassigned Controller source can adopt an unambiguous connection.
/// A remembered device remains authoritative even while disconnected.
static var freshDefaults: Self {
var value = Self(); value.right.source = .mouse
return value
}
func assigningSoleController(_ deviceIDs: [String], automaticRight: Bool = false) -> Self {
guard deviceIDs.count == 1, let device = deviceIDs.first,
!device.isEmpty, device.count < 1024 else { return self }
var result = self
if automaticRight, result.right.source == .mouse, result.right.device.isEmpty {
result.right.source = .controller
}
for port in 0..<2 where result[port].source == .controller && result[port].device.isEmpty {
result[port].device = device
}
return result
}
func validated() throws -> Self {
for p in [right, left] {
guard p.deadZone.isFinite, (0...0.5).contains(p.deadZone),
@@ -46,16 +64,48 @@ struct InputSettings: Codable, Equatable {
}
}
struct InputSettingsStore {
struct State {
let settings: InputSettings
let automaticRightController: Bool
}
/// Keep the existing flat settings document/profile contract. This optional
/// store-only marker distinguishes a fresh fallback from a person's choice.
private struct Record: Codable {
let settings: InputSettings
let automaticRightController: Bool
private enum Keys: String, CodingKey { case automaticRightController }
init(settings: InputSettings, automaticRightController: Bool) {
self.settings = settings; self.automaticRightController = automaticRightController
}
init(from decoder: Decoder) throws {
settings = try InputSettings(from: decoder)
automaticRightController = try decoder.container(keyedBy: Keys.self)
.decodeIfPresent(Bool.self, forKey: .automaticRightController) ?? false
}
func encode(to encoder: Encoder) throws {
try settings.encode(to: encoder)
if automaticRightController {
var fields = encoder.container(keyedBy: Keys.self)
try fields.encode(true, forKey: .automaticRightController)
}
}
}
let url: URL
static let standard = InputSettingsStore(url: AppIdentity.supportDirectory.appendingPathComponent("InputSettings.json"))
func load() throws -> InputSettings {
guard FileManager.default.fileExists(atPath: url.path) else { return InputSettings() }
return try JSONDecoder().decode(InputSettings.self, from: Data(contentsOf: url)).validated()
try loadState().settings
}
func save(_ value: InputSettings) throws {
func loadState() throws -> State {
guard FileManager.default.fileExists(atPath: url.path) else {
return State(settings: .freshDefaults, automaticRightController: true)
}
let record = try JSONDecoder().decode(Record.self, from: Data(contentsOf: url))
return State(settings: try record.settings.validated(), automaticRightController: record.automaticRightController)
}
func save(_ value: InputSettings, automaticRightController: Bool = false) throws {
_ = try value.validated()
try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
try JSONEncoder().encode(value).write(to: url, options: .atomic)
try JSONEncoder().encode(Record(settings: value, automaticRightController: automaticRightController)).write(to: url, options: .atomic)
}
}
struct JoystickSample: Equatable {