X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Config.m;h=189773436a41c7af148000a5834d65aafffa7d6a;hp=27ca4f0e91912a23585ecd6fbca2c4235e91e1af;hb=f864d363128de19fc6591b77ae9226b34166d715;hpb=51ca12b552a9c17c4d4029b0340e193b273044a8 diff --git a/Config.m b/Config.m index 27ca4f0..1897734 100644 --- a/Config.m +++ b/Config.m @@ -5,22 +5,41 @@ // Created by Sam McCall on 4/05/09. // +#import "Config.h" + +#import "NJInput.h" + @implementation Config --(id) init { - if(self=[super init]) { - entries = [[NSMutableDictionary alloc] init]; - } - return self; +- (id)initWithName:(NSString *)name { + if ((self = [super init])) { + self.name = name ? name : @"Untitled"; + _entries = [[NSMutableDictionary alloc] init]; + } + return self; } -@synthesize protect, name, entries; +- (Target *)objectForKeyedSubscript:(NJInput *)input { + return input ? _entries[input.uid] : nil; +} --(void) setTarget:(Target*)target forAction:(id)jsa { - [entries setValue:target forKey: [jsa stringify]]; +- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input { + if (input) { + if (target) + _entries[input.uid] = target; + else + [_entries removeObjectForKey:input.uid]; + } } --(Target*) getTargetForAction: (id) jsa { - return entries[[jsa stringify]]; + +- (NSDictionary *)serialize { + NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] initWithCapacity:_entries.count]; + for (id key in _entries) { + id serialized = [_entries[key] serialize]; + if (serialized) + cfgEntries[key] = serialized; + } + return @{ @"name": _name, @"entries": cfgEntries }; } @end