X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJMapping.m;h=1b05c424bfe708ab23698b07448ffea79c368eec;hp=355dbccdf58951959b52f630ad841665626ccea7;hb=baa03e73a5af66b725f58fa5efd04bf54b7b2eed;hpb=93c9d4bc39c6addbab6dbc7878d3684e42bbdc01 diff --git a/Classes/NJMapping.m b/Classes/NJMapping.m index 355dbcc..1b05c42 100644 --- a/Classes/NJMapping.m +++ b/Classes/NJMapping.m @@ -17,23 +17,29 @@ // Extra checks during initialization because the data is often loaded // from untrusted serializations. -- (id)initWithName:(NSString *)name { +- (id)init { if ((self = [super init])) { - self.name = [name isKindOfClass:NSString.class] ? name : @"Untitled"; + self.name = NSLocalizedString(@"Untitled", @"name for new mappings"); _entries = [[NSMutableDictionary alloc] init]; } return self; } -- (id)initWithSerialization:(NSDictionary *)serialization - mappings:(NSArray *)mappings { +- (id)initWithName:(NSString *)name { + if ((self = [self init])) { + if ([name isKindOfClass:NSString.class]) + self.name = name; + } + return self; +} + +- (id)initWithSerialization:(NSDictionary *)serialization { if ((self = [self initWithName:serialization[@"name"]])) { NSDictionary *entries = serialization[@"entries"]; if ([entries isKindOfClass:NSDictionary.class]) { for (id key in entries) { if ([key isKindOfClass:NSString.class]) { - NJOutput *output = [NJOutput outputDeserialize:entries[key] - withMappings:mappings]; + NJOutput *output = [NJOutput outputWithSerialization:entries[key]]; if (output) _entries[key] = output; } @@ -92,11 +98,13 @@ return NO; } -+ (id)mappingWithContentsOfURL:(NSURL *)url mappings:(NSArray *)mappings error:(NSError **)error { ++ (id)mappingWithContentsOfURL:(NSURL *)url error:(NSError **)error { NSInputStream *stream = [NSInputStream inputStreamWithURL:url]; [stream open]; NSDictionary *serialization = stream && !*error - ? [NSJSONSerialization JSONObjectWithStream:stream options:0 error:error] + ? [NSJSONSerialization JSONObjectWithStream:stream + options:(NSJSONReadingOptions)0 + error:error] : nil; [stream close]; @@ -108,12 +116,12 @@ && [serialization[@"entries"] isKindOfClass:NSDictionary.class])) { *error = [NSError errorWithDomain:@"Enjoyable" code:0 - description:@"This isn't a valid mapping file."]; + description:NSLocalizedString(@"invalid mapping file", + @"error when imported file was JSON but not a mapping")]; return nil; } - return [[NJMapping alloc] initWithSerialization:serialization - mappings:mappings]; + return [[NJMapping alloc] initWithSerialization:serialization]; } - (void)mergeEntriesFrom:(NJMapping *)other { @@ -121,4 +129,10 @@ [_entries addEntriesFromDictionary:other->_entries]; } +- (void)postLoadProcess:(id )allMappings { + for (NJOutput *o in _entries.allValues) + [o postLoadProcess:allMappings]; +} + + @end