From: Joe Wreschnig Date: Wed, 27 Feb 2013 23:34:12 +0000 (+0100) Subject: Indices are for display niceness only, so index them from 1 rather than keep offsetti... X-Git-Tag: version-1.0~104 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=3f6df7a954fb74bcebf6fc6c0e60821843b0f31b;p=enjoyable.git Indices are for display niceness only, so index them from 1 rather than keep offsetting them. Remove SubAction, it's just JSAction now. --- diff --git a/Enjoy.xcodeproj/project.pbxproj b/Enjoy.xcodeproj/project.pbxproj index b8dc528..16e0380 100644 --- a/Enjoy.xcodeproj/project.pbxproj +++ b/Enjoy.xcodeproj/project.pbxproj @@ -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 = ""; }; D5617D290FAF579A00928B3A /* JSActionAnalog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSActionAnalog.h; sourceTree = ""; }; D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionAnalog.m; sourceTree = ""; }; - D5617DF00FAF636C00928B3A /* SubAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubAction.h; sourceTree = ""; }; - D5617DF10FAF636C00928B3A /* SubAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SubAction.m; sourceTree = ""; }; D5617FD40FAFD06000928B3A /* Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Target.h; sourceTree = ""; }; D5617FD50FAFD06000928B3A /* Target.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Target.m; sourceTree = ""; }; D5617FD70FAFD1E600928B3A /* TargetKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetKeyboard.h; sourceTree = ""; }; @@ -124,8 +121,6 @@ D5617A350FAEB74000928B3A /* ConfigsController.m */, D5617A370FAEBA1800928B3A /* Config.h */, D5617A380FAEBA1800928B3A /* Config.m */, - D5617DF00FAF636C00928B3A /* SubAction.h */, - D5617DF10FAF636C00928B3A /* SubAction.m */, D5F8096F0FB093400006A4DE /* TargetConfig.h */, D5F809700FB093400006A4DE /* TargetConfig.m */, D5617FD40FAFD06000928B3A /* Target.h */, @@ -295,7 +290,6 @@ 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 */, diff --git a/Enjoy_Prefix.pch b/Enjoy_Prefix.pch index 0fab501..2105ca7 100644 --- a/Enjoy_Prefix.pch +++ b/Enjoy_Prefix.pch @@ -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" diff --git a/JSAction.h b/JSAction.h index b92c7d6..4b35832 100644 --- a/JSAction.h +++ b/JSAction.h @@ -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; diff --git a/JSAction.m b/JSAction.m index 8576b2f..f96c10d 100644 --- a/JSAction.m +++ b/JSAction.m @@ -16,12 +16,23 @@ @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 { diff --git a/JSActionAnalog.m b/JSActionAnalog.m index 06552a9..ae347fa 100644 --- a/JSActionAnalog.m +++ b/JSActionAnalog.m @@ -18,12 +18,12 @@ - (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; } diff --git a/JSActionButton.m b/JSActionButton.m index c358c8d..f6a0fa7 100644 --- a/JSActionButton.m +++ b/JSActionButton.m @@ -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; } diff --git a/JSActionHat.m b/JSActionHat.m index d948cc7..41d3728 100644 --- a/JSActionHat.m +++ b/JSActionHat.m @@ -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"; } diff --git a/Joystick.m b/Joystick.m index a65304e..861ab8d 100644 --- a/Joystick.m +++ b/Joystick.m @@ -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 { diff --git a/JoystickController.m b/JoystickController.m index 8b350a4..317e9a5 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -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 index 7b297d8..0000000 --- a/SubAction.h +++ /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 - -#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 index 45ad4ea..0000000 --- a/SubAction.m +++ /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