summary refs log tree commit diff stats
path: root/libs/cocos2d/CCTMXXMLParser.h
blob: 18d7a8addbf8f3fcece595f880309112a7c0ae97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * cocos2d for iPhone: http://www.cocos2d-iphone.org
 *
 * Copyright (c) 2009-2010 Ricardo Quesada
 * Copyright (c) 2011 Zynga Inc.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 *
 * TMX Tiled Map support:
 * http://www.mapeditor.org
 *
 */

/*
 * Internal TMX parser
 *
 * IMPORTANT: These classed should not be documented using doxygen strings
 * since the user should not use them.
 *
 */
 

#import <Availability.h>
#import <Foundation/Foundation.h>

enum {
	TMXLayerAttribNone = 1 << 0,
	TMXLayerAttribBase64 = 1 << 1,
	TMXLayerAttribGzip = 1 << 2,
	TMXLayerAttribZlib = 1 << 3,
};

enum {
	TMXPropertyNone,
	TMXPropertyMap,
	TMXPropertyLayer,
	TMXPropertyObjectGroup,
	TMXPropertyObject,
	TMXPropertyTile
};

/* CCTMXLayerInfo contains the information about the layers like:
 - Layer name
 - Layer size
 - Layer opacity at creation time (it can be modified at runtime)
 - Whether the layer is visible (if it's not visible, then the CocosNode won't be created)
 
 This information is obtained from the TMX file.
 */
@interface CCTMXLayerInfo : NSObject
{
	NSString			*name_;
	CGSize				layerSize_;
	unsigned int		*tiles_;
	BOOL				visible_;
	unsigned char		opacity_;
	BOOL				ownTiles_;
	unsigned int		minGID_;
	unsigned int		maxGID_;
	NSMutableDictionary	*properties_;
	CGPoint				offset_;
}

@property (nonatomic,readwrite,retain)	NSString *name;
@property (nonatomic,readwrite)			CGSize layerSize;
@property (nonatomic,readwrite)			unsigned int *tiles;
@property (nonatomic,readwrite)			BOOL visible;
@property (nonatomic,readwrite)			unsigned char opacity;
@property (nonatomic,readwrite)			BOOL ownTiles;
@property (nonatomic,readwrite)			unsigned int minGID;
@property (nonatomic,readwrite)			unsigned int maxGID;
@property (nonatomic,readwrite,retain) NSMutableDictionary *properties;
@property (nonatomic,readwrite)			CGPoint offset;
@end

/* CCTMXTilesetInfo contains the information about the tilesets like:
 - Tileset name
 - Tilset spacing
 - Tileset margin
 - size of the tiles
 - Image used for the tiles
 - Image size
 
 This information is obtained from the TMX file. 
 */
@interface CCTMXTilesetInfo : NSObject
{
	NSString		*name_;
	unsigned int	firstGid_;
	CGSize			tileSize_;
	unsigned int	spacing_;
	unsigned int	margin_;
	
	// filename containing the tiles (should be spritesheet / texture atlas)
	NSString	*sourceImage_;
	
	// size in pixels of the image
	CGSize		imageSize_;
}
@property (nonatomic,readwrite,retain) NSString *name;
@property (nonatomic,readwrite,assign) unsigned int firstGid;
@property (nonatomic,readwrite,assign) CGSize tileSize;
@property (nonatomic,readwrite,assign) unsigned int spacing;
@property (nonatomic,readwrite,assign) unsigned int margin;
@property (nonatomic,readwrite,retain) NSString *sourceImage;
@property (nonatomic,readwrite,assign) CGSize imageSize;

-(CGRect) rectForGID:(unsigned int)gid;
@end

/* CCTMXMapInfo contains the information about the map like:
 - Map orientation (hexagonal, isometric or orthogonal)
 - Tile size
 - Map size
 
 And it also contains:
 - Layers (an array of TMXLayerInfo objects)
 - Tilesets (an array of TMXTilesetInfo objects)
 - ObjectGroups (an array of TMXObjectGroupInfo objects)
 
 This information is obtained from the TMX file.
 
 */
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
#if defined(__IPHONE_4_0)
@interface CCTMXMapInfo : NSObject <NSXMLParserDelegate>
#else
@interface CCTMXMapInfo : NSObject
#endif

#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
@interface CCTMXMapInfo : NSObject <NSXMLParserDelegate>
#endif
{	
	NSMutableString	*currentString;
    BOOL				storingCharacters;	
	int					layerAttribs;
	int					parentElement;
	unsigned int		parentGID_;

	
	// tmx filename
	NSString *filename_;

	// map orientation
	int	orientation_;	
	
	// map width & height
	CGSize	mapSize_;
	
	// tiles width & height
	CGSize	tileSize_;
	
	// Layers
	NSMutableArray *layers_;
	
	// tilesets
	NSMutableArray *tilesets_;
		
	// ObjectGroups
	NSMutableArray *objectGroups_;
	
	// properties
	NSMutableDictionary *properties_;
	
	// tile properties
	NSMutableDictionary *tileProperties_;
}

@property (nonatomic,readwrite,assign) int orientation;
@property (nonatomic,readwrite,assign) CGSize mapSize;
@property (nonatomic,readwrite,assign) CGSize tileSize;
@property (nonatomic,readwrite,retain) NSMutableArray *layers;
@property (nonatomic,readwrite,retain) NSMutableArray *tilesets;
@property (nonatomic,readwrite,retain) NSString *filename;
@property (nonatomic,readwrite,retain) NSMutableArray *objectGroups;
@property (nonatomic,readwrite,retain) NSMutableDictionary *properties;
@property (nonatomic,readwrite,retain) NSMutableDictionary *tileProperties;

/** creates a TMX Format with a tmx file */
+(id) formatWithTMXFile:(NSString*)tmxFile;
/** initializes a TMX format witha  tmx file */
-(id) initWithTMXFile:(NSString*)tmxFile;
@end