Skip to content

Latest commit

 

History

History
93 lines (78 loc) · 9.19 KB

README.md

File metadata and controls

93 lines (78 loc) · 9.19 KB

swift-version swift-package-manager platform ci-status license

GCOverseer 🎮

Combine wrapper around Apple's Game Controller Framework.

Tested Platforms

  • iOS 14+
  • macOS 11+ (BigSur+)
  • Mac Catalyst 14+
  • tvOS 14+
  • Xcode 12+
  • Swift 5.3+

Usage Examples

Handle Connected / Disconnected Events

import SpriteKit
import Combine
import GCOverseer

class GameScene: SKScene {

    let gcOverseer = GCOverseer()

    var cancellables = Set<AnyCancellable>()

    override init(size: CGSize) {
        super.init(size: size)

        // 🎮
        gcOverseer.$isGameControllerConnected
            .sink { isConnected in
                // Do something
            }
            .store(in: &cancellables)
    }
}

Available Properties

Property Description
@Published var isGameControllerConnected: Bool Subscribe to this variable to keep track of connect / disconnect events of game controllers.

Available APIs

API Description
controllers() Returns all controllers that are connected to the device. E.g. Dualshock, Xbox, Siri Remote controllers, etc.
extendedGamepadControllers() Returns all controllers supporting the extendedGamepad profile that are connected to the device. E.g. Dualshock, Xbox controllers, etc.
dualshockControllers() Returns all DualShock controllers that are connected to the device.
xboxControllers() Returns all Xbox controllers that are connected to the device.
microGamepadControllers() Returns all controllers supporting the microGamepad profile that are connected to the device. E.g. Apple's Siri Remote.
motionControllers() Returns all controllers supporting the motion profile that are connected to the device.
controllerFor(playerIndex:) Returns the controller for the player 1, player 2, etc.
enableLogging() / disableLogging() Enables / disables logging output.

Integration

Xcode

Use Xcode's built-in support for SPM.

or...

Package.swift

In your Package.swift, add GCOverseer as a dependency:

dependencies: [
    .package(
        url: "https://github.com/backslash-f/gcoverseer",
        .upToNextMajor(from: "1.0.0")
    )
]

Associate the dependency with your target:

targets: [
    .target(
        name: "YourTargetName",
        dependencies: [
            .product(
                name: "GCOverseer",
                package: "gcoverseer"
            )
        ]
    )
]

Run: swift build