Improved the random game selection functionality in GameSelectorComponent.

This commit is contained in:
Leon Styhre 2022-12-15 18:11:33 +01:00
parent f195ba72a2
commit da3fb9a825

View file

@ -63,9 +63,12 @@ public:
Settings::getInstance()->getBool("ForceKid"))}; Settings::getInstance()->getBool("ForceKid"))};
if (mGameSelection == GameSelection::RANDOM) { if (mGameSelection == GameSelection::RANDOM) {
for (int i = 0; i < mGameCount; ++i) { int tries {8};
for (int i {0}; i < mGameCount; ++i) {
if (mSystem->getRootFolder()->getGameCount().first == 0) if (mSystem->getRootFolder()->getGameCount().first == 0)
break; break;
if (mSystem->getRootFolder()->getGameCount().first == mGames.size())
break;
FileData* randomGame {nullptr}; FileData* randomGame {nullptr};
if (mGameCount > 1 || lastGame == nullptr || if (mGameCount > 1 || lastGame == nullptr ||
@ -74,6 +77,14 @@ public:
else else
randomGame = mSystem->getRandomGame(lastGame, true); randomGame = mSystem->getRandomGame(lastGame, true);
if (std::find(mGames.begin(), mGames.end(), randomGame) != mGames.end()) {
if (tries > 0) {
--i;
--tries;
}
continue;
}
if (randomGame != nullptr) if (randomGame != nullptr)
mGames.emplace_back(randomGame); mGames.emplace_back(randomGame);
} }