-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 92cb96d
Showing
15 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# .github/workflows/build-documentation.yml | ||
|
||
name: build-documentation | ||
|
||
on: | ||
# Run on push to main branch | ||
push: | ||
branches: | ||
- main | ||
|
||
# Dispatch if triggered using Github (website) | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Build-documentation: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Build documentation | ||
uses: 0xWDG/build-documentation@main |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# .github/workflows/build-multiplatform.yml | ||
|
||
name: Build-Packages | ||
|
||
on: | ||
# Run on pull_request | ||
pull_request: | ||
|
||
# Dispatch if triggered using Github (website) | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Build-Packages: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Build Swift Packages | ||
uses: 0xWDG/build-swift@main |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Run Swiftlint | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
swiftlint: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: SwiftLint | ||
run: | | ||
brew install swiftlint | ||
swiftlint --reporter github-actions-logging --strict |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run tests on Linux and macOS | ||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_linux: | ||
if: false | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Swift test | ||
run: swift test | ||
|
||
test_macos: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Swift test | ||
run: swift test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## User settings | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
build/ | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
### Swift Package Manager | ||
Packages/ | ||
Package.pins | ||
Package.resolved | ||
# *.xcodeproj | ||
# | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
.swiftpm | ||
.build/ | ||
|
||
### CocoaPods | ||
Pods/ | ||
*.xcworkspace | ||
|
||
### Carthage | ||
Carthage/Checkouts | ||
Carthage/Build/ | ||
|
||
### Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
### fastlane | ||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
### Code Injection | ||
iOSInjectionProject/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: 1 | ||
builder: | ||
configs: | ||
- documentation_targets: [GameControllerKit] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
excluded: | ||
- "*resource_bundle_accessor*" # SwiftPM Generated | ||
- ".build/*" | ||
|
||
opt_in_rules: | ||
- missing_docs | ||
- empty_count | ||
- empty_string | ||
- toggle_bool | ||
- unused_optional_binding | ||
- valid_ibinspectable | ||
- modifier_order | ||
- first_where | ||
- fatal_error_message | ||
- force_unwrapping | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Wesley de Groot, [email protected] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// swift-tools-version: 5.8.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "GameControllerKit", | ||
platforms: [ | ||
.macOS(.v12), | ||
.iOS(.v16), | ||
.tvOS(.v16) | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, making them visible to other packages. | ||
.library( | ||
name: "GameControllerKit", | ||
targets: ["GameControllerKit"]) | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.target( | ||
name: "GameControllerKit"), | ||
.testTarget( | ||
name: "GameControllerKitTests", | ||
dependencies: ["GameControllerKit"]) | ||
] | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# GameControllerKit | ||
|
||
GameControllerKit is a Swift package that makes it easy to work with game controllers on iOS, macOS, and tvOS. It provides a simple API to connect to game controllers, read input from them, and control their lights and haptics. | ||
|
||
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FGameControllerKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/0xWDG/GameControllerKit) | ||
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FGameControllerKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/0xWDG/GameControllerKit) | ||
[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager) | ||
![License](https://img.shields.io/github/license/0xWDG/GameControllerKit) | ||
|
||
## Requirements | ||
|
||
- Swift 5.9+ (Xcode 15+) | ||
- iOS 13+, macOS 10.15+, tvOS 16+ | ||
|
||
## Installation (Pakage.swift) | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/0xWDG/GameControllerKit.git", branch: "main"), | ||
], | ||
targets: [ | ||
.target(name: "MyTarget", dependencies: [ | ||
.product(name: "GameControllerKit", package: "GameControllerKit"), | ||
]), | ||
] | ||
``` | ||
|
||
## Installation (Xcode) | ||
|
||
1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...** | ||
2. Paste the repository URL (`https://github.com/0xWDG/GameControllerKit`) and click **Next**. | ||
3. Click **Finish**. | ||
|
||
## Usage | ||
|
||
```swift | ||
import SwiftUI | ||
import GameControllerKit | ||
|
||
|
||
struct ContentView: View { | ||
@State var gameController = GameControllerKit() | ||
|
||
@State var log: [String] = [] | ||
|
||
func handler(action: GCKAction, pressed: Bool) { | ||
log.append( | ||
"\(String(describing: action)), \(pressed ? "Pressed" : "Unpressed")" | ||
) | ||
|
||
if action == .buttonA && pressed { | ||
// When pressed on A or X (on PlayStation controllers), set the color to a random color. | ||
// Colors are only supported on controllers that have a light, like DualShock and Dualsense controllers. | ||
gameController.set(color: .GCKRandom) | ||
} | ||
|
||
if case .rightThumbstick = action { | ||
log.append("Right thumbstick: " + | ||
String( | ||
describing: gameController.translate( | ||
action: action | ||
) | ||
) | ||
) | ||
} | ||
|
||
if case .leftThumbstick = action { | ||
log.append("Left thumbstick: " + | ||
String( | ||
describing: gameController.translate( | ||
action: action | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
Button { | ||
gameController.set(color: .GCKRandom) | ||
} label: { | ||
Text("Random Color") | ||
} | ||
|
||
Text("Controller: \(gameController.controller?.productCategory ?? "None"), \((gameController.controllerType ?? .generic).description)") | ||
Text("Left: \(String(describing: gameController.leftThumbstick))") | ||
Text("Right: \(String(describing: gameController.rightThumbstick)).") | ||
Text("Last action: \(String(describing: gameController.lastAction)).") | ||
|
||
List { | ||
ForEach(log.reversed(), id: \.self) { text in | ||
Text(text) | ||
} | ||
} | ||
} | ||
.padding() | ||
.onAppear { | ||
gameController.set(handler: handler) | ||
UIApplication.shared.isIdleTimerDisabled = true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Contact | ||
|
||
We can get in touch via [Mastodon](https://mastodon.social/@0xWDG), [Twitter/X](https://twitter.com/0xWDG), [Discord](https://discordapp.com/users/918438083861573692), [Email](mailto:[email protected]), [Website](https://wesleydegroot.nl). | ||
|
||
Interested learning more about Swift? [Check out my blog](https://wesleydegroot.nl/blog/). |
Oops, something went wrong.