Removed obsolete comment
[supertux.git] / src / supertux / world.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #include <algorithm>
18
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"
35
36 std::unique_ptr<World>
37 World::load(const std::string& directory)
38 {
39   std::unique_ptr<World> world(new World);
40
41   world->load_(directory);
42
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();
49   }
50
51   return std::move(world);
52 }
53
54 World::World() :
55   m_basedir(),
56   m_worldmap_filename(),
57   m_savegame_filename(),
58   m_title(),
59   m_description(),
60   m_hide_from_contribs(false),
61   m_is_levelset(true)
62 {
63 }
64
65 World::~World()
66 {
67 }
68
69 void
70 World::load_(const std::string& directory)
71 {
72   m_basedir = directory;
73   m_worldmap_filename = m_basedir + "/worldmap.stwm";
74
75   lisp::Parser parser;
76   const lisp::Lisp* root = parser.parse(m_basedir + "/info");
77
78   const lisp::Lisp* info = root->get_lisp("supertux-world");
79   if(info == NULL)
80     info = root->get_lisp("supertux-level-subset");
81   if(info == NULL)
82     throw std::runtime_error("File is not a world or levelsubset file");
83
84   m_hide_from_contribs = false;
85   m_is_levelset = true;
86
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);
91 }
92
93 std::string
94 World::get_basedir() const
95 {
96   return m_basedir;
97 }
98
99 std::string
100 World::get_title() const
101 {
102   return m_title;
103 }
104
105 /* EOF */