Skip to content

Commit 92cb96d

Browse files
committed
Initial commit
0 parents  commit 92cb96d

File tree

15 files changed

+884
-0
lines changed

15 files changed

+884
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# .github/workflows/build-documentation.yml
2+
3+
name: build-documentation
4+
5+
on:
6+
# Run on push to main branch
7+
push:
8+
branches:
9+
- main
10+
11+
# Dispatch if triggered using Github (website)
12+
workflow_dispatch:
13+
14+
jobs:
15+
Build-documentation:
16+
runs-on: macos-latest
17+
steps:
18+
- name: Build documentation
19+
uses: 0xWDG/build-documentation@main
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# .github/workflows/build-multiplatform.yml
2+
3+
name: Build-Packages
4+
5+
on:
6+
# Run on pull_request
7+
pull_request:
8+
9+
# Dispatch if triggered using Github (website)
10+
workflow_dispatch:
11+
12+
jobs:
13+
Build-Packages:
14+
runs-on: macos-latest
15+
steps:
16+
- name: Build Swift Packages
17+
uses: 0xWDG/build-swift@main

.github/workflows/swiftlint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Run Swiftlint
2+
on:
3+
push:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
swiftlint:
9+
runs-on: macos-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: SwiftLint
14+
run: |
15+
brew install swiftlint
16+
swiftlint --reporter github-actions-logging --strict

.github/workflows/tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Run tests on Linux and macOS
2+
on:
3+
push:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test_linux:
8+
if: false
9+
runs-on: ubuntu-latest
10+
continue-on-error: true
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Swift test
15+
run: swift test
16+
17+
test_macos:
18+
runs-on: macos-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Swift test
23+
run: swift test

.gitignore

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## User settings
2+
xcuserdata/
3+
4+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
5+
*.xcscmblueprint
6+
*.xccheckout
7+
8+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
9+
build/
10+
DerivedData/
11+
*.moved-aside
12+
*.pbxuser
13+
!default.pbxuser
14+
*.mode1v3
15+
!default.mode1v3
16+
*.mode2v3
17+
!default.mode2v3
18+
*.perspectivev3
19+
!default.perspectivev3
20+
21+
## Obj-C/Swift specific
22+
*.hmap
23+
24+
## App packaging
25+
*.ipa
26+
*.dSYM.zip
27+
*.dSYM
28+
29+
## Playgrounds
30+
timeline.xctimeline
31+
playground.xcworkspace
32+
33+
### Swift Package Manager
34+
Packages/
35+
Package.pins
36+
Package.resolved
37+
# *.xcodeproj
38+
#
39+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
40+
# hence it is not needed unless you have added a package configuration file to your project
41+
.swiftpm
42+
.build/
43+
44+
### CocoaPods
45+
Pods/
46+
*.xcworkspace
47+
48+
### Carthage
49+
Carthage/Checkouts
50+
Carthage/Build/
51+
52+
### Accio dependency management
53+
Dependencies/
54+
.accio/
55+
56+
### fastlane
57+
fastlane/report.xml
58+
fastlane/Preview.html
59+
fastlane/screenshots/**/*.png
60+
fastlane/test_output
61+
62+
### Code Injection
63+
iOSInjectionProject/

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [GameControllerKit]

.swiftlint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
excluded:
2+
- "*resource_bundle_accessor*" # SwiftPM Generated
3+
- ".build/*"
4+
5+
opt_in_rules:
6+
- missing_docs
7+
- empty_count
8+
- empty_string
9+
- toggle_bool
10+
- unused_optional_binding
11+
- valid_ibinspectable
12+
- modifier_order
13+
- first_where
14+
- fatal_error_message
15+
- force_unwrapping
16+

