X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flevel_subset.cpp;h=9d1b246b64bb44b90e9d8119737db2bb4abd64a3;hb=5e12121c11b1f2b6fe32fa285a6a40eece80fa91;hp=19edf4772766d1d00fe400717b609b78e889b856;hpb=5a542dea3c6043703683b68fcaa774f6cb0d9127;p=supertux.git diff --git a/src/level_subset.cpp b/src/level_subset.cpp index 19edf4772..9d1b246b6 100644 --- a/src/level_subset.cpp +++ b/src/level_subset.cpp @@ -30,6 +30,8 @@ #include "app/globals.h" #include "video/surface.h" #include "level_subset.h" +#include "lisp/parser.h" +#include "lisp/lisp.h" using namespace SuperTux; @@ -63,27 +65,19 @@ void LevelSubset::create(const std::string& subset_name) void LevelSubset::read_info_file(const std::string& info_file) { - lisp_object_t* root_obj = lisp_read_from_file(info_file); - if (root_obj == NULL) - return; - lisp_object_t* cur = lisp_car(root_obj); + lisp::Parser parser; + std::auto_ptr root (parser.parse(info_file)); - if (lisp_symbol_p(cur) && strcmp(lisp_symbol(cur), "supertux-level-subset") == 0) - { - LispReader reader(lisp_cdr(root_obj)); + const lisp::Lisp* info = root->get_lisp("supertux-level-subset"); + if(!info) + throw std::runtime_error("File is not a levelsubset file"); - reader.read_string("title", title, true); - reader.read_string("description", description, true); - reader.read_string_vector("levels", levels); - hide_from_contribs = false; - reader.read_bool("hide-from-contribs", hide_from_contribs); - } - else - { - std::cout << "LevelSubset: parse error in info file: " << info_file << std::endl; - } + hide_from_contribs = false; - lisp_free(root_obj); + info->get("title", title); + info->get("description", description); + info->get_vector("levels", levels); + info->get("hide-from-contribs", hide_from_contribs); } void LevelSubset::load(const std::string& subset) @@ -99,8 +93,22 @@ void LevelSubset::load(const std::string& subset) msg << "Couldn't find level subset '" << subset << "'."; throw new std::runtime_error(msg.str()); } - - read_info_file(filename); + + try { + read_info_file(filename); + } catch(std::exception& e) { + std::stringstream msg; + msg << "Couldn't parse info file '" << filename << "': " << e.what(); + throw new std::runtime_error(msg.str()); + } + + // test is a worldmap exists + has_worldmap = false; + std::string worldmap = get_resource_filename( + std::string("levels/") + subset + "/worldmap.stwm"); + if(worldmap != "") { + has_worldmap = true; + } if (levels.empty()) { // Level info file doesn't define any levels, so read the @@ -175,6 +183,12 @@ LevelSubset::get_level_filename(unsigned int num) return levels[num]; } +std::string +LevelSubset::get_worldmap_filename() +{ + return std::string("/levels/" + name + "/worldmap.stwm"); +} + int LevelSubset::get_num_levels() const {