Revert ca83136
[supertux.git] / src / supertux / levelset.cpp
1 //  SuperTux
2 //  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
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 "supertux/levelset.hpp"
18
19 #include <physfs.h>
20 #include <algorithm>
21
22 #include "util/log.hpp"
23 #include "util/string_util.hpp"
24
25 Levelset::Levelset(const std::string& basedir) :
26   m_basedir(basedir),
27   m_levels()
28 {
29   char** files = PHYSFS_enumerateFiles(m_basedir.c_str());
30   if (!files)
31   {
32     log_warning << "Couldn't read subset dir '" << m_basedir << "'" << std::endl;
33     return;
34   }
35
36   for(const char* const* filename = files; *filename != 0; ++filename)
37   {
38     if(StringUtil::has_suffix(*filename, ".stl"))
39     {
40       m_levels.push_back(*filename);
41     }
42   }
43   PHYSFS_freeList(files);
44
45   std::sort(m_levels.begin(), m_levels.end(), StringUtil::numeric_less);
46 }
47
48 int
49 Levelset::get_num_levels() const
50 {
51   return static_cast<int>(m_levels.size());
52 }
53
54 std::string
55 Levelset::get_level_filename(int i) const
56 {
57   return m_levels[i];
58 }
59
60 /* EOF */