Index hat switch names. Remove JSAction index properties entirely, once the name...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 28 Feb 2013 18:28:34 +0000 (19:28 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 28 Feb 2013 18:28:34 +0000 (19:28 +0100)
JSAction.h
JSAction.m
JSActionAnalog.m
JSActionButton.m
JSActionHat.h
JSActionHat.m
Joystick.m

index fc0971b3ec778c8f34b575ec48f84d38f7c008b8..5f61191b0b5f15a29361c00c6fc302e2cf888c0e 100644 (file)
@@ -9,7 +9,6 @@
 @interface JSAction : NSObject
 
 @property (assign) void *cookie;
-@property (assign) int index;
 @property (copy) NSArray *children;
 @property (weak) id base;
 @property (copy) NSString *name;
index 0cb98554bf020ba58c622924533e9da9ebadf23e..0216e582f1e3729c1a61d8231dc36a7c6eab3a80 100644 (file)
@@ -10,7 +10,6 @@
 @implementation JSAction
 
 @synthesize cookie;
-@synthesize index;
 @synthesize children;
 @synthesize base;
 @synthesize name;
index ae347fa9ad85774e7ac9ad41ba8ff109117df3d4..7348e1968aff0ea713ac947696f598869a8bc196 100644 (file)
     if ((self = [super init])) {
         self.children = @[[[JSAction alloc] initWithName:@"Low" base:self],
                           [[JSAction alloc] initWithName:@"High" base:self]];
-        self.index = newIndex;
         self.offset = offset_;
         self.scale = scale_;
-        self.name = [[NSString alloc] initWithFormat: @"Axis %d", self.index];
+        self.name = [[NSString alloc] initWithFormat: @"Axis %d", newIndex];
     }
     return self;
 }
index 58503c82de69560f91c3d30f1b438d4d6c148a7a..12449ce99dfa50c362c020df761801bcc660a2ca 100644 (file)
 
 - (id)initWithName:(NSString *)name_ idx:(int)idx max:(int)max_ {
     if ((self = [super init])) {
-        self.index = idx;
         self.max = max_;
         if (name_.length)
-            self.name = [NSString stringWithFormat:@"Button %d - %@", self.index, name_];
+            self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name_];
         else
-            self.name = [NSString stringWithFormat:@"Button %d", self.index];
+            self.name = [NSString stringWithFormat:@"Button %d", idx];
     }
     return self;
 }
index 114d82e5e4f125be4d05eddd1b64a2ce021b8c06..7c9ffce8a3844842a2a8c6f6812864f952e688ff 100644 (file)
@@ -10,4 +10,6 @@
 
 @interface JSActionHat : JSAction
 
+- (id)initWithIndex:(int)index;
+
 @end
index 6ed0ad13443b3c19737d6c6367f646c341c7b63d..174d2df484b406eaa19ee9dd99ef54f2e856673c 100644 (file)
@@ -29,14 +29,13 @@ static BOOL active_fourway[20] = {
 
 @implementation JSActionHat
 
-- (id)init {
+- (id)initWithIndex:(int)index {
     if ((self = [super init])) {
-        self.children = @[[[JSAction alloc] initWithName:@"Up" base: self],
-                          [[JSAction alloc] initWithName:@"Down" base: self],
-                          [[JSAction alloc] initWithName:@"Left" base: self],
-                          [[JSAction alloc] initWithName:@"Right" base: self]];
-        // TODO(jfw): Should have an indexed name, like everything else.
-        self.name = @"Hat switch";
+        self.children = @[[[JSAction alloc] initWithName:@"Up" base:self],
+                          [[JSAction alloc] initWithName:@"Down" base:self],
+                          [[JSAction alloc] initWithName:@"Left" base:self],
+                          [[JSAction alloc] initWithName:@"Right" base:self]];
+        self.name = [NSString stringWithFormat:@"Hat Switch %d", index];
     }
     return self;
 }
index 7870ce0589ec6e6a44f0d54790726eb0bf664d0b..c86a3637a19a6460df653108bf0d835664056834 100644 (file)
@@ -18,6 +18,7 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) {
     
     int buttons = 0;
     int axes = 0;
+    int hats = 0;
     
     for (int i = 0; i < CFArrayGetCount(elements); i++) {
         IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
@@ -40,7 +41,7 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) {
                                                       idx:++buttons
                                                       max:max];
         } else if (usage == kHIDUsage_GD_Hatswitch) {
-            action = [[JSActionHat alloc] init];
+            action = [[JSActionHat alloc] initWithIndex:++hats];
         } else if (usage >= kHIDUsage_GD_X && usage <= kHIDUsage_GD_Rz) {
             // TODO(jfw): Scaling equation doesn't seem right if min != 0.
             action = [[JSActionAnalog alloc] initWithIndex:++axes