@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
#import "Config.h"
-@implementation Config
+@implementation Config {
+ NSMutableDictionary *entries;
+}
@synthesize protect, name, entries;
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
[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];
}
}
@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
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 {
@property (assign) IOHIDDeviceRef device;
@property (copy) NSArray *children;
@property (readonly) NSString *name;
+@property (readonly) NSString *uid;
- (id)initWithDevice:(IOHIDDeviceRef)device;
- (id)handlerForEvent:(IOHIDValueRef)value;
}
- (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 {
[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)
}
-(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;
}
}
} else {
[self setEnabled: YES];
}
- Target* target = [[configsController currentConfig] getTargetForAction: jsaction];
+ Target* target = configsController.currentConfig[jsaction];
id act = jsaction;
NSString* actFullName = [act name];