diff options
-rw-r--r-- | src/map.c | 152 |
1 files changed, 149 insertions, 3 deletions
@@ -35,6 +35,7 @@ struct db_map { Uint8 bg_r; Uint8 bg_g; Uint8 bg_b; + int fr; }; static char * @@ -84,8 +85,153 @@ _db_tmx_invalid_start(void *pv, const char *name, } static void XMLCALL +_db_tmx_property_end(void *pv, const char *name) +{ + XML_Parser p; + + db_dbg(" </%s> (property)", name); + + p = (XML_Parser) pv; + + if (db_xml_check_tag(name, "property")) { + db_xml_node_pop(p); + } else { + db_xml_unexpected_end_tag(p, name, "property"); + } +} + +static void XMLCALL +_db_tmx_property_start(void *pv, const char *name, const char **attr) +{ + XML_Parser p; + struct db_map *map; + char *p_name; + char *p_type; + + db_dbg(" <%s> (property)", name); + + p = (XML_Parser) pv; + map = db_xml_node_peek(p); + + if (db_xml_check_tag(name, "property")) { + db_xml_get_string_attr(p, attr, "name", &p_name, 1); + db_xml_get_string_attr(p, attr, "type", &p_type, 1); + if (strcmp(p_name, "framerate") == 0) { + if (strcmp(p_type, "int") != 0) { + db_err("Framerate must be an integer"); + free(p_name); + free(p_type); + XML_StopParser(p, XML_FALSE); + return; + } + db_xml_get_int_attr(p, attr, "value", &map->fr, 1); + db_dbg(" Framerate: %d", map->fr); + } else { + db_dbg("Skipping unknown property \"%s\"", p_name); + } + free(p_name); + free(p_type); + db_xml_node_push(p, map, _db_tmx_invalid_start, + _db_tmx_property_end, NULL); + } else { + db_xml_unexpected_start_tag(p, name, "property"); + } +} + +static void XMLCALL +_db_tmx_properties_end(void *pv, const char *name) +{ + XML_Parser p; + + db_dbg(" </%s> (properties)", name); + + p = (XML_Parser) pv; + + if (db_xml_check_tag(name, "properties")) { + db_xml_node_pop(p); + } else { + db_xml_unexpected_end_tag(p, name, "properties"); + } +} + +static void XMLCALL +_db_tmx_tileset_end(void *pv, const char *name) +{ + XML_Parser p; + + db_dbg(" </%s> (tileset)", name); + + p = (XML_Parser) pv; + + if (db_xml_check_tag(name, "tileset")) { + db_xml_node_pop(p); + } else { + db_xml_unexpected_end_tag(p, name, "tileset"); + } +} + +static void XMLCALL +_db_tmx_layer_end(void *pv, const char *name) +{ + XML_Parser p; + + db_dbg(" </%s> (layer)", name); + + p = (XML_Parser) pv; + + if (db_xml_check_tag(name, "layer")) { + db_xml_node_pop(p); + } else { + db_xml_unexpected_end_tag(p, name, "layer"); + } +} + +static void XMLCALL +_db_tmx_objectgroup_end(void *pv, const char *name) +{ + XML_Parser p; + + db_dbg(" </%s> (objectgroup)", name); + + p = (XML_Parser) pv; + + if (db_xml_check_tag(name, "objectgroup")) { + db_xml_node_pop(p); + } else { + db_xml_unexpected_end_tag(p, name, "objectgroup"); + } +} + +static void XMLCALL _db_tmx_map_el_start(void *pv, const char *name, const char **attr) { + XML_Parser p; + struct db_map *map; + + db_dbg(" <%s> (map child)", name); + + p = (XML_Parser) pv; + map = db_xml_node_peek(p); + + if (db_xml_check_tag(name, "properties")) { + 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_node_push(p, map, _db_tmx_invalid_start, + _db_tmx_tileset_end, NULL); + } else if (db_xml_check_tag(name, "layer")) { + /* TODO: data */ + db_xml_node_push(p, map, _db_tmx_invalid_start, + _db_tmx_layer_end, NULL); + } else if (db_xml_check_tag(name, "objectgroup")) { + /* TODO: object */ + db_xml_node_push(p, map, _db_tmx_invalid_start, + _db_tmx_objectgroup_end, NULL); + } else { + db_xml_unexpected_start_tag(p, name, + "properties, tileset, layer, or objectgroup"); + } } static void XMLCALL @@ -150,8 +296,8 @@ _db_tmx_map_start(void *pv, const char *name, const char **attr) XML_StopParser(p, XML_FALSE); return; } - db_dbg("Map size: %dx%d px", map->w, map->h); - db_dbg("Tile size: %dx%d px", map->tw, map->th); + db_dbg(" Map size: %dx%d px", map->w, map->h); + db_dbg(" Tile size: %dx%d px", map->tw, map->th); /* Get and check background color */ db_xml_get_string_attr(p, attr, "backgroundcolor", &backgroundcolor, 1); @@ -164,7 +310,7 @@ _db_tmx_map_start(void *pv, const char *name, const char **attr) map->bg_r = bg_r; map->bg_g = bg_g; map->bg_b = bg_b; - db_dbg("Map background color: (0x%02x, 0x%02x, 0x%02x)", + db_dbg(" Background color: (0x%02x, 0x%02x, 0x%02x)", map->bg_r, map->bg_g, map->bg_b); db_xml_node_push(p, map, _db_tmx_map_el_start, _db_tmx_map_end, NULL); |