2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "lisp/parser.hpp"
20 #include "lisp/writer.hpp"
21 #include "physfs/ifile_streambuf.hpp"
22 #include "scripting/serialize.hpp"
23 #include "scripting/squirrel_util.hpp"
24 #include "supertux/gameconfig.hpp"
25 #include "supertux/globals.hpp"
26 #include "supertux/player_status.hpp"
27 #include "supertux/screen_fade.hpp"
28 #include "supertux/screen_manager.hpp"
29 #include "supertux/world.hpp"
30 #include "supertux/savegame.hpp"
31 #include "util/file_system.hpp"
32 #include "util/reader.hpp"
33 #include "util/string_util.hpp"
34 #include "worldmap/worldmap.hpp"
36 std::unique_ptr<World>
37 World::load(const std::string& directory)
39 std::unique_ptr<World> world(new World);
41 world->load_(directory);
43 { // generate savegame filename
44 std::string worlddirname = FileSystem::basename(directory);
45 std::ostringstream stream;
46 stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
47 std::string slotfile = stream.str();
48 world->m_savegame_filename = stream.str();
51 return std::move(world);
56 m_worldmap_filename(),
57 m_savegame_filename(),
60 m_hide_from_contribs(false),
70 World::load_(const std::string& directory)
72 m_basedir = directory;
73 m_worldmap_filename = m_basedir + "/worldmap.stwm";
76 const lisp::Lisp* root = parser.parse(m_basedir + "/info");
78 const lisp::Lisp* info = root->get_lisp("supertux-world");
80 info = root->get_lisp("supertux-level-subset");
82 throw std::runtime_error("File is not a world or levelsubset file");
84 m_hide_from_contribs = false;
87 info->get("title", m_title);
88 info->get("description", m_description);
89 info->get("levelset", m_is_levelset);
90 info->get("hide-from-contribs", m_hide_from_contribs);
94 World::get_basedir() const
100 World::get_title() const