From: Joe Wreschnig Date: Thu, 28 Feb 2013 18:28:34 +0000 (+0100) Subject: Index hat switch names. Remove JSAction index properties entirely, once the name... X-Git-Tag: version-1.0~90 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=2fb801b58b29997f54443d9879d2e20ae8b169ad;p=enjoyable.git Index hat switch names. Remove JSAction index properties entirely, once the name is generated they're not necessary. --- diff --git a/JSAction.h b/JSAction.h index fc0971b..5f61191 100644 --- a/JSAction.h +++ b/JSAction.h @@ -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; diff --git a/JSAction.m b/JSAction.m index 0cb9855..0216e58 100644 --- a/JSAction.m +++ b/JSAction.m @@ -10,7 +10,6 @@ @implementation JSAction @synthesize cookie; -@synthesize index; @synthesize children; @synthesize base; @synthesize name; diff --git a/JSActionAnalog.m b/JSActionAnalog.m index ae347fa..7348e19 100644 --- a/JSActionAnalog.m +++ b/JSActionAnalog.m @@ -20,10 +20,9 @@ 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; } diff --git a/JSActionButton.m b/JSActionButton.m index 58503c8..12449ce 100644 --- a/JSActionButton.m +++ b/JSActionButton.m @@ -16,12 +16,11 @@ - (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; } diff --git a/JSActionHat.h b/JSActionHat.h index 114d82e..7c9ffce 100644 --- a/JSActionHat.h +++ b/JSActionHat.h @@ -10,4 +10,6 @@ @interface JSActionHat : JSAction +- (id)initWithIndex:(int)index; + @end diff --git a/JSActionHat.m b/JSActionHat.m index 6ed0ad1..174d2df 100644 --- a/JSActionHat.m +++ b/JSActionHat.m @@ -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; } diff --git a/Joystick.m b/Joystick.m index 7870ce0..c86a363 100644 --- a/Joystick.m +++ b/Joystick.m @@ -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