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 b8dc528b2e2c9c05bf54b6ec5d02c7a11dfb0328..16e0380e25b67b13e02cea5f1fbd4f7118ca96f6 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 0fab5019bbf383e2bbc282c4c8c0dff25f8b90b8..2105ca7e93f0480c31504f1ae1089168390c7d7c 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 b92c7d6301017b0ecd88b2335b388db8e8d3a132..4b35832a4b6c12cfd778c9bc59ff9b09c8383e41 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 8576b2fdc6af36e4a95dfc55db90f762957dc960..f96c10d878adc5dd7a9c6c2ddb73c385d36da911 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 06552a967509f721cd0228fc6f977fd189c36ff1..ae347fa9ad85774e7ac9ad41ba8ff109117df3d4 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 c358c8dfc873d38d5ca56bbc741c56f3eac9cf15..f6a0fa76f003edc5ab89c3242c64e245de4f9bde 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 d948cc7ac42493be52e71765950de04c34c17714..41d372870a33a519497adc4fdbde75e1b8bf57cd 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 a65304e304b84a434a06dd31fa64a830e9d34fdb..861ab8d8bc1c44459d22f6515c077cb22aa21b51 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 8b350a489788f25f33373a7cf4cc0e168a7b1b55..317e9a51c9b09ae0680c9cf42b9565ee9c8fd447 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