backslash-f / gcoverseer

Observe and manage game controllers using Combine ๐ŸŽฎ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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", from: "0.1.0")
],

Associate the dependency with your target:

targets: [
  .target(name: "App", dependencies: ["GCOverseer"])
]

Run: swift build

About

Observe and manage game controllers using Combine ๐ŸŽฎ

License:MIT License


Languages

Language:Swift 100.0%