LICENCE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Wesley de Groot, [email protected]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version: 5.8.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "GameControllerKit",
8+
platforms: [
9+
.macOS(.v12),
10+
.iOS(.v16),
11+
.tvOS(.v16)
12+
],
13+
products: [
14+
// Products define the executables and libraries a package produces, making them visible to other packages.
15+
.library(
16+
name: "GameControllerKit",
17+
targets: ["GameControllerKit"])
18+
],
19+
targets: [
20+
// Targets are the basic building blocks of a package, defining a module or a test suite.
21+
// Targets can depend on other targets in this package and products from dependencies.
22+
.target(
23+
name: "GameControllerKit"),
24+
.testTarget(
25+
name: "GameControllerKitTests",
26+
dependencies: ["GameControllerKit"])
27+
]
28+
)

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# GameControllerKit
2+
3+
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.
4+
5+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FGameControllerKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/0xWDG/GameControllerKit)
6+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FGameControllerKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/0xWDG/GameControllerKit)
7+
[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager)
8+
![License](https://img.shields.io/github/license/0xWDG/GameControllerKit)
9+
10+
## Requirements
11+
12+
- Swift 5.9+ (Xcode 15+)
13+
- iOS 13+, macOS 10.15+, tvOS 16+
14+
15+
## Installation (Pakage.swift)
16+
17+
```swift
18+
dependencies: [
19+
.package(url: "https://github.com/0xWDG/GameControllerKit.git", branch: "main"),
20+
],
21+
targets: [
22+
.target(name: "MyTarget", dependencies: [
23+
.product(name: "GameControllerKit", package: "GameControllerKit"),
24+
]),
25+
]
26+
```
27+
28+
## Installation (Xcode)
29+
30+
1. In Xcode, open your project and navigate to **File****Swift Packages****Add Package Dependency...**
31+
2. Paste the repository URL (`https://github.com/0xWDG/GameControllerKit`) and click **Next**.
32+
3. Click **Finish**.
33+
34+
## Usage
35+
36+
```swift
37+
import SwiftUI
38+
import GameControllerKit
39+
40+
41+
struct ContentView: View {
42+
@State var gameController = GameControllerKit()
43+
44+
@State var log: [String] = []
45+
46+
func handler(action: GCKAction, pressed: Bool) {
47+
log.append(
48+
"\(String(describing: action)), \(pressed ? "Pressed" : "Unpressed")"
49+
)
50+
51+
if action == .buttonA && pressed {
52+
// When pressed on A or X (on PlayStation controllers), set the color to a random color.
53+
// Colors are only supported on controllers that have a light, like DualShock and Dualsense controllers.
54+
gameController.set(color: .GCKRandom)
55+
}
56+
57+
if case .rightThumbstick = action {
58+
log.append("Right thumbstick: " +
59+
String(
60+
describing: gameController.translate(
61+
action: action
62+
)
63+
)
64+
)
65+
}
66+
67+
if case .leftThumbstick = action {
68+
log.append("Left thumbstick: " +
69+
String(
70+
describing: gameController.translate(
71+
action: action
72+
)
73+
)
74+
)
75+
}
76+
}
77+
78+
var body: some View {
79+
VStack {
80+
Button {
81+
gameController.set(color: .GCKRandom)
82+
} label: {
83+
Text("Random Color")
84+
}
85+
86+
Text("Controller: \(gameController.controller?.productCategory ?? "None"), \((gameController.controllerType ?? .generic).description)")
87+
Text("Left: \(String(describing: gameController.leftThumbstick))")
88+
Text("Right: \(String(describing: gameController.rightThumbstick)).")
89+
Text("Last action: \(String(describing: gameController.lastAction)).")
90+
91+
List {
92+
ForEach(log.reversed(), id: \.self) { text in
93+
Text(text)
94+
}
95+
}
96+
}
97+
.padding()
98+
.onAppear {
99+
gameController.set(handler: handler)
100+
UIApplication.shared.isIdleTimerDisabled = true
101+
}
102+
}
103+
}
104+
```
105+
106+
## Contact
107+
108+
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).
109+
110+
Interested learning more about Swift? [Check out my blog](https://wesleydegroot.nl/blog/).

0 commit comments

Comments
 (0)