struct cell *cell;
float *vecptr;
const char *str;
+ char *tset_path;
if(!(ts = ts_load(fname))) {
fprintf(stderr, "failed to load level: %s\n", fname);
lvl->fname = strdup(fname);
if((lvl->dirname = malloc(strlen(fname) + 1))) {
-#ifndef LEVEL_EDITOR
path_dir(lvl->fname, lvl->dirname);
-#endif
}
lvl->cell_size = ts_get_attr_num(ts, "cellsize", DEF_CELL_SIZE);
}
if((str = ts_get_attr_str(ts, "tileset", 0))) {
- lvl->tset = get_tileset(str);
+ tset_path = alloca(strlen(str) + strlen(lvl->dirname) + 2);
+ combine_path(lvl->dirname, str, tset_path);
+ lvl->tset = get_tileset(tset_path);
}
iter = ts->child_list;
tiletype = detect_cell_tile(lvl, j, i, &cell->tilerot);
}
- cell->tile = get_tile(lvl->tset, tiletype);
-
+ if(lvl->tset) {
+ cell->tile = get_tile(lvl->tset, tiletype);
+ }
cell++;
}
}
int load_tileset(struct tileset *tset, const char *fname)
{
struct ts_node *ts, *node, *iter;
- const char *str;
+ const char *str, *prefix;
char *path;
struct mesh *mesh;
struct tile *tile;
return -1;
}
path = alloca(strlen(fname) + strlen(str) + 2);
- path_dir(str, path);
+ path_dir(fname, path);
combine_path(path, str, path);
if(load_scenefile(&tset->scn, path) == -1) {
tset->name = strdup(ts_get_attr_str(ts, "name", fname));
iter = ts->child_list;
- while(node) {
+ while(iter) {
node = iter;
iter = iter->next;
if(strcmp(node->name, "tile") == 0) {
- if(!(str = ts_get_attr_str(node, "prefix", 0))) {
+ if(!(prefix = ts_get_attr_str(node, "prefix", 0))) {
continue;
}
- if((type = tile_type(ts_get_attr_str(node, "type", 0))) == -1) {
- fprintf(stderr, "load_tileset: missing or invalid tile type\n");
+ if(!(str = ts_get_attr_str(node, "type", 0))) {
+ fprintf(stderr, "load_tileset: missing tile type\n");
+ continue;
+ }
+ if((type = tile_type(str)) == -1) {
+ fprintf(stderr, "load_tileset: invalid tile type: %s\n", str);
continue;
}
mesh = tset->scn.meshlist;
while(mesh) {
- if(match_prefix(mesh->name, str)) {
+ if(mesh->name && match_prefix(mesh->name, prefix)) {
if(vec) {
xform_mesh(mesh, xform);
}
}
mesh = mesh->next;
}
+
+ tile->next = tset->tiles;
+ tset->tiles = tile;
}
}