for (int i = 0; i < subset.get_num_levels(); ++i)
{
- Level* level = new Level;
- level->load(subset.get_level_filename(i));
- contrib_subset_menu->additem(MN_ACTION, level->get_name(), 0, 0, i);
- delete level;
+ /** get level's title */
+ std::string level_title = "<no title>";
+
+ LispReader* reader = LispReader::load(subset.get_level_filename(i), "supertux-level");
+ if(!reader)
+ {
+ std::cerr << "Error: Could not open level file. Ignoring...\n";
+ return;
+ }
+
+ reader->read_string("name", level_title, true);
+ delete reader;
+
+ contrib_subset_menu->additem(MN_ACTION, level_title, 0, 0, i);
}
contrib_subset_menu->additem(MN_HL,"",0,0);
/** get level's title */
level.title = "<no title>";
- FILE * fi;
- lisp_object_t* root_obj = 0;
- fi = fopen((datadir + "/levels/" + level.name).c_str(), "r");
- if (fi == NULL)
- {
- perror((datadir + "/levels/" + level.name).c_str());
+ LispReader* reader = LispReader::load(datadir + "/levels/" + level.name, "supertux-level");
+ if(!reader)
+ {
+ std::cerr << "Error: Could not open level file. Ignoring...\n";
return;
- }
-
- lisp_stream_t stream;
- lisp_stream_init_file (&stream, fi);
- root_obj = lisp_read (&stream);
-
- if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
- {
- printf("World: Parse Error in file %s", level.name.c_str());
- }
-
- if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
- {
- LispReader reader(lisp_cdr(root_obj));
- reader.read_string("name", level.title, true);
- }
-
- lisp_free(root_obj);
+ }
- fclose(fi);
+ reader->read_string("name", level.title, true);
+ delete reader;
}
void