X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJMapping.m;fp=NJMapping.m;h=a5f810ccd57b2ad20050f095056f5f7b6b3a04d9;hp=0000000000000000000000000000000000000000;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=f864d363128de19fc6591b77ae9226b34166d715 diff --git a/NJMapping.m b/NJMapping.m new file mode 100644 index 0000000..a5f810c --- /dev/null +++ b/NJMapping.m @@ -0,0 +1,45 @@ +// +// NJMapping.m +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// + +#import "NJMapping.h" + +#import "NJInput.h" + +@implementation NJMapping + +- (id)initWithName:(NSString *)name { + if ((self = [super init])) { + self.name = name ? name : @"Untitled"; + _entries = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (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]; + } +} + +- (NSDictionary *)serialize { + NSMutableDictionary *entries = [[NSMutableDictionary alloc] initWithCapacity:_entries.count]; + for (id key in _entries) { + id serialized = [_entries[key] serialize]; + if (serialized) + entries[key] = serialized; + } + return @{ @"name": _name, @"entries": entries }; +} + +@end