From bc5213c73f0c030553b11a511aac8e2c458b20a5 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 10 Aug 2014 23:54:23 +0200 Subject: [PATCH] Further filename untangling in World class --- src/supertux/world.cpp | 28 ++++++++++------------------ src/supertux/world.hpp | 15 ++++----------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index 60ce1cf1c..f9bc52acb 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -96,11 +96,10 @@ 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; } @@ -108,19 +107,12 @@ World::load_(const std::string& directory) { 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 @@ -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 @@ -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 { @@ -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; diff --git a/src/supertux/world.hpp b/src/supertux/world.hpp index f61ea7e63..04fad2201 100644 --- a/src/supertux/world.hpp +++ b/src/supertux/world.hpp @@ -50,9 +50,9 @@ public: 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(); } @@ -62,14 +62,7 @@ public: bool is_levelset() const { return m_is_levelset; } private: - struct Level - { - Level() : fullpath(), name() {} - std::string fullpath; - std::string name; - }; - - std::vector m_levels; + std::vector m_levels; std::string m_basedir; std::string m_worldmap_filename; std::string m_savegame_filename; -- 2.11.0