Last active
August 29, 2015 14:05
-
-
Save alexispurslane/53faee46c8b572df4c74 to your computer and use it in GitHub Desktop.
A simple level creating DSL. I am kinda proud of myself for doing this. This little DSL will probably be expanded and given it's own GUI for The Outer Ring 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSDictionary *) readMap: (NSString *)content | |
| { | |
| content = [content stringByReplacingOccurrencesOfString:@"--------------------" withString:@""]; | |
| NSMutableArray *map1 = [@[] mutableCopy]; | |
| NSArray *array = [content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; | |
| NSMutableArray *arrayMut1 = [[NSMutableArray alloc] initWithArray:[self splitArrayWithArray:array rangeNumber:([array count] / 2)] copyItems:YES]; | |
| NSMutableArray *arrayMut = [NSMutableArray new]; | |
| for(NSArray *subarray in arrayMut1) { | |
| NSMutableArray *subCopy = [NSMutableArray new]; | |
| for (id item in subarray){ | |
| [subCopy addObject:[item copy]]; | |
| } | |
| [arrayMut addObject: subCopy]; | |
| } | |
| [arrayMut[1] removeObject:@""]; | |
| [arrayMut[1] addObject:arrayMut[2][0]]; | |
| [arrayMut removeObject:arrayMut[2]]; | |
| if (!content) { | |
| NSLog(@"Error reading level file."); | |
| } | |
| NSLog(@"%@", arrayMut); | |
| NSAssert([arrayMut[0] count] == ((NSString *)arrayMut[0][0]).length, @"Level expected to be of equal size and length."); | |
| //NSString *char = [content substringWithRange:NSMakeRange(0, 1)]; | |
| for (int i = 0; i < [arrayMut[0] count]; i++) { | |
| [map1 addObject:[[NSArray array] mutableCopy]]; | |
| } | |
| NSArray *arrayNMut = arrayMut[1]; | |
| arrayMut = arrayMut[0]; | |
| for (int i = 0; i < [arrayMut count]; i++) { | |
| for (int j = 0; j < [arrayMut[i] length]; j++) { | |
| NSString *charac = [arrayMut[i] substringWithRange:NSMakeRange(j, 1)]; | |
| if ([charac isEqual: @"."]) { | |
| [map1[i] addObject: self.tiles[0]]; | |
| } else if ([charac isEqual: @"#"]) { | |
| [map1[i] addObject: self.tiles[2]]; | |
| } else if ([charac isEqual: @"@"]) { | |
| [map1[i] addObject: self.tiles[1]]; | |
| } | |
| } | |
| } | |
| NSMutableArray *map2 = [NSMutableArray array]; | |
| for (int i = 0; i < [arrayNMut count]; i++) { | |
| [map2 addObject:[[NSArray array] mutableCopy]]; | |
| } | |
| for (int i = 0; i < [arrayNMut count]; i++) { | |
| for (int j = 0; j < [arrayNMut[i] length]; j++) { | |
| NSString *charac = [arrayNMut[i] substringWithRange:NSMakeRange(j, 1)]; | |
| if ([charac isEqual: @"."]) { | |
| [map2[i] addObject: self.tiles[0]]; | |
| } else if ([charac isEqual: @"#"]) { | |
| [map2[i] addObject: self.tiles[2]]; | |
| } else if ([charac isEqual: @"@"]) { | |
| [map2[i] addObject: self.tiles[1]]; | |
| } | |
| } | |
| } | |
| NSLog(@"map2: %@", map2); | |
| return @{ | |
| @"mutableMap": map1, | |
| @"map": [NSArray arrayWithArray: map2] | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment