X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftileset.c;fp=src%2Ftileset.c;h=53a3d38683a7f480c2ea2c4051d2d996bfae773f;hb=7a1a5aa446fcf3d2b0bb26f6f7465e4f3d116e47;hp=0000000000000000000000000000000000000000;hpb=8c3ae60742d38e2dbcd9811b16966933df0a5c29;p=vrlugburz diff --git a/src/tileset.c b/src/tileset.c new file mode 100644 index 0000000..53a3d38 --- /dev/null +++ b/src/tileset.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include "treestore.h" +#include "tileset.h" +#include "level.h" + +int load_tileset(struct tileset *tset, const char *fname) +{ + struct ts_node *ts, *node; + const char *str; + char *path; + + if(!(ts = ts_load(fname))) { + fprintf(stderr, "failed to load tileset: %s\n", fname); + return -1; + } + if(strcmp(ts->name, "tileset") != 0) { + fprintf(stderr, "invalid or corrupted tileset file: %s\n", fname); + ts_free_tree(ts); + return -1; + } + + if(!(str = ts_get_attr_str(ts, "file", 0))) { + fprintf(stderr, "tileset %s is missing the file attribute\n", fname); + ts_free_tree(ts); + return -1; + } + path = alloca(strlen(fname) + strlen(str) + 2); + path_dir(str, path); + combine_path(path, str, path); + + if(load_scenefile(&tset->scn, path) == -1) { + fprintf(stderr, "tileset %s: failed to load scene file: %s\n", fname, path); + ts_free_tree(ts); + return -1; + } + + tset->name = strdup(ts_get_attr_str(ts, "name", fname)); +}