22 |
*/ |
*/ |
23 |
|
|
24 |
#include <Foundation/NSDictionary.h> |
#include <Foundation/NSDictionary.h> |
25 |
|
#include <Foundation/NSString.h> |
26 |
|
#include <Foundation/NSException.h> |
27 |
|
|
28 |
|
#include "Map/MapDisplay.h" |
29 |
#include "Map/MapLoader.h" |
#include "Map/MapLoader.h" |
30 |
|
|
31 |
/** |
/** |
45 |
|
|
46 |
@implementation MapLoader |
@implementation MapLoader |
47 |
|
|
48 |
+ (void) loadMap: (NSString *)mapName |
+ (MapDisplay *) loadMap: (NSString *)mapName |
|
to: (MapDisplay *)terrain |
|
49 |
{ |
{ |
50 |
NSParameterAssert (mapName); |
NSParameterAssert (mapName); |
51 |
NSParameterAssert ([mapName length] != 0); |
NSParameterAssert ([mapName length] != 0); |
|
NSAssert (terrain, @"terrain no instanciate\n"); |
|
52 |
|
|
53 |
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile: mapName]; |
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile: mapName]; |
54 |
|
|
55 |
int seaLevel = [[dic objectForKey: @"seaLevel"] intValue]; |
/* FIXME - sould store the objects of the map */ |
|
|
|
|
// FIXME sould store the objects of the map |
|
56 |
|
|
57 |
[terrain initWithMapImageName: [dic objectForKey: @"terrain"] |
NSString *path = [mapName stringByDeletingLastPathComponent]; |
58 |
colorsImageName: [dic objectForKey: @"colors"] |
NSString *terrainName |
59 |
shadowsImageName: [dic objectForKey: @"shadows"] |
= [path stringByAppendingPathComponent: [dic objectForKey: @"terrain"]]; |
60 |
texturesImageName: [dic objectForKey: @"textures"]]; |
NSString *colorsName |
61 |
|
= [path stringByAppendingPathComponent: [dic objectForKey: @"colors"]]; |
62 |
|
NSString *shadowsName |
63 |
|
= [path stringByAppendingPathComponent: [dic objectForKey: @"shadows"]]; |
64 |
|
NSString *texturesName |
65 |
|
= [path stringByAppendingPathComponent: [dic objectForKey: @"textures"]]; |
66 |
|
|
67 |
|
MapDisplay *map = [MapDisplay alloc]; |
68 |
|
[map initWithMapImageName: terrainName |
69 |
|
colorsImageName: colorsName |
70 |
|
shadowsImageName: shadowsName |
71 |
|
texturesImageName: texturesName]; |
72 |
|
|
73 |
[terrain setSeaLevel: (u_int8_t)seaLevel]; |
[map setSeaLevel: [[dic objectForKey: @"seaLevel"] intValue]]; |
74 |
|
|
75 |
|
return map; |
76 |
} |
} |
77 |
|
|
78 |
@end |
@end |