Skip to content

Commit

Permalink
fix: Support non-extended gamepads and virtual controllers (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsci authored Feb 20, 2024
1 parent 7bc6c13 commit 20c5c06
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions OpoLua/View Controllers/ProgramViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,21 @@ class ProgramViewController: UIViewController {

func configureControllers() {
for controller in GCController.controllers() {
controller.extendedGamepad?.buttonHome?.pressedChangedHandler = self.pressedChangeHandler(for: .home)
controller.extendedGamepad?.buttonA.pressedChangedHandler = self.pressedChangeHandler(for: .a)
controller.extendedGamepad?.buttonB.pressedChangedHandler = self.pressedChangeHandler(for: .b)
controller.extendedGamepad?.dpad.up.pressedChangedHandler = self.pressedChangeHandler(for: .up)
controller.extendedGamepad?.dpad.down.pressedChangedHandler = self.pressedChangeHandler(for: .down)
controller.extendedGamepad?.dpad.left.pressedChangedHandler = self.pressedChangeHandler(for: .left)
controller.extendedGamepad?.dpad.right.pressedChangedHandler = self.pressedChangeHandler(for: .right)
controller.extendedGamepad?.leftThumbstick.up.pressedChangedHandler = self.pressedChangeHandler(for: .up)
controller.extendedGamepad?.leftThumbstick.down.pressedChangedHandler = self.pressedChangeHandler(for: .down)
controller.extendedGamepad?.leftThumbstick.left.pressedChangedHandler = self.pressedChangeHandler(for: .left)
controller.extendedGamepad?.leftThumbstick.right.pressedChangedHandler = self.pressedChangeHandler(for: .right)
controller.extendedGamepad?.buttonOptions?.pressedChangedHandler = self.pressedChangeHandler(for: .options)
controller.extendedGamepad?.buttonMenu.pressedChangedHandler = self.pressedChangeHandler(for: .menu)
let input = controller.physicalInputProfile

for dpad in input.allDpads {
dpad.left.pressedChangedHandler = self.pressedChangeHandler(for: .left)
dpad.right.pressedChangedHandler = self.pressedChangeHandler(for: .right)
dpad.up.pressedChangedHandler = self.pressedChangeHandler(for: .up)
dpad.down.pressedChangedHandler = self.pressedChangeHandler(for: .down)
}

let buttons = input.buttons
buttons[GCInputButtonHome]?.pressedChangedHandler = self.pressedChangeHandler(for: .home)
buttons[GCInputButtonA]?.pressedChangedHandler = self.pressedChangeHandler(for: .a)
buttons[GCInputButtonB]?.pressedChangedHandler = self.pressedChangeHandler(for: .b)
buttons[GCInputButtonOptions]?.pressedChangedHandler = self.pressedChangeHandler(for: .options)
buttons[GCInputButtonMenu]?.pressedChangedHandler = self.pressedChangeHandler(for: .menu)
}
}

Expand Down Expand Up @@ -439,10 +441,7 @@ class ProgramViewController: UIViewController {
let configuration = GCVirtualController.Configuration()
configuration.elements = [GCInputButtonA,
GCInputButtonB,
GCInputDirectionPad,
GCInputDirectionPad,
GCInputButtonHome,
GCInputButtonOptions]
GCInputDirectionPad]
virtualController = GCVirtualController(configuration: configuration)
virtualController?.connect()
}
Expand Down

0 comments on commit 20c5c06

Please sign in to comment.