ObjFW  Diff

Differences From Artifact [0639ff2a5d]:

To Artifact [581b1be473]:


15
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
 * You should have received a copy of the GNU Lesser General Public License
 * version 3.0 along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#import "OHCombinedJoyCons.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameController.h"
#import "OHGameControllerDirectionalPad.h"



#import "OFInvalidArgumentException.h"

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

+ (instancetype)gamepadWithLeftJoyCon: (OHGameController *)leftJoyCon
			  rightJoyCon: (OHGameController *)rightJoyCon
{
	return [[[self alloc] initWithLeftJoyCon: leftJoyCon
				     rightJoyCon: rightJoyCon] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithLeftJoyCon: (OHGameController *)leftJoyCon
		       rightJoyCon: (OHGameController *)rightJoyCon
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFDictionary *leftButtons, *rightButtons;
		OFMutableDictionary *buttons, *directionalPads;

		if (leftJoyCon.vendorID.unsignedShortValue !=
		    OHVendorIDNintendo ||
		    rightJoyCon.vendorID.unsignedShortValue !=
		    OHVendorIDNintendo)
			@throw [OFInvalidArgumentException exception];

		if (leftJoyCon.productID.unsignedShortValue !=
		    OHProductIDLeftJoyCon ||
		    rightJoyCon.productID.unsignedShortValue !=
		    OHProductIDRightJoyCon)
			@throw [OFInvalidArgumentException exception];

		_leftJoyCon = [leftJoyCon.profile retain];
		_rightJoyCon = [rightJoyCon.profile retain];

		leftButtons = _leftJoyCon.buttons;
		rightButtons = _rightJoyCon.buttons;

		buttons = [OFMutableDictionary dictionaryWithCapacity:
		    leftButtons.count + rightButtons.count];
		[buttons addEntriesFromDictionary: leftButtons];
		[buttons addEntriesFromDictionary: rightButtons];
		[buttons removeObjectForKey: @"SL"];
		[buttons removeObjectForKey: @"SR"];
		[buttons makeImmutable];
		_buttons = [buttons retain];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];







|




>
>



|


|
|










|
|





<


<
<
<
<
<
<
<
<
<
<
<
<
|
|

<
<
<

|
|
|







15
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
 * You should have received a copy of the GNU Lesser General Public License
 * version 3.0 along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#import "OHJoyConPair.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameController.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHLeftJoyCon.h"
#import "OHRightJoyCon.h"

#import "OFInvalidArgumentException.h"

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

+ (instancetype)gamepadWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
			  rightJoyCon: (OHRightJoyCon *)rightJoyCon
{
	return [[[self alloc] initWithLeftJoyCon: leftJoyCon
				     rightJoyCon: rightJoyCon] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
		       rightJoyCon: (OHRightJoyCon *)rightJoyCon
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		OFMutableDictionary *buttons, *directionalPads;













		_leftJoyCon = [leftJoyCon retain];
		_rightJoyCon = [rightJoyCon retain];




		buttons = [OFMutableDictionary dictionaryWithCapacity:
		    _leftJoyCon.buttons.count + _rightJoyCon.buttons.count];
		[buttons addEntriesFromDictionary: _leftJoyCon.buttons];
		[buttons addEntriesFromDictionary: _rightJoyCon.buttons];
		[buttons removeObjectForKey: @"SL"];
		[buttons removeObjectForKey: @"SR"];
		[buttons makeImmutable];
		_buttons = [buttons retain];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];