diff options
-rw-r--r-- | src/map.c | 71 |
1 files changed, 67 insertions, 4 deletions
@@ -16,16 +16,25 @@ * You should have received a copy of the GNU General Public License * along with Dodge Balls. If not, see <http://www.gnu.org/licenses/>. */ + #include <expat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "defs.h" #include "dirs.h" #include "map.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; }; static char * @@ -75,6 +84,11 @@ _db_tmx_invalid_start(void *pv, const char *name, } static void XMLCALL +_db_tmx_map_el_start(void *pv, const char *name, const char **attr) +{ +} + +static void XMLCALL _db_tmx_map_end(void *pv, const char *name) { XML_Parser p; @@ -91,11 +105,16 @@ _db_tmx_map_end(void *pv, const char *name) } static void XMLCALL -_db_tmx_map_start(void *pv, const char *name, - const char **attr __attribute__((__unused__))) +_db_tmx_map_start(void *pv, const char *name, const char **attr) { - XML_Parser p; + XML_Parser p; struct db_map *map; + char *orientation; + char *renderorder; + char *backgroundcolor; + unsigned int bg_r; + unsigned int bg_g; + unsigned int bg_b; db_dbg(" <%s> (map)", name); @@ -103,7 +122,51 @@ _db_tmx_map_start(void *pv, const char *name, map = db_xml_node_peek(p); if (db_xml_check_tag(name, "map")) { - db_xml_node_push(p, map, _db_tmx_invalid_start, + /* Check orientation */ + db_xml_get_string_attr(p, attr, "orientation", &orientation, 1); + if (strcmp(orientation, "orthogonal") != 0) { + db_err("Map must be orthogonal"); + XML_StopParser(p, XML_FALSE); + return; + } + free(orientation); + /* Check render order */ + db_xml_get_string_attr(p, attr, "renderorder", &renderorder, 1); + if (strcmp(renderorder, "right-down") != 0) { + db_err("Map must be rendered right-down"); + XML_StopParser(p, XML_FALSE); + return; + } + free(renderorder); + /* Get and check size */ + db_xml_get_int_attr(p, attr, "width", &map->w, 1); + db_xml_get_int_attr(p, attr, "height", &map->h, 1); + db_xml_get_int_attr(p, attr, "tilewidth", &map->tw, 1); + db_xml_get_int_attr(p, attr, "tileheight", &map->th, 1); + if (map->w * map->tw != DB_WINDOW_W || + map->h * map->th != DB_WINDOW_H) { + db_err("Map size must be %dx%d px", + DB_WINDOW_W, DB_WINDOW_H); + 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); + /* Get and check background color */ + db_xml_get_string_attr(p, attr, "backgroundcolor", + &backgroundcolor, 1); + if (sscanf(backgroundcolor, "#%02x%02x%02x", + &bg_r, &bg_g, &bg_b) != 3) { + db_err("Background color must be \"#xxxxxx\""); + XML_StopParser(p, XML_FALSE); + return; + } + 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)", + 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); } else { db_xml_unexpected_start_tag(p, name, "map"); |