From cc896bb6264d6e0bf74597c37d9c322850ee9e2a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 31 Jan 2023 19:11:58 +0100 Subject: [PATCH] Added an allowDuplicates property to the gameselector element. --- es-core/src/ThemeData.cpp | 3 ++- es-core/src/components/GameSelectorComponent.h | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 52690673b..0939a9df1 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -470,7 +470,8 @@ std::map> {"zIndex", FLOAT}}}, {"gameselector", {{"selection", STRING}, - {"gameCount", UNSIGNED_INTEGER}}}, + {"gameCount", UNSIGNED_INTEGER}, + {"allowDuplicates", BOOLEAN}}}, {"helpsystem", {{"pos", NORMALIZED_PAIR}, {"origin", NORMALIZED_PAIR}, diff --git a/es-core/src/components/GameSelectorComponent.h b/es-core/src/components/GameSelectorComponent.h index d7368f731..2d957dc8a 100644 --- a/es-core/src/components/GameSelectorComponent.h +++ b/es-core/src/components/GameSelectorComponent.h @@ -22,6 +22,7 @@ public: , mGameSelection {GameSelection::RANDOM} , mNeedsRefresh {false} , mGameCount {1} + , mAllowDuplicates {false} { mSystem->getRootFolder()->setUpdateListCallback([&]() { mNeedsRefresh = true; }); } @@ -64,11 +65,12 @@ public: Settings::getInstance()->getBool("ForceKid"))}; if (mGameSelection == GameSelection::RANDOM) { - int tries {8}; + int tries {mSystem->getRootFolder()->getGameCount().first < 6 ? 12 : 8}; for (int i {0}; i < mGameCount; ++i) { if (mSystem->getRootFolder()->getGameCount().first == 0) break; - if (mSystem->getRootFolder()->getGameCount().first == mGames.size()) + if (!mAllowDuplicates && + mSystem->getRootFolder()->getGameCount().first == mGames.size()) break; FileData* randomGame {nullptr}; @@ -83,6 +85,10 @@ public: --i; --tries; } + else if (mAllowDuplicates && randomGame != nullptr) { + mGames.emplace_back(randomGame); + } + continue; } @@ -160,6 +166,9 @@ public: if (elem->has("gameCount")) mGameCount = glm::clamp(static_cast(elem->get("gameCount")), 1, 30); + + if (elem->has("allowDuplicates")) + mAllowDuplicates = elem->get("allowDuplicates"); } private: @@ -170,6 +179,7 @@ private: GameSelection mGameSelection; bool mNeedsRefresh; int mGameCount; + bool mAllowDuplicates; }; #endif // ES_CORE_COMPONENTS_GAME_SELECTOR_COMPONENT_H