Indices are for display niceness only, so index them from 1 rather than keep offsetti...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 23:34:12 +0000 (00:34 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 23:34:12 +0000 (00:34 +0100)
Enjoy.xcodeproj/project.pbxproj
Enjoy_Prefix.pch
JSAction.h
JSAction.m
JSActionAnalog.m
JSActionButton.m
JSActionHat.m
Joystick.m
JoystickController.m
SubAction.h [deleted file]
SubAction.m [deleted file]

index b8dc528..16e0380 100644 (file)
@@ -21,7 +21,6 @@
                D5617D1A0FAF568100928B3A /* JSActionButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D190FAF568100928B3A /* JSActionButton.m */; };
                D5617D260FAF579300928B3A /* JSActionHat.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D250FAF579300928B3A /* JSActionHat.m */; };
                D5617D2B0FAF579A00928B3A /* JSActionAnalog.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */; };
-               D5617DF20FAF636C00928B3A /* SubAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617DF10FAF636C00928B3A /* SubAction.m */; };
                D5617FD60FAFD06000928B3A /* Target.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD50FAFD06000928B3A /* Target.m */; };
                D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD80FAFD1E600928B3A /* TargetKeyboard.m */; };
                D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE30FAFD7B000928B3A /* TargetController.m */; };
@@ -66,8 +65,6 @@
                D5617D250FAF579300928B3A /* JSActionHat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionHat.m; sourceTree = "<group>"; };
                D5617D290FAF579A00928B3A /* JSActionAnalog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSActionAnalog.h; sourceTree = "<group>"; };
                D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionAnalog.m; sourceTree = "<group>"; };
-               D5617DF00FAF636C00928B3A /* SubAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubAction.h; sourceTree = "<group>"; };
-               D5617DF10FAF636C00928B3A /* SubAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SubAction.m; sourceTree = "<group>"; };
                D5617FD40FAFD06000928B3A /* Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Target.h; sourceTree = "<group>"; };
                D5617FD50FAFD06000928B3A /* Target.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Target.m; sourceTree = "<group>"; };
                D5617FD70FAFD1E600928B3A /* TargetKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetKeyboard.h; sourceTree = "<group>"; };
                                D5617A350FAEB74000928B3A /* ConfigsController.m */,
                                D5617A370FAEBA1800928B3A /* Config.h */,
                                D5617A380FAEBA1800928B3A /* Config.m */,
-                               D5617DF00FAF636C00928B3A /* SubAction.h */,
-                               D5617DF10FAF636C00928B3A /* SubAction.m */,
                                D5F8096F0FB093400006A4DE /* TargetConfig.h */,
                                D5F809700FB093400006A4DE /* TargetConfig.m */,
                                D5617FD40FAFD06000928B3A /* Target.h */,
                                D5617D1A0FAF568100928B3A /* JSActionButton.m in Sources */,
                                D5617D260FAF579300928B3A /* JSActionHat.m in Sources */,
                                D5617D2B0FAF579A00928B3A /* JSActionAnalog.m in Sources */,
-                               D5617DF20FAF636C00928B3A /* SubAction.m in Sources */,
                                D5617FD60FAFD06000928B3A /* Target.m in Sources */,
                                D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */,
                                D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */,
index 0fab501..2105ca7 100644 (file)
@@ -18,7 +18,6 @@
 #import "JSActionButton.h"
 #import "JSActionHat.h"
 #import "KeyInputTextView.h"
-#import "SubAction.h"
 #import "Target.h"
 #import "TargetConfig.h"
 #import "TargetController.h"
index b92c7d6..4b35832 100644 (file)
@@ -19,6 +19,8 @@
 @property (assign) BOOL active;
 @property (readonly) float magnitude;
 
+- (id)initWithName:(NSString *)newName base:(JSAction *)newBase;
+
 - (void)notifyEvent:(IOHIDValueRef)value;
 - (NSString *)stringify;
 - (id)findSubActionForValue:(IOHIDValueRef)value;
index 8576b2f..f96c10d 100644 (file)
 @synthesize name;
 @synthesize active;
 
+- (id)initWithName:(NSString *)newName base:(JSAction *)newBase {
+    if ((self = [super init])) {
+        self.name = newName;
+        self.base = newBase;
+    }
+    return self;
+}
+
 - (id)findSubActionForValue:(IOHIDValueRef)value {
     return NULL;
 }
 
 - (NSString *)stringify {
-    return [NSString stringWithFormat: @"%@~%p", [base stringify], cookie];
+    if (cookie)
+        return [NSString stringWithFormat: @"%@~%p", [base stringify], cookie];
+    else
+        return [NSString stringWithFormat: @"%@~%@", [base stringify], name];
 }
 
 - (void)notifyEvent:(IOHIDValueRef)value {
index 06552a9..ae347fa 100644 (file)
 
 - (id)initWithIndex:(int)newIndex offset:(float)offset_ scale:(float)scale_ {
     if ((self = [super init])) {
-        self.children = @[[[SubAction alloc] initWithIndex:0 name:@"Low" base:self],
-                          [[SubAction alloc] initWithIndex:1 name:@"High" base:self]];
+        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 + 1];
+        self.name = [[NSString alloc] initWithFormat: @"Axis %d", self.index];
     }
     return self;
 }
index c358c8d..f6a0fa7 100644 (file)
@@ -17,9 +17,9 @@
         self.index = idx;
         self.max = max_;
         if (name_.length)
-            self.name = [NSString stringWithFormat:@"Button %d - %@", self.index + 1, name_];
+            self.name = [NSString stringWithFormat:@"Button %d - %@", self.index, name_];
         else
-            self.name = [NSString stringWithFormat:@"Button %d", self.index + 1];
+            self.name = [NSString stringWithFormat:@"Button %d", self.index];
     }
     return self;
 }
index d948cc7..41d3728 100644 (file)
@@ -29,10 +29,10 @@ static BOOL active_fourway[20] = {
 
 - (id)init {
     if ((self = [super init])) {
-        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]];
+        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";
     }
index a65304e..861ab8d 100644 (file)
@@ -32,13 +32,13 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) {
         
         if (max - min == 1 || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) {
             action = [[JSActionButton alloc] initWithName:(__bridge NSString *)elName
-                                                      idx:buttons++
+                                                      idx:++buttons
                                                       max:max];
         } else if (usage == kHIDUsage_GD_Hatswitch) {
             action = [[JSActionHat alloc] init];
         } 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++
+            action = [[JSActionAnalog alloc] initWithIndex:++axes
                                                     offset:-1.f
                                                      scale:2.f / (max - min)];
         } else {
@@ -74,7 +74,7 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) {
 }
 
 - (NSString *)name {
-    return [NSString stringWithFormat:@"%@ #%d", productName, index + 1];
+    return [NSString stringWithFormat:@"%@ #%d", productName, index];
 }
 
 - (id)base {
index 8b350a4..317e9a5 100644 (file)
@@ -82,7 +82,7 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa
 }
 
 static int findAvailableIndex(NSArray *list, Joystick *js) {
-    for (int index = 0; ; index++) {
+    for (int index = 1; ; index++) {
         BOOL available = YES;
         for (Joystick *used in list) {
             if ([used.productName isEqualToString:js.productName] && used.index == index) {
diff --git a/SubAction.h b/SubAction.h
deleted file mode 100644 (file)
index 7b297d8..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-//  SubAction.h
-//  Enjoy
-//
-//  Created by Sam McCall on 5/05/09.
-//  Copyright 2009 University of Otago. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-#import "JSAction.h"
-
-@interface SubAction : JSAction
-
-- (id)initWithIndex:(int)newIndex name:(NSString *)newName  base:(JSAction *)newBase;
-
-@end
diff --git a/SubAction.m b/SubAction.m
deleted file mode 100644 (file)
index 45ad4ea..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-//  SubAction.m
-//  Enjoy
-//
-//  Created by Sam McCall on 5/05/09.
-//
-
-// TODO(jfw): This class is useless and can just be replaced w/ JSAction probably.
-
-#import "SubAction.h"
-
-@implementation SubAction
-
-- (id)initWithIndex:(int)newIndex name:(NSString *)newName base:(JSAction *)newBase {
-       if ((self = [super init])) {
-        self.name = newName;
-        self.base = newBase;
-        self.index = newIndex;
-       }
-       return self;
-}
-
--(NSString*) stringify {
-       return [[NSString alloc] initWithFormat: @"%@~%d", [self.base stringify], self.index];
-}
-
-@end