54 doc = xmlReadFile( _filename, NULL, 0 );
60 memset( result, 0,
sizeof (
TmxMap ) );
62 xmlNode *root_element = NULL;
63 xmlNode *cur_node = NULL;
65 root_element = xmlDocGetRootElement(doc);
67 for (cur_node = root_element; cur_node; cur_node = cur_node->next) {
68 if (cur_node->type == XML_ELEMENT_NODE) {
69 if ( strcmp( cur_node->name,
"map" ) == 0 ) {
70 struct _xmlAttr * properties = cur_node->properties;
72 if ( properties->type == XML_ATTRIBUTE_NODE ) {
73 xmlChar* value = xmlNodeListGetString(cur_node->doc, properties->children, 1);
74 if ( strcmp( properties->name,
"version") == 0 ) {
75 result->
version = strdup( value );
76 }
else if ( strcmp( properties->name,
"tiledVersion") == 0 ) {
78 }
else if ( strcmp( properties->name,
"orientation") == 0 ) {
79 if ( strcmp( value,
"orthogonal" ) == 0 ) {
81 }
else if ( strcmp( value,
"isometric" ) == 0 ) {
83 }
else if ( strcmp( value,
"staggered" ) == 0 ) {
85 }
else if ( strcmp( value,
"hexagonal" ) == 0 ) {
88 }
else if ( strcmp( properties->name,
"renderorder") == 0 ) {
89 if ( strcmp( value,
"right-down" ) == 0 ) {
91 }
else if ( strcmp( value,
"right-up" ) == 0 ) {
93 }
else if ( strcmp( value,
"left-down" ) == 0 ) {
95 }
else if ( strcmp( value,
"left-up" ) == 0 ) {
98 }
else if ( strcmp( properties->name,
"width") == 0 ) {
99 result->
width = atoi( value );
100 }
else if ( strcmp( properties->name,
"height") == 0 ) {
101 result->
height = atoi( value );
102 }
else if ( strcmp( properties->name,
"tilewidth") == 0 ) {
104 }
else if ( strcmp( properties->name,
"tileheight") == 0 ) {
106 }
else if ( strcmp( properties->name,
"infinite") == 0 ) {
108 }
else if ( strcmp( properties->name,
"nextlayerid") == 0 ) {
110 }
else if ( strcmp( properties->name,
"nextobjectid") == 0 ) {
115 properties = properties->next;
118 xmlNode * child = cur_node->children;
121 if ( strcmp( child->name,
"tileset" ) == 0 ) {
126 struct _xmlAttr * properties = child->properties;
127 while( properties ) {
128 if ( properties->type == XML_ATTRIBUTE_NODE ) {
129 xmlChar* value = xmlNodeListGetString(child->doc, properties->children, 1);
130 if ( strcmp( properties->name,
"source") == 0 ) {
132 }
if ( strcmp( properties->name,
"firstgid") == 0 ) {
133 firstgid = atoi( value );
137 properties = properties->next;
142 char * filename = strdup( _filename );
143 char * filenameWithPath =
malloc( 1024 );
144 memset( filenameWithPath, 0, 1024 );
145 char * separator = strrchr( filename,
'/' );
148 strcopy( filenameWithPath, filename );
150 strcat( filenameWithPath,
source );
161 while( actual->
next ) {
162 actual = actual->
next;
164 actual->
next = tileset;
169 }
else if ( strcmp( child->name,
"layer" ) == 0 ) {
172 memset( layer, 0,
sizeof(
TmxLayer ) );
174 struct _xmlAttr * properties = child->properties;
175 while( properties ) {
176 if ( properties->type == XML_ATTRIBUTE_NODE ) {
177 xmlChar* value = xmlNodeListGetString(child->doc, properties->children, 1);
178 if ( strcmp( properties->name,
"name") == 0 ) {
179 layer->
name = strdup( value );
180 }
if ( strcmp( properties->name,
"width") == 0 ) {
181 layer->
width = atoi( value );
182 }
if ( strcmp( properties->name,
"height") == 0 ) {
183 layer->
height = atoi( value );
184 }
if ( strcmp( properties->name,
"id") == 0 ) {
185 layer->
id = atoi( value );
189 properties = properties->next;
192 xmlNode * rechild = child->children;
195 if ( strcmp( rechild->name,
"data" ) == 0 ) {
198 memset( layer->
data, 0, layer->
width * layer->
height *
sizeof(
int ) );
200 char * content = (
char*)xmlNodeGetContent( rechild->children );
206 char valueString[32];
207 memset( valueString, 0, 32 );
214 if ( (c <
'0') || (c >
'9') ) {
219 if ( (c <
'0') || (c >
'9') ) {
227 int value = atoi( valueString );
228 layer->
data[step] = value;
235 rechild = rechild->next;
243 while( actual->
next ) {
244 actual = actual->
next;
246 actual->
next = layer;