From: Joe Wreschnig Date: Thu, 28 Feb 2013 00:08:58 +0000 (+0100) Subject: Rename 'stringify' to 'uid' where it pertains to unique action IDs. X-Git-Tag: version-1.0~103 X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=commitdiff_plain;h=25dd74a4a34f4ba7ec797360bd8f92cbd7bc758e Rename 'stringify' to 'uid' where it pertains to unique action IDs. --- diff --git a/Config.h b/Config.h index d118262..d85ec93 100644 --- a/Config.h +++ b/Config.h @@ -17,7 +17,7 @@ @property (copy) NSString *name; @property (readonly) NSMutableDictionary *entries; -- (void)setTarget:(Target *)target forAction:(JSAction *)jsa; -- (Target *)getTargetForAction:(JSAction *)sa; +- (Target *)objectForKeyedSubscript:(JSAction *)action; +- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action; @end diff --git a/Config.m b/Config.m index f62c40f..727b8b0 100644 --- a/Config.m +++ b/Config.m @@ -7,7 +7,9 @@ #import "Config.h" -@implementation Config +@implementation Config { + NSMutableDictionary *entries; +} @synthesize protect, name, entries; @@ -18,12 +20,17 @@ return self; } -- (void)setTarget:(Target *)target forAction:(JSAction *)jsa { - entries[[jsa stringify]] = target; +- (Target *)objectForKeyedSubscript:(JSAction *)action { + return action ? entries[action.uid] : nil; } -- (Target *)getTargetForAction:(JSAction *)jsa { - return entries[[jsa stringify]]; +- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action { + if (action) { + if (target) + entries[action.uid] = target; + else + [entries removeObjectForKey:action.uid]; + } } @end diff --git a/ConfigsController.m b/ConfigsController.m index 63211ae..58614b2 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -68,11 +68,11 @@ [configs removeObjectAtIndex: [tableView selectedRow]]; // remove all "switch to configuration" actions - for(int i=0; i<[configs count]; i++) { - NSMutableDictionary* entries = [(Config*)configs[i] entries]; - for(id key in entries) { - Target* target = (Target*) entries[key]; - if([target isKindOfClass: [TargetConfig class]] && [(TargetConfig*)target config] == current_config) + for (Config *config in configs) { + NSMutableDictionary *entries = config.entries; + for (id key in entries) { + Target *target = entries[key]; + if([target isKindOfClass:[TargetConfig class]] && [(TargetConfig *)target config] == current_config) [entries removeObjectForKey: key]; } } diff --git a/JSAction.h b/JSAction.h index 4b35832..94d56f0 100644 --- a/JSAction.h +++ b/JSAction.h @@ -18,11 +18,11 @@ @property (copy) NSString *name; @property (assign) BOOL active; @property (readonly) float magnitude; +@property (readonly) NSString *uid; - (id)initWithName:(NSString *)newName base:(JSAction *)newBase; - (void)notifyEvent:(IOHIDValueRef)value; -- (NSString *)stringify; - (id)findSubActionForValue:(IOHIDValueRef)value; @end diff --git a/JSAction.m b/JSAction.m index f96c10d..0cb9855 100644 --- a/JSAction.m +++ b/JSAction.m @@ -28,11 +28,8 @@ return NULL; } -- (NSString *)stringify { - if (cookie) - return [NSString stringWithFormat: @"%@~%p", [base stringify], cookie]; - else - return [NSString stringWithFormat: @"%@~%@", [base stringify], name]; +- (NSString *)uid { + return [NSString stringWithFormat:@"%@~%@", [self.base uid], self.name]; } - (void)notifyEvent:(IOHIDValueRef)value { diff --git a/Joystick.h b/Joystick.h index 04c5686..831b10b 100644 --- a/Joystick.h +++ b/Joystick.h @@ -20,6 +20,7 @@ @property (assign) IOHIDDeviceRef device; @property (copy) NSArray *children; @property (readonly) NSString *name; +@property (readonly) NSString *uid; - (id)initWithDevice:(IOHIDDeviceRef)device; - (id)handlerForEvent:(IOHIDValueRef)value; diff --git a/Joystick.m b/Joystick.m index 861ab8d..3f21818 100644 --- a/Joystick.m +++ b/Joystick.m @@ -78,12 +78,11 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) { } - (id)base { - // FIXME(jfw): This is a hack because actions get joysticks as their base. return nil; } -- (NSString *)stringify { - return [[NSString alloc] initWithFormat: @"%d~%d~%d", vendorId, productId, index]; +- (NSString *)uid { + return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, index]; } - (JSAction *)findActionByCookie:(void *)cookie { diff --git a/JoystickController.m b/JoystickController.m index 317e9a5..d87dca7 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -62,7 +62,7 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa [mainAction notifyEvent:value]; NSArray *children = mainAction.children ? mainAction.children : mainAction ? @[mainAction] : @[]; for (JSAction *subaction in children) { - Target *target = [controller.currentConfig getTargetForAction:subaction]; + Target *target = controller.currentConfig[subaction]; target.magnitude = mainAction.magnitude; target.running = subaction.active; if (target.running && target.isContinuous) diff --git a/TargetController.m b/TargetController.m index 82eec03..074c487 100644 --- a/TargetController.m +++ b/TargetController.m @@ -93,10 +93,9 @@ } -(void) commit { - id action = [joystickController selectedAction]; - if(action) { - Target* target = [self state]; - [[configsController currentConfig] setTarget: target forAction: action]; + JSAction *action = [joystickController selectedAction]; + if (action) { + configsController.currentConfig[action] = self.state; } } @@ -131,7 +130,7 @@ } else { [self setEnabled: YES]; } - Target* target = [[configsController currentConfig] getTargetForAction: jsaction]; + Target* target = configsController.currentConfig[jsaction]; id act = jsaction; NSString* actFullName = [act name];