Skip to content

Instantly share code, notes, and snippets.

@Plnda
Last active September 15, 2020 12:07
Show Gist options
  • Save Plnda/ad9038789894478ee32b9b827b35d15a to your computer and use it in GitHub Desktop.
Save Plnda/ad9038789894478ee32b9b827b35d15a to your computer and use it in GitHub Desktop.
Controller.swift
public struct Controller: Codable
{
let axes: [Double]
let buttons: [GamePadButton?]
let connected: Bool
let id: String
let index: Int
let mapping: String
let timestamp: Double
public var jsonString: String {
guard let data = try? JSONEncoder().encode(self) else {
return "{}"
}
return String(data: data, encoding: .utf8) ?? "{}"
}
}
public struct GamePadButton: Codable
{
let pressed: Bool
let value: Double
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment