Skip to content

Commit

Permalink
Further filename untangling in World class
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 11, 2014
1 parent 3df4d4c commit bc5213c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
28 changes: 10 additions & 18 deletions src/supertux/world.cpp
Expand Up @@ -96,31 +96,23 @@ World::load_(const std::string& directory)
// 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;
}

for(const char* const* filename = files; *filename != 0; ++filename)
{
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
Expand Down Expand Up @@ -274,10 +266,10 @@ World::load_state()
}
}

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
Expand Down Expand Up @@ -325,11 +317,11 @@ World::get_num_solved_levels() const
{
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
{
Expand All @@ -351,13 +343,13 @@ World::get_num_solved_levels() const
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;
Expand Down
15 changes: 4 additions & 11 deletions src/supertux/world.hpp
Expand Up @@ -50,9 +50,9 @@ class World : public Currenton<World>
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(); }

Expand All @@ -62,14 +62,7 @@ class World : public Currenton<World>
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;
Expand Down

0 comments on commit bc5213c

Please sign in to comment.