foo
[vrlugburz] / src / tileset.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <alloca.h>
5 #include "treestore.h"
6 #include "tileset.h"
7 #include "level.h"
8 #include "fs.h"
9
10 int load_tileset(struct tileset *tset, const char *fname)
11 {
12         struct ts_node *ts, *node, *iter;
13         const char *str;
14         char *path;
15         struct mesh *mesh;
16
17         if(!(ts = ts_load(fname))) {
18                 fprintf(stderr, "failed to load tileset: %s\n", fname);
19                 return -1;
20         }
21         if(strcmp(ts->name, "tileset") != 0) {
22                 fprintf(stderr, "invalid or corrupted tileset file: %s\n", fname);
23                 ts_free_tree(ts);
24                 return -1;
25         }
26
27         if(!(str = ts_get_attr_str(ts, "file", 0))) {
28                 fprintf(stderr, "tileset %s is missing the file attribute\n", fname);
29                 ts_free_tree(ts);
30                 return -1;
31         }
32         path = alloca(strlen(fname) + strlen(str) + 2);
33         path_dir(str, path);
34         combine_path(path, str, path);
35
36         if(load_scenefile(&tset->scn, path) == -1) {
37                 fprintf(stderr, "tileset %s: failed to load scene file: %s\n", fname, path);
38                 ts_free_tree(ts);
39                 return -1;
40         }
41
42         tset->name = strdup(ts_get_attr_str(ts, "name", fname));
43
44         iter = ts->child_list;
45         while(node) {
46                 node = iter;
47                 iter = iter->next;
48                 if(strcmp(node->name, "tile") == 0) {
49                         if(!(str = ts_get_attr_str(node, "prefix", 0))) {
50                                 continue;
51                         }
52                         if(!(mesh = find_mesh_prefix(&tset->scn, str))) {
53                                 fprintf(stderr, "load_tileset: failed to find mesh with prefix: %s\n", str);
54                                 continue;
55                         }
56                         /* TOOD cont */
57                 }
58         }
59
60         return 0;
61 }