// Level info file doesn't define any levels, so read the
// directory to see what we can find
- std::string path = m_basedir;
- char** files = PHYSFS_enumerateFiles(path.c_str());
+ char** files = PHYSFS_enumerateFiles(m_basedir.c_str());
if(!files)
{
- log_warning << "Couldn't read subset dir '" << path << "'" << std::endl;
+ log_warning << "Couldn't read subset dir '" << m_basedir << "'" << std::endl;
return;
}
{
if(StringUtil::has_suffix(*filename, ".stl"))
{
- Level level;
- level.fullpath = path + *filename;
- level.name = *filename;
- m_levels.push_back(level);
+ m_levels.push_back(*filename);
}
}
PHYSFS_freeList(files);
- std::sort(m_levels.begin(), m_levels.end(),
- [](const Level& lhs, const Level& rhs)
- {
- return StringUtil::numeric_less(lhs.fullpath, rhs.fullpath);
- });
+ std::sort(m_levels.begin(), m_levels.end(), StringUtil::numeric_less);
}
void
}
}
-const std::string&
+std::string
World::get_level_filename(unsigned int i) const
{
- return m_levels[i].fullpath;
+ return FileSystem::join(m_basedir, m_levels[i]);
}
unsigned int
{
for(auto level : m_levels)
{
- sq_pushstring(vm, level.name.c_str(), -1);
+ sq_pushstring(vm, level.c_str(), -1);
if(SQ_FAILED(sq_get(vm, -2)))
{
log_warning << "failed to get state.worlds['" << m_worldmap_filename << "'].levels['"
- << level.name << "']" << std::endl;
+ << level << "']" << std::endl;
}
else
{
return num_solved_levels;
}
-const std::string&
+std::string
World::get_basedir() const
{
return m_basedir;
}
-const std::string&
+std::string
World::get_title() const
{
return m_title;
unsigned int get_num_levels() const;
int get_num_solved_levels() const;
- const std::string& get_level_filename(unsigned int i) const;
- const std::string& get_basedir() const;
- const std::string& get_title() const;
+ std::string get_level_filename(unsigned int i) const;
+ std::string get_basedir() const;
+ std::string get_title() const;
PlayerStatus* get_player_status() const { return m_player_status.get(); }
bool is_levelset() const { return m_is_levelset; }
private:
- struct Level
- {
- Level() : fullpath(), name() {}
- std::string fullpath;
- std::string name;
- };
-
- std::vector<Level> m_levels;
+ std::vector<std::string> m_levels;
std::string m_basedir;
std::string m_worldmap_filename;
std::string m_savegame_filename;