Created
September 15, 2020 11:33
-
-
Save Plnda/70fd5724a2329a5a61c711a668374bd9 to your computer and use it in GitHub Desktop.
controllerData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var controllerData: String { | |
guard let controller = GCController.controllers().first, | |
let gamepad = controller.extendedGamepad, | |
let buttonOptions = gamepad.buttonOptions, | |
let buttonHome = gamepad.buttonHome, | |
let leftThumbstickButton = gamepad.leftThumbstickButton, | |
let rightThumbstickButton = gamepad.rightThumbstickButton else { | |
return "" | |
} | |
let customController = Controller( | |
axes: [ | |
Double(gamepad.leftThumbstick.xAxis.value), | |
Double(-1.0 * gamepad.leftThumbstick.yAxis.value), | |
Double(gamepad.rightThumbstick.xAxis.value), | |
Double(-1.0 * gamepad.rightThumbstick.yAxis.value) | |
], | |
buttons: [ | |
GamePadButton(pressed: gamepad.buttonA.isPressed, value: Double(gamepad.buttonA.value)), | |
GamePadButton(pressed: gamepad.buttonB.isPressed, value: Double(gamepad.buttonB.value)), | |
GamePadButton(pressed: gamepad.buttonX.isPressed, value: Double(gamepad.buttonX.value)), | |
GamePadButton(pressed: gamepad.buttonY.isPressed, value: Double(gamepad.buttonY.value)), | |
GamePadButton(pressed: gamepad.leftShoulder.isPressed, value: Double(gamepad.leftShoulder.value)), | |
GamePadButton(pressed: gamepad.rightShoulder.isPressed, value: Double(gamepad.rightShoulder.value)), | |
GamePadButton(pressed: gamepad.leftTrigger.isPressed, value: Double(gamepad.leftTrigger.value)), | |
GamePadButton(pressed: gamepad.rightTrigger.isPressed, value: Double(gamepad.rightTrigger.value)), | |
GamePadButton(pressed: buttonOptions.isPressed, value: Double(buttonOptions.value)), | |
GamePadButton(pressed: gamepad.buttonMenu.isPressed, value: Double(gamepad.buttonMenu.value)), | |
GamePadButton(pressed: leftThumbstickButton.isPressed, value: Double(leftThumbstickButton.value)), | |
GamePadButton(pressed: rightThumbstickButton.isPressed, value: Double(rightThumbstickButton.value)), | |
GamePadButton(pressed: gamepad.dpad.up.isPressed, value: Double(gamepad.dpad.up.value)), | |
GamePadButton(pressed: gamepad.dpad.down.isPressed, value: Double(gamepad.dpad.down.value)), | |
GamePadButton(pressed: gamepad.dpad.left.isPressed, value: Double(gamepad.dpad.left.value)), | |
GamePadButton(pressed: gamepad.dpad.right.isPressed, value: Double(gamepad.dpad.right.value)), | |
GamePadButton(pressed: buttonHome.isPressed, value: Double(buttonHome.value)), | |
], | |
connected: true, | |
id: "Emulated iOS Controller", | |
index: 0, | |
mapping: "standard", | |
timestamp: 0) | |
return customController.jsonString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment