summaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-22 17:07:46 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-22 17:35:44 (EDT)
commit8a0e4c830fea4ffa3eaaed370be3b2256cfa925a (patch)
tree8b4eac713c88b2e557f610051201784d0f7c608d /src/map.c
parenta6058a0a36c6e1e50af9fa6c850d380194c8d925 (diff)
downloaddodge-balls-8a0e4c830fea4ffa3eaaed370be3b2256cfa925a.zip
dodge-balls-8a0e4c830fea4ffa3eaaed370be3b2256cfa925a.tar.gz
dodge-balls-8a0e4c830fea4ffa3eaaed370be3b2256cfa925a.tar.bz2
db_tileset_new(): New function
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/src/map.c b/src/map.c
index 123491b..3e7c0e3 100644
--- a/src/map.c
+++ b/src/map.c
@@ -24,18 +24,22 @@
#include "defs.h"
#include "dirs.h"
#include "map.h"
+#include "tileset.h"
#include "output.h"
#include "xml.h"
struct db_map {
- int w;
- int h;
- int tw;
- int th;
- Uint8 bg_r;
- Uint8 bg_g;
- Uint8 bg_b;
- int fr;
+ char *game_id;
+ int w;
+ int h;
+ int tw;
+ int th;
+ Uint8 bg_r;
+ Uint8 bg_g;
+ Uint8 bg_b;
+ int fr;
+ struct db_tileset *tileset_head;
+ struct db_tileset *tileset_tail;
};
static char *
@@ -207,6 +211,8 @@ _db_tmx_map_el_start(void *pv, const char *name, const char **attr)
{
XML_Parser p;
struct db_map *map;
+ int firstgid;
+ char *source;
db_dbg(" <%s> (map child)", name);
@@ -217,7 +223,19 @@ _db_tmx_map_el_start(void *pv, const char *name, const char **attr)
db_xml_node_push(p, map, _db_tmx_property_start,
_db_tmx_properties_end, NULL);
} else if (db_xml_check_tag(name, "tileset")) {
- /* TODO: attr */
+ db_xml_get_int_attr(p, attr, "firstgid", &firstgid, 1);
+ db_xml_get_string_attr(p, attr, "source", &source, 1);
+ db_dbg(" Tileset: <%s>", source);
+ map->tileset_tail = db_tileset_new(map->game_id, source,
+ firstgid, map->tileset_tail);
+ if (map->tileset_head == NULL) {
+ map->tileset_head = map->tileset_tail;
+ }
+ free(source);
+ if (map->tileset_tail == NULL) {
+ XML_StopParser(p, XML_FALSE);
+ return;
+ }
db_xml_node_push(p, map, _db_tmx_invalid_start,
_db_tmx_tileset_end, NULL);
} else if (db_xml_check_tag(name, "layer")) {
@@ -336,8 +354,16 @@ db_map_new(const char *game_id, const char *level_id)
return NULL;
}
+ map->game_id = strdup(game_id);
+ if (map->game_id == NULL) {
+ db_err("Failed to allocate memory");
+ free(map);
+ return NULL;
+ }
+
p = XML_ParserCreate(NULL);
if (p == NULL) {
+ free(map->game_id);
free(map);
return NULL;
}
@@ -349,6 +375,7 @@ db_map_new(const char *game_id, const char *level_id)
db_xml_node_pop(p);
XML_ParserFree(p);
free(path);
+ free(map->game_id);
free(map);
return NULL;
}
@@ -358,6 +385,7 @@ db_map_new(const char *game_id, const char *level_id)
db_xml_node_pop(p);
XML_ParserFree(p);
free(path);
+ free(map->game_id);
free(map);
return NULL;
}
@@ -368,6 +396,7 @@ db_map_new(const char *game_id, const char *level_id)
XML_ParserFree(p);
free(path);
fclose(fp);
+ free(map->game_id);
free(map);
return NULL;
}
@@ -386,6 +415,7 @@ db_map_new(const char *game_id, const char *level_id)
db_xml_node_pop(p);
XML_ParserFree(p);
fclose(fp);
+ free(map->game_id);
free(map);
return NULL;
}