X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Config.m;h=55162b081baa3270f35037fe0c00caed42bd18e2;hp=27ca4f0e91912a23585ecd6fbca2c4235e91e1af;hb=d442b81606d83ebf913f43d7c3fc5c885c0bbe30;hpb=51ca12b552a9c17c4d4029b0340e193b273044a8 diff --git a/Config.m b/Config.m index 27ca4f0..55162b0 100644 --- a/Config.m +++ b/Config.m @@ -5,22 +5,38 @@ // Created by Sam McCall on 4/05/09. // +#import "Config.h" + +#import "JSAction.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:(JSAction *)action { + return action ? _entries[action.uid] : nil; +} --(void) setTarget:(Target*)target forAction:(id)jsa { - [entries setValue:target forKey: [jsa stringify]]; +- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action { + if (action) { + if (target) + _entries[action.uid] = target; + else + [_entries removeObjectForKey:action.uid]; + } } --(Target*) getTargetForAction: (id) jsa { - return entries[[jsa stringify]]; + +- (NSDictionary *)serialize { + NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] initWithCapacity:_entries.count]; + for (id key in _entries) + cfgEntries[key] = [_entries[key] serialize]; + return @{ @"name": _name, @"entries": cfgEntries }; } @end