Rename 'subActions' to 'children' to match Joystick property name. Simplify logic...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 15:31:32 +0000 (16:31 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 15:31:32 +0000 (16:31 +0100)
JSAction.h
JSAction.m
JSActionAnalog.m
JSActionHat.m
JoystickController.m

index 9de469659445cc69113046868a6df3ae1326cf72..30e99b9cd71e68a4a649a9d170589d7742a5f0ae 100644 (file)
@@ -16,7 +16,7 @@
 
 @property (assign) void* cookie;
 @property (assign) int index;
-@property (copy) NSArray *subActions;
+@property (copy) NSArray *children;
 @property (strong) id base;
 @property (copy) NSString *name;
 @property (readonly) BOOL active;
index 6bc15291d3c37fd72100017123498ba8a168e9e8..84d1ea84c395d40587dd3bd04879fc74247fa51c 100644 (file)
@@ -11,7 +11,7 @@
 
 @synthesize cookie;
 @synthesize index;
-@synthesize subActions;
+@synthesize children;
 @synthesize base;
 @synthesize name;
 
index e7d6eba8f6b2d08687e8e775f241fc30ffd97db0..5aded63d3ad01e51dc8da6d926d2e4f8c26cd655 100644 (file)
@@ -16,8 +16,8 @@
 
 - (id)initWithIndex:(int)newIndex offset:(float)offset_ scale:(float)scale_ {
     if ((self = [super init])) {
-        self.subActions = @[[[SubAction alloc] initWithIndex:0 name:@"Low" base:self],
-                            [[SubAction alloc] initWithIndex:1 name:@"High" base:self]];
+        self.children = @[[[SubAction alloc] initWithIndex:0 name:@"Low" base:self],
+                          [[SubAction alloc] initWithIndex:1 name:@"High" base:self]];
         self.index = newIndex;
         self.offset = offset_;
         self.scale = scale_;
@@ -31,9 +31,9 @@
     float parsed = [self getRealValue:raw];
     
     if (parsed < -DEAD_ZONE)
-        return self.subActions[0];
+        return self.children[0];
     else if (parsed > DEAD_ZONE)
-        return self.subActions[1];
+        return self.children[1];
     else
         return nil;
 }
@@ -41,8 +41,8 @@
 - (void)notifyEvent:(IOHIDValueRef)value {
     int raw = IOHIDValueGetIntegerValue(value);
     float parsed = [self getRealValue:raw];
-    [self.subActions[0] setActive:parsed < -DEAD_ZONE];
-    [self.subActions[1] setActive:parsed > DEAD_ZONE];
+    [self.children[0] setActive:parsed < -DEAD_ZONE];
+    [self.children[1] setActive:parsed > DEAD_ZONE];
 }
 
 - (float)getRealValue:(int)value {
index 4e11b49b4dcfaafd71ba9cd8b8d810c8c5cb0dd1..d948cc7ac42493be52e71765950de04c34c17714 100644 (file)
@@ -29,7 +29,7 @@ static BOOL active_fourway[20] = {
 
 - (id)init {
     if ((self = [super init])) {
-        self.subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
+        self.children = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
                             [[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
                             [[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
                             [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]];
@@ -44,34 +44,34 @@ static BOOL active_fourway[20] = {
     switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) {
         case 7: // 8-way switch, 0-7.
             switch (parsed) {
-                case 0: return self.subActions[0];
-                case 4: return self.subActions[1];
-                case 6: return self.subActions[2];
-                case 2: return self.subActions[3];
+                case 0: return self.children[0];
+                case 4: return self.children[1];
+                case 6: return self.children[2];
+                case 2: return self.children[3];
                 default: return nil;
             }
         case 8: // 8-way switch, 1-8 (neutral 0).
             switch (parsed) {
-                case 1: return self.subActions[0];
-                case 5: return self.subActions[1];
-                case 7: return self.subActions[2];
-                case 3: return self.subActions[3];
+                case 1: return self.children[0];
+                case 5: return self.children[1];
+                case 7: return self.children[2];
+                case 3: return self.children[3];
                 default: return nil;
             }
         case 3: // 4-way switch, 0-3.
             switch (parsed) {
-                case 0: return self.subActions[0];
-                case 2: return self.subActions[1];
-                case 3: return self.subActions[2];
-                case 1: return self.subActions[3];
+                case 0: return self.children[0];
+                case 2: return self.children[1];
+                case 3: return self.children[2];
+                case 1: return self.children[3];
                 default: return nil;
             }
         case 4: // 4-way switch, 1-4 (neutral 0).
             switch (parsed) {
-                case 1: return self.subActions[0];
-                case 3: return self.subActions[1];
-                case 4: return self.subActions[2];
-                case 2: return self.subActions[3];
+                case 1: return self.children[0];
+                case 3: return self.children[1];
+                case 4: return self.children[2];
+                case 2: return self.children[3];
                 default: return nil;
             }
         default:
@@ -87,9 +87,9 @@ static BOOL active_fourway[20] = {
         parsed++;
         size++;
     }
-    BOOL *activeSubactions = (size == 8) ? active_eightway : active_fourway;
+    BOOL *activechildren = (size == 8) ? active_eightway : active_fourway;
     for (int i = 0; i < 4; i++)
-        [self.subActions[i] setActive:activeSubactions[parsed * 4 + i]];
+        [self.children[i] setActive:activechildren[parsed * 4 + i]];
 }
 
 @end
index 54734a8f7598165272f8351ef193520796a07118..6d73a2a7d609b1ad6c248d03005780bbee155de7 100644 (file)
@@ -62,10 +62,10 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa
                        return;
                
                [mainAction notifyEvent: value];
-               NSArray* subactions = [mainAction subActions];
-               if(!subactions)
-                       subactions = @[mainAction];
-               for(id subaction in subactions) {
+               NSArray* children = [mainAction children];
+               if(!children)
+                       children = @[mainAction];
+               for(id subaction in children) {
                        Target* target = [[controller->configsController currentConfig] getTargetForAction:subaction];
                        if(!target)
                                continue;
@@ -176,46 +176,21 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD
 
 - (JSAction *)selectedAction {
     id item = [outlineView itemAtRow:outlineView.selectedRow];
-       if ([item isKindOfClass: [JSAction class]] && ![item subActions])
-               return item;
-    else
-        return nil;
+    return [item children] ? nil : item;
 }
 
-/* outline view */
-
 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
-       if(item == nil)
-               return [joysticks count];
-       if([item isKindOfClass: [Joystick class]])
-               return [[item children] count];
-       if([item isKindOfClass: [JSAction class]] && [item subActions] != NULL)
-               return [[item subActions] count];
-       return 0;
+    return item ? [[item children] count] : [joysticks count];
 }
 
 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
-       if(item == nil)
-               return YES;
-       if([item isKindOfClass: [Joystick class]])
-               return YES;
-       if([item isKindOfClass: [JSAction class]]) 
-               return [item subActions]==NULL ? NO : YES;
-       return NO;
+    return item ? [[item children] count] > 0: YES;
 }
 
 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
-       if(item == nil) 
-               return joysticks[index];
-
-       if([item isKindOfClass: [Joystick class]])
-               return [item children][index];
-       
-       if([item isKindOfClass: [JSAction class]]) 
-               return [item subActions][index];
-
-       return NULL;
+    return item ? [item children][index] : joysticks[index];
 }
+
 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  {
        if(item == nil)
                return @"root";