ObjFW  Diff

Differences From Artifact [50efe01c0d]:

To Artifact [70416dbdb2]:


16
17
18
19
20
21
22

23
24
25
26



27
28
29
30
31
32
33
34
35
36
37





38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54


55
56
57
58
59
60
61
62
63

64
65
66


67
68
69
70
71
72
73






74
75
76
77

78
79
80


81
82
83
84
85
86
87






88
89
90
91

92
93

94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109












110
111
112
113
114
115
116
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60



61
62
63
64
65
66
67
68
69
70

71



72
73







74
75
76
77
78
79
80
81
82

83



84
85







86
87
88
89
90
91
92
93
94

95


96



97
98













99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117







+




+
+
+











+
+
+
+
+













-
+
-
-
-
+
+








-
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+



-
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+



-
+
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







 * version 3.0 along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#import "OHNintendoSwitchExtendedGamepad.h"
#import "OHNintendoSwitchExtendedGamepad+Private.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerDirectionalPad+Private.h"
#import "OHGameControllerElement.h"
#import "OHGameControllerElement+Private.h"

static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Left Thumbstick",
	@"Right Thumbstick", @"+", @"-"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHNintendoSwitchExtendedGamepad
@synthesize buttons = _buttons, directionalPads = _directionalPads;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)oh_init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
		    [OFMutableDictionary dictionaryWithCapacity: numButtons];
		OFMutableDictionary *directionalPads;
		OHGameControllerAxis *xAxis, *yAxis;
		OHGameControllerDirectionalPad *directionalPad;
		OHGameControllerButton *up, *down, *left, *right;

		for (size_t i = 0; i < numButtons; i++) {
			OHGameControllerButton *button =
			OHGameControllerButton *button = [OHGameControllerButton
			    [[[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]
				  analog: false] autorelease];
			    oh_elementWithName: buttonNames[i]
					analog: false];
			[buttons setObject: button forKey: buttonNames[i]];
		}
		[buttons makeImmutable];
		_buttons = [buttons retain];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];

		xAxis = [[[OHGameControllerAxis alloc]
		xAxis = [OHGameControllerAxis oh_elementWithName: @"X"
		    initWithName: @"X"
			  analog: true] autorelease];
		yAxis = [[[OHGameControllerAxis alloc]
							  analog: true];
		yAxis = [OHGameControllerAxis oh_elementWithName: @"Y"
		    initWithName: @"Y"
			  analog: true] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"Left Thumbstick"
			   xAxis: xAxis
			   yAxis: yAxis
			  analog: true] autorelease];
							  analog: true];
		directionalPad = [OHGameControllerDirectionalPad
		    oh_padWithName: @"Left Thumbstick"
			     xAxis: xAxis
			     yAxis: yAxis
			    analog: true];
		[directionalPads setObject: directionalPad
				    forKey: @"Left Thumbstick"];

		xAxis = [[[OHGameControllerAxis alloc]
		xAxis = [OHGameControllerAxis oh_elementWithName: @"RX"
		    initWithName: @"RX"
			  analog: true] autorelease];
		yAxis = [[[OHGameControllerAxis alloc]
							  analog: true];
		yAxis = [OHGameControllerAxis oh_elementWithName: @"RY"
		    initWithName: @"RY"
			  analog: true] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"Right Thumbstick"
			   xAxis: xAxis
			   yAxis: yAxis
			  analog: true] autorelease];
							  analog: true];
		directionalPad = [OHGameControllerDirectionalPad
		    oh_padWithName: @"Right Thumbstick"
			     xAxis: xAxis
			     yAxis: yAxis
			    analog: true];
		[directionalPads setObject: directionalPad
				    forKey: @"Right Thumbstick"];

		up = [[[OHGameControllerButton alloc]
		up = [OHGameControllerButton oh_elementWithName: @"D-Pad Up"
		    initWithName: @"D-Pad Up"
			  analog: false] autorelease];
							 analog: false];
		down = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Down"
			  analog: false] autorelease];
		down = [OHGameControllerButton oh_elementWithName: @"D-Pad Down"
							   analog: false];
		left = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Left"
			  analog: false] autorelease];
		right = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Right"
			  analog: false] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			      up: up
			    down: down
			    left: left
			   right: right
			  analog: false] autorelease];
		left = [OHGameControllerButton oh_elementWithName: @"D-Pad Left"
							   analog: false];
		right = [OHGameControllerButton
		    oh_elementWithName: @"D-Pad Right"
				analog: false];
		directionalPad = [OHGameControllerDirectionalPad
		    oh_padWithName: @"D-Pad"
				up: up
			      down: down
			      left: left
			     right: right
			    analog: false];
		[directionalPads setObject: directionalPad forKey: @"D-Pad"];

		[directionalPads makeImmutable];
		_directionalPads = [directionalPads retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {