Added an allowDuplicates property to the gameselector element.

This commit is contained in:
Leon Styhre 2023-01-31 19:11:58 +01:00
parent 94498bb706
commit cc896bb626
2 changed files with 14 additions and 3 deletions

View file

@ -470,7 +470,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"zIndex", FLOAT}}}, {"zIndex", FLOAT}}},
{"gameselector", {"gameselector",
{{"selection", STRING}, {{"selection", STRING},
{"gameCount", UNSIGNED_INTEGER}}}, {"gameCount", UNSIGNED_INTEGER},
{"allowDuplicates", BOOLEAN}}},
{"helpsystem", {"helpsystem",
{{"pos", NORMALIZED_PAIR}, {{"pos", NORMALIZED_PAIR},
{"origin", NORMALIZED_PAIR}, {"origin", NORMALIZED_PAIR},

View file

@ -22,6 +22,7 @@ public:
, mGameSelection {GameSelection::RANDOM} , mGameSelection {GameSelection::RANDOM}
, mNeedsRefresh {false} , mNeedsRefresh {false}
, mGameCount {1} , mGameCount {1}
, mAllowDuplicates {false}
{ {
mSystem->getRootFolder()->setUpdateListCallback([&]() { mNeedsRefresh = true; }); mSystem->getRootFolder()->setUpdateListCallback([&]() { mNeedsRefresh = true; });
} }
@ -64,11 +65,12 @@ public:
Settings::getInstance()->getBool("ForceKid"))}; Settings::getInstance()->getBool("ForceKid"))};
if (mGameSelection == GameSelection::RANDOM) { if (mGameSelection == GameSelection::RANDOM) {
int tries {8}; int tries {mSystem->getRootFolder()->getGameCount().first < 6 ? 12 : 8};
for (int i {0}; i < mGameCount; ++i) { 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()) if (!mAllowDuplicates &&
mSystem->getRootFolder()->getGameCount().first == mGames.size())
break; break;
FileData* randomGame {nullptr}; FileData* randomGame {nullptr};
@ -83,6 +85,10 @@ public:
--i; --i;
--tries; --tries;
} }
else if (mAllowDuplicates && randomGame != nullptr) {
mGames.emplace_back(randomGame);
}
continue; continue;
} }
@ -160,6 +166,9 @@ public:
if (elem->has("gameCount")) if (elem->has("gameCount"))
mGameCount = glm::clamp(static_cast<int>(elem->get<unsigned int>("gameCount")), 1, 30); mGameCount = glm::clamp(static_cast<int>(elem->get<unsigned int>("gameCount")), 1, 30);
if (elem->has("allowDuplicates"))
mAllowDuplicates = elem->get<bool>("allowDuplicates");
} }
private: private:
@ -170,6 +179,7 @@ private:
GameSelection mGameSelection; GameSelection mGameSelection;
bool mNeedsRefresh; bool mNeedsRefresh;
int mGameCount; int mGameCount;
bool mAllowDuplicates;
}; };
#endif // ES_CORE_COMPONENTS_GAME_SELECTOR_COMPONENT_H #endif // ES_CORE_COMPONENTS_GAME_SELECTOR_COMPONENT_H