Skip to content

Commit

Permalink
feat(ui): Always keep the mains save file at the top of the list (end…
Browse files Browse the repository at this point in the history
  • Loading branch information
warp-core authored Oct 21, 2023
1 parent 34b1374 commit 1add811
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions source/LoadPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,20 +465,31 @@ void LoadPanel::UpdateLists()
string fileName = Files::Name(path);
// The file name is either "Pilot Name.txt" or "Pilot Name~SnapshotTitle.txt".
size_t pos = fileName.find('~');
if(pos == string::npos)
const bool isSnapshot = (pos != string::npos);
if(!isSnapshot)
pos = fileName.size() - 4;

string pilotName = fileName.substr(0, pos);
files[pilotName].emplace_back(fileName, Files::Timestamp(path));
auto &savesList = files[pilotName];
savesList.emplace_back(fileName, Files::Timestamp(path));
// Ensure that the main save for this pilot, not a snapshot, is first in the list.
if(!isSnapshot)
swap(savesList.front(), savesList.back());
}

for(auto &it : files)
sort(it.second.begin(), it.second.end(),
{
// Don't include the first item in the sort if this pilot has a non-snapshot save.
auto start = it.second.begin();
if(start->first.find('~') == string::npos)
++start;
sort(start, it.second.end(),
[](const pair<string, time_t> &a, const pair<string, time_t> &b) -> bool
{
return a.second > b.second || (a.second == b.second && a.first < b.first);
}
);
}

if(!files.empty())
{
Expand Down

0 comments on commit 1add811

Please sign in to comment.