1 // $Id: level_subset.cpp 3118 2006-03-25 17:29:08Z sommer $
4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "file_system.hpp"
28 #include "lisp/parser.hpp"
29 #include "lisp/lisp.hpp"
30 #include "physfs/physfs_stream.hpp"
31 #include "script_manager.hpp"
32 #include "scripting/wrapper_util.hpp"
35 static bool has_suffix(const std::string& data, const std::string& suffix)
37 if (data.length() >= suffix.length())
38 return data.compare(data.length() - suffix.length(), suffix.length(), suffix) == 0;
46 hide_from_contribs = false;
54 World::load(const std::string& filename)
56 basedir = FileSystem::dirname(filename);
59 std::auto_ptr<lisp::Lisp> root (parser.parse(filename));
61 const lisp::Lisp* info = root->get_lisp("supertux-world");
63 info = root->get_lisp("supertux-level-subset");
65 throw std::runtime_error("File is not a world or levelsubset file");
67 hide_from_contribs = false;
70 info->get("title", title);
71 info->get("description", description);
72 info->get("levelset", is_levelset);
73 info->get_vector("levels", levels);
74 info->get("hide-from-contribs", hide_from_contribs);
76 // Level info file doesn't define any levels, so read the
77 // directory to see what we can find
79 std::string path = basedir + "/";
80 char** files = PHYSFS_enumerateFiles(path.c_str());
82 msg_warning << "Couldn't read subset dir '" << path << "'" << std::endl;
86 for(const char* const* filename = files; *filename != 0; ++filename) {
87 if(has_suffix(*filename, ".stl")) {
88 levels.push_back(path + *filename);
91 PHYSFS_freeList(files);
97 std::string filename = basedir + "/world.nut";
98 std::cout << filename << std::endl;
99 if (!PHYSFS_exists(filename.c_str()))
102 IFileStream in(filename);
104 HSQUIRRELVM vm = script_manager->create_thread();
105 Scripting::compile_and_run(vm, in, filename);
109 World::get_level_filename(unsigned int i) const
115 World::get_num_levels() const
117 return levels.size();