Updated addon repository URL and improved debug output on download
[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     world->m_savegame_filename = stream.str();
48   }
49
50   return std::move(world);
51 }
52
53 World::World() :
54   m_basedir(),
55   m_worldmap_filename(),
56   m_savegame_filename(),
57   m_title(),
58   m_description(),
59   m_hide_from_contribs(false),
60   m_is_levelset(true)
61 {
62 }
63
64 World::~World()
65 {
66 }
67
68 void
69 World::load_(const std::string& directory)
70 {
71   m_basedir = directory;
72   m_worldmap_filename = m_basedir + "/worldmap.stwm";
73
74   lisp::Parser parser;
75   const lisp::Lisp* root = parser.parse(m_basedir + "/info");
76
77   const lisp::Lisp* info = root->get_lisp("supertux-world");
78   if(info == NULL)
79     info = root->get_lisp("supertux-level-subset");
80   if(info == NULL)
81     throw std::runtime_error("File is not a world or levelsubset file");
82
83   m_hide_from_contribs = false;
84   m_is_levelset = true;
85
86   info->get("title", m_title);
87   info->get("description", m_description);
88   info->get("levelset", m_is_levelset);
89   info->get("hide-from-contribs", m_hide_from_contribs);
90 }
91
92 std::string
93 World::get_basedir() const
94 {
95   return m_basedir;
96 }
97
98 std::string
99 World::get_title() const
100 {
101   return m_title;
102 }
103
104 /* EOF */