X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftitle.cpp;h=1e5449ef35c9bf9522262fc9167cf5c6ddcc0cce;hb=62ff7f7776875e9389d10ae2e7b6348e9e5cb9c7;hp=714f9bd0b5ec83bdb56406e4a7320167ed255f3d;hpb=6f801c22d97251799740317fb1d0caf2e744b321;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 714f9bd0b..1e5449ef3 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -41,11 +41,12 @@ #include "title.h" #include "video/screen.h" #include "video/surface.h" -#include "high_scores.h" #include "gui/menu.h" #include "timer.h" #include "special/frame_rate.h" #include "app/setup.h" +#include "lisp/lisp.h" +#include "lisp/parser.h" #include "level.h" #include "level_subset.h" #include "gameloop.h" @@ -127,13 +128,13 @@ void generate_contrib_menu() contrib_menu->additem(MN_HL,"",0,0); int i = 0; - for(std::set::iterator it = worldmap_list.begin(); it != worldmap_list.end(); ++it) - { + for(std::set::iterator it = worldmap_list.begin(); + it != worldmap_list.end(); ++it) { WorldMapNS::WorldMap worldmap; worldmap.loadmap((*it).c_str()); contrib_menu->additem(MN_ACTION, worldmap.get_world_title(),0,0, i); ++i; - } + } contrib_menu->additem(MN_HL,"",0,0); @@ -158,6 +159,25 @@ void generate_contrib_menu() level_subsets.clear(); } +std::string get_level_name(const std::string& filename) +{ + try { + lisp::Parser parser; + std::auto_ptr root (parser.parse(filename)); + + const lisp::Lisp* level = root->get_lisp("supertux-level"); + if(!level) + return ""; + + std::string name; + level->get("name", name); + return name; + } catch(std::exception& e) { + std::cerr << "Problem getting name of '" << filename << "'.\n"; + return ""; + } +} + void check_levels_contrib_menu() { static int current_subset = -1; @@ -214,35 +234,12 @@ void check_levels_contrib_menu() contrib_subset_menu->additem(MN_HL,"",0,0); for (int i = 0; i < subset.get_num_levels(); ++i) - { + { /** get level's title */ - std::string level_title = ""; - std::string filename = subset.get_level_filename(i); - std::string filepath; - filepath = st_dir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - filepath = datadir + "/levels/" + filename; - if (access(filepath.c_str(), R_OK) != 0) - { - std::cerr << "Error: Level: couldn't find level: " << filename << std::endl; - continue; - } - } - - LispReader* reader = LispReader::load(filepath, "supertux-level"); - if(!reader) - { - std::cerr << "Error: Could not open level file. Ignoring...\n"; - continue; - } - - reader->read_string("name", level_title, true); - delete reader; - - contrib_subset_menu->additem(MN_ACTION, level_title, 0, 0, i); - } + std::string title = get_level_name(filename); + contrib_subset_menu->additem(MN_ACTION, title, 0, 0, i); + } contrib_subset_menu->additem(MN_HL,"",0,0); contrib_subset_menu->additem(MN_BACK, _("Back"), 0, 0);