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 fc0971b..5f61191 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 0cb9855..0216e58 100644 (file)
@@ -10,7 +10,6 @@
 @implementation JSAction
 
 @synthesize cookie;
-@synthesize index;
 @synthesize children;
 @synthesize base;
 @synthesize name;
index ae347fa..7348e19 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 58503c8..12449ce 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 114d82e..7c9ffce 100644 (file)
@@ -10,4 +10,6 @@
 
 @interface JSActionHat : JSAction
 
+- (id)initWithIndex:(int)index;
+
 @end
index 6ed0ad1..174d2df 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 7870ce0..c86a363 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