Skip to content

Commit b5b0664

Browse files
Merge pull request #357 from lethal-guitar/small-stuff
Robustness: Sort highscore lists after loading/importing
2 parents 505b3f3 + f1d47ba commit b5b0664

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/loader/user_profile_import.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ data::SavedGame loadSavedGame(
102102

103103

104104
data::HighScoreList loadHighScoreList(const std::string& filename) {
105+
using std::begin;
106+
using std::end;
107+
using std::sort;
108+
105109
data::HighScoreList list;
106110

107111
const auto data = loadFile(filename);
@@ -112,7 +116,7 @@ data::HighScoreList loadHighScoreList(const std::string& filename) {
112116
list[i].mScore = std::min<std::uint32_t>(reader.readU32(), data::MAX_SCORE);
113117
}
114118

115-
// TODO: Ensure the list is sorted
119+
sort(begin(list), end(list));
116120
return list;
117121
}
118122

src/user_profile.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ void UserProfile::saveToDisk() {
244244

245245

246246
void UserProfile::loadFromDisk() {
247+
using std::begin;
248+
using std::end;
249+
using std::sort;
250+
247251
if (!mProfilePath) {
248252
return;
249253
}
@@ -289,7 +293,7 @@ void UserProfile::loadFromDisk() {
289293
}
290294
}
291295

292-
// TODO: Ensure the list is sorted
296+
sort(begin(mHighScoreLists[i]), end(mHighScoreLists[i]));
293297

294298
++i;
295299
if (i >= mHighScoreLists.size()) {

0 commit comments

Comments
 (0)