Order characters by last save

This commit is contained in:
Evil Eye 2025-06-29 18:09:11 +02:00
parent 4520eb077d
commit d756b02d68
3 changed files with 19 additions and 6 deletions

View File

@ -18,14 +18,25 @@ bool MWState::operator<(const Slot& left, const Slot& right)
return left.mTimeStamp < right.mTimeStamp; return left.mTimeStamp < right.mTimeStamp;
} }
std::string MWState::getFirstGameFile(const std::vector<std::string>& contentFiles) bool MWState::operator<(const Character& left, const Character& right)
{
if (left.mSlots.empty() && right.mSlots.empty())
return left.mPath < right.mPath;
else if (left.mSlots.empty())
return false;
else if (right.mSlots.empty())
return true;
return right.mSlots.back() < left.mSlots.back();
}
std::string_view MWState::getFirstGameFile(const std::vector<std::string>& contentFiles)
{ {
for (const std::string& c : contentFiles) for (const std::string& c : contentFiles)
{ {
if (Misc::StringUtils::ciEndsWith(c, ".esm") || Misc::StringUtils::ciEndsWith(c, ".omwgame")) if (Misc::StringUtils::ciEndsWith(c, ".esm") || Misc::StringUtils::ciEndsWith(c, ".omwgame"))
return c; return c;
} }
return ""; return {};
} }
void MWState::Character::addSlot(const std::filesystem::path& path, const std::string& game) void MWState::Character::addSlot(const std::filesystem::path& path, const std::string& game)

View File

@ -2,6 +2,7 @@
#define GAME_STATE_CHARACTER_H #define GAME_STATE_CHARACTER_H
#include <filesystem> #include <filesystem>
#include <string_view>
#include <components/esm3/savedgame.hpp> #include <components/esm3/savedgame.hpp>
@ -16,7 +17,7 @@ namespace MWState
bool operator<(const Slot& left, const Slot& right); bool operator<(const Slot& left, const Slot& right);
std::string getFirstGameFile(const std::vector<std::string>& contentFiles); std::string_view getFirstGameFile(const std::vector<std::string>& contentFiles);
class Character class Character
{ {
@ -63,6 +64,8 @@ namespace MWState
///< Return signature information for this character. ///< Return signature information for this character.
/// ///
/// \attention This function must not be called if there are no slots. /// \attention This function must not be called if there are no slots.
friend bool operator<(const Character& left, const Character& right);
}; };
} }

View File

@ -18,10 +18,8 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
} }
else else
{ {
for (std::filesystem::directory_iterator iter(mPath); iter != std::filesystem::directory_iterator(); ++iter) for (const std::filesystem::path& characterDir : std::filesystem::directory_iterator(mPath))
{ {
std::filesystem::path characterDir = *iter;
if (std::filesystem::is_directory(characterDir)) if (std::filesystem::is_directory(characterDir))
{ {
Character character(characterDir, mGame); Character character(characterDir, mGame);
@ -30,6 +28,7 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
mCharacters.push_back(character); mCharacters.push_back(character);
} }
} }
mCharacters.sort();
} }
} }