Made GameSelectorComponent not return the same game repeatedly in a row.

This commit is contained in:
Leon Styhre 2022-09-12 19:48:11 +02:00
parent ee3d32990d
commit 8e43138722

View file

@ -49,6 +49,12 @@ public:
{
if (!mNeedsRefresh)
return;
FileData* lastGame {nullptr};
if (mGameCount == 1 && !mGames.empty())
lastGame = mGames.front();
mGames.clear();
mNeedsRefresh = false;
@ -59,7 +65,14 @@ public:
for (int i = 0; i < mGameCount; ++i) {
if (mSystem->getRootFolder()->getGameCount().first == 0)
break;
FileData* randomGame {mSystem->getRandomGame(nullptr, true)};
FileData* randomGame {nullptr};
if (mGameCount > 1 || lastGame == nullptr ||
mSystem->getRootFolder()->getGameCount().first == 1)
randomGame = mSystem->getRandomGame(nullptr, true);
else
randomGame = mSystem->getRandomGame(lastGame, true);
if (randomGame != nullptr)
mGames.emplace_back(randomGame);
}