X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Config.m;h=189773436a41c7af148000a5834d65aafffa7d6a;hp=f62c40fdf49a1571442bd25becb1ffd9f7bd13ac;hb=f864d363128de19fc6591b77ae9226b34166d715;hpb=e68c19b5923618b763543c74bf8dd6f85d4d323e diff --git a/Config.m b/Config.m index f62c40f..1897734 100644 --- a/Config.m +++ b/Config.m @@ -7,23 +7,39 @@ #import "Config.h" -@implementation Config +#import "NJInput.h" -@synthesize protect, name, entries; +@implementation Config -- (id)init { +- (id)initWithName:(NSString *)name { if ((self = [super init])) { - entries = [[NSMutableDictionary alloc] init]; + self.name = name ? name : @"Untitled"; + _entries = [[NSMutableDictionary alloc] init]; } return self; } -- (void)setTarget:(Target *)target forAction:(JSAction *)jsa { - entries[[jsa stringify]] = target; +- (Target *)objectForKeyedSubscript:(NJInput *)input { + return input ? _entries[input.uid] : nil; +} + +- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input { + if (input) { + if (target) + _entries[input.uid] = target; + else + [_entries removeObjectForKey:input.uid]; + } } -- (Target *)getTargetForAction:(JSAction *)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