Analog mouse scrolling.
[enjoyable.git] / Config.m
1 //
2 // Config.m
3 // Enjoy
4 //
5 // Created by Sam McCall on 4/05/09.
6 //
7
8 #import "Config.h"
9
10 #import "JSAction.h"
11
12 @implementation Config
13
14 - (id)initWithName:(NSString *)name {
15 if ((self = [super init])) {
16 self.name = name ? name : @"Untitled";
17 _entries = [[NSMutableDictionary alloc] init];
18 }
19 return self;
20 }
21
22 - (Target *)objectForKeyedSubscript:(JSAction *)action {
23 return action ? _entries[action.uid] : nil;
24 }
25
26 - (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action {
27 if (action) {
28 if (target)
29 _entries[action.uid] = target;
30 else
31 [_entries removeObjectForKey:action.uid];
32 }
33 }
34
35 - (NSDictionary *)serialize {
36 NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] initWithCapacity:_entries.count];
37 for (id key in _entries) {
38 id serialized = [_entries[key] serialize];
39 if (serialized)
40 cfgEntries[key] = serialized;
41 }
42 return @{ @"name": _name, @"entries": cfgEntries };
43 }
44
45 @end