Skip to content

Commit cbfa688

Browse files
committed
Add Famicom and SNES controller support
1 parent ecdd3fa commit cbfa688

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

JoyKeyMapper/DataModels/GameControllerIcon.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ let joyconRBase = NSImage(named: "joycon_right_base")!
2222
let joyconRBody = NSImage(named: "joycon_right_body")!
2323
let joyconRButton = NSImage(named: "joycon_right_button")!
2424

25+
let famicon_1 = NSImage(named: "famicon_1")!
26+
let famicon_2 = NSImage(named: "famicon_2")!
27+
let snescon = NSImage(named: "snescon")!
28+
2529
let unknownController = NSImage(named: "unknown_controller")!
2630

2731
let batteryFull = NSImage(named: "battery_full")!
@@ -41,6 +45,12 @@ func GameControllerIcon(for controller: GameController) -> NSImage {
4145
return createJoyConLIcon(for: controller)
4246
case .JoyConR:
4347
return createJoyConRIcon(for: controller)
48+
case .FamicomController1:
49+
return famicon_1
50+
case .FamicomController2:
51+
return famicon_2
52+
case .SNESController:
53+
return snescon
4454
default:
4555
return unknownController
4656
}

JoyKeyMapper/Views/KeyMapList/ViewController+NSOutlineViewDelegate.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ let buttonNames: [JoyCon.Button: String] = [
3131
.LeftSL: "Left SL",
3232
.LeftSR: "Left SR",
3333
.RightSL: "Right SL",
34-
.RightSR: "Right SR"
34+
.RightSR: "Right SR",
35+
.Start: "Start",
36+
.Select: "Select",
3537
]
3638
let directionNames: [JoyCon.StickDirection: String] = [
3739
.Up: "Up",
@@ -45,7 +47,18 @@ let rightStickName = NSLocalizedString("Right Stick", comment: "Right Stick")
4547
let controllerButtons: [JoyCon.ControllerType: [JoyCon.Button]] = [
4648
.JoyConL: [.Up, .Right, .Down, .Left, .LeftSL, .LeftSR, .L, .ZL, .Minus, .Capture, .LStick],
4749
.JoyConR: [.A, .B, .X, .Y, .RightSL, .RightSR, .R, .ZR, .Plus, .Home, .RStick],
48-
.ProController: [.A, .B, .X, .Y, .L, .ZL, .R, .ZR, .Up, .Right, .Down, .Left, .Minus, .Plus, .Capture, .Home, .LStick, .RStick]
50+
.ProController: [.A, .B, .X, .Y, .L, .ZL, .R, .ZR, .Up, .Right, .Down, .Left, .Minus, .Plus, .Capture, .Home, .LStick, .RStick],
51+
.FamicomController1: [.A, .B, .L, .R, .Up, .Right, .Down, .Left, .Start, .Select],
52+
.FamicomController2: [.A, .B, .L, .R, .Up, .Right, .Down, .Left],
53+
.SNESController: [.A, .B, .X, .Y, .L, .ZL, .R, .ZR, .Up, .Right, .Down, .Left, .Start, .Select],
54+
]
55+
let numSticks: [JoyCon.ControllerType: Int] = [
56+
.JoyConL: 1,
57+
.JoyConR: 1,
58+
.ProController: 2,
59+
.FamicomController1: 0,
60+
.FamicomController2: 0,
61+
.SNESController: 0
4962
]
5063
let stickerDirections: [JoyCon.StickDirection] = [
5164
.Up, .Right, .Down, .Left
@@ -87,6 +100,10 @@ extension ViewController: NSOutlineViewDelegate, NSOutlineViewDataSource, KeyCon
87100
guard let buttons = controllerButtons[controller.type] else { return 0 }
88101
guard let config = self.selectedKeyConfig else { return 0 }
89102

103+
if controller.type == .unknown {
104+
return 0
105+
}
106+
90107
if let indexOfItem = item as? Int {
91108
let stickIndex = indexOfItem - buttons.count
92109

@@ -111,13 +128,7 @@ extension ViewController: NSOutlineViewDelegate, NSOutlineViewDataSource, KeyCon
111128
return 0
112129
}
113130

114-
if controller.type == .JoyConL || controller.type == .JoyConR {
115-
return buttons.count + 1
116-
}
117-
if controller.type == .ProController {
118-
return buttons.count + 2
119-
}
120-
return 0
131+
return buttons.count + (numSticks[controller.type] ?? 0)
121132
}
122133

123134
func numberOfChildItemOfStick(for type: String?) -> Int {

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ target 'JoyKeyMapper' do
66
use_frameworks!
77

88
# Pods for JoyKeyMapper
9-
pod 'JoyConSwift', '0.1.2'
9+
pod 'JoyConSwift', '0.2.1'
1010

1111
end

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
PODS:
2-
- JoyConSwift (0.1.2)
2+
- JoyConSwift (0.2.1)
33

44
DEPENDENCIES:
5-
- JoyConSwift (= 0.1.2)
5+
- JoyConSwift (= 0.2.1)
66

77
SPEC REPOS:
88
trunk:
99
- JoyConSwift
1010

1111
SPEC CHECKSUMS:
12-
JoyConSwift: 925e59c82d91ddf5381079612a84741f40cc1ecd
12+
JoyConSwift: a8025cc234394cbc38fc1b48cfe1de8de6f66551
1313

14-
PODFILE CHECKSUM: e982e7c0dcf71eb98d451ee7e1bc5b7d358a6dc4
14+
PODFILE CHECKSUM: f077d9a7d63235de745659f9e64c4c8ec6de86af
1515

1616
COCOAPODS: 1.9.3

0 commit comments

Comments
 (0)