X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJMappingsController.m;h=ad257cfb8b269028d62d85bc6d4882108b7706f8;hp=de66fb888f5199bdd348b40289ffa6412da2558a;hb=dacfcc6b0bf3bfebc89b5e6e8266da9eb36177cd;hpb=a7260fe79808efcad6a92cace15a1b3429f14787 diff --git a/Classes/NJMappingsController.m b/Classes/NJMappingsController.m index de66fb8..ad257cf 100644 --- a/Classes/NJMappingsController.m +++ b/Classes/NJMappingsController.m @@ -51,7 +51,9 @@ [self updateInterfaceForCurrentMapping]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingListChanged - object:_mappings]; + object:self + userInfo:@{ @"mappings": _mappings, + @"mapping": _currentMapping }]; } - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state @@ -104,8 +106,10 @@ _manualMapping = mapping; _currentMapping = mapping; [self updateInterfaceForCurrentMapping]; - [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged - object:_currentMapping]; + [NSNotificationCenter.defaultCenter + postNotificationName:NJEventMappingChanged + object:self + userInfo:@{ @"mapping": _currentMapping }]; } - (IBAction)addPressed:(id)sender { @@ -167,21 +171,19 @@ - (void)loadAllFrom:(NSArray *)storedMappings andActivate:(NSUInteger)selected { NSMutableArray* newMappings = [[NSMutableArray alloc] initWithCapacity:storedMappings.count]; - // have to do two passes in case mapping1 refers to mapping2 via a NJOutputMapping + // Requires two passes to deal with inter-mapping references. First make + // an empty mapping for each serialized mapping. Then, deserialize the + // data pointing to the empty mappings. Then merge that data back into + // its equivalent empty one, which is the one we finally use. for (NSDictionary *storedMapping in storedMappings) { NJMapping *mapping = [[NJMapping alloc] initWithName:storedMapping[@"name"]]; [newMappings addObject:mapping]; } for (unsigned i = 0; i < storedMappings.count; ++i) { - NSDictionary *entries = storedMappings[i][@"entries"]; - NJMapping *mapping = newMappings[i]; - for (id key in entries) { - NJOutput *output = [NJOutput outputDeserialize:entries[key] - withMappings:newMappings]; - if (output) - mapping.entries[key] = output; - } + NJMapping *realMapping = [[NJMapping alloc] initWithSerialization:storedMappings[i] + mappings:newMappings]; + [newMappings[i] mergeEntriesFrom:realMapping]; } if (newMappings.count) { @@ -201,15 +203,8 @@ error:&error]; if (mapping && !error) { - BOOL conflict = NO; NJMapping *mergeInto = self[mapping.name]; - for (id key in mapping.entries) { - if (mergeInto.entries[key] - && ![mergeInto.entries[key] isEqual:mapping.entries[key]]) { - conflict = YES; - break; - } - } + BOOL conflict = [mergeInto hasConflictWith:mapping]; if (conflict) { NSAlert *conflictAlert = [[NSAlert alloc] init]; @@ -230,7 +225,7 @@ } if (mergeInto) { - [mergeInto.entries addEntriesFromDictionary:mapping.entries]; + [mergeInto mergeEntriesFrom:mapping]; mapping = mergeInto; } else { [_mappings addObject:mapping];