Commit c98a7555 authored by Jean-Baptiste Demonte's avatar Jean-Baptiste Demonte

feat(demo): Load configuration on Demo startup, to enable the configuration update

parent 6a38a143
......@@ -13,11 +13,19 @@ DemoMode::DemoMode(Window& window)
mRecalboxConf(*RecalboxConf::getInstance()),
mRandomGenerator(mRandomDevice()),
mGameRandomizer(0, 1U << 30U)
{
}
void DemoMode::init()
{
// Default duration
mDefaultDuration = (int)mRecalboxConf.getUInt("global.demo.duration", 90);
mInfoScreenDuration = (int)mRecalboxConf.getUInt("global.demo.infoscreenduration", 6);
// flush previous init
mDemoSystems.clear();
mDurations.clear();
// Build system list filtered by user config
const std::vector<SystemData*>& allSystems = SystemData::getAllSystems();
bool systemListExists = !mRecalboxConf.get("global.demo.systemlist").empty();
......@@ -26,15 +34,16 @@ DemoMode::DemoMode(Window& window)
const std::string& name = allSystems[i]->getName();
bool includeSystem = mRecalboxConf.getBool(name + ".demo.include");
bool systemIsInIncludeList = !systemListExists || mRecalboxConf.isInList("global.demo.systemlist", name);
int gameCount = allSystems[i]->getRootFolder()->countAllDisplayableItemsRecursively(false);
if ((includeSystem || systemIsInIncludeList) && (gameCount > 0))
bool hasVisibleGame = allSystems[i]->getRootFolder()->hasVisibleGame();
if ((includeSystem || systemIsInIncludeList) && hasVisibleGame)
{
mDemoSystems.push_back(allSystems[i]);
int systemDuration = mRecalboxConf.getUInt(name + ".demo.duration", (unsigned int)mDefaultDuration);
mDurations.push_back(systemDuration);
LOG(LogInfo) << "System selected for demo : " << allSystems[i]->getName() << " with session of " << systemDuration << "s";
}
else LOG(LogDebug) << "System NOT selected for demo : " << allSystems[i]->getName() << " - isSelected: " << (includeSystem | systemIsInIncludeList) << " - gameCount: " << gameCount;
else
LOG(LogDebug) << "System NOT selected for demo : " << allSystems[i]->getName() << " - isSelected: " << (includeSystem | systemIsInIncludeList) << " - hasVisibleGame: " << hasVisibleGame ? 1 : 0;
}
// Check if there is at least one system.
......@@ -157,6 +166,8 @@ void DemoMode::runDemo()
bool Initialized = false;
std::string controllerConfigs;
init();
while(getRandomGame(game, duration))
{
// Get game's parent system
......
......@@ -53,6 +53,8 @@ class DemoMode
//! Secondary seed
int mSeed;
void init();
/*!
* @brief Check if an item is in its history records
* @param item item to seek for
......
......@@ -192,6 +192,16 @@ bool FolderData::hasGame() const
return false;
}
bool FolderData::hasVisibleGame() const
{
for (FileData* fd : mChildren)
{
if ( (fd->isGame() && !fd->Metadata().Hidden()) || (fd->isFolder() && CastFolder(fd)->hasVisibleGame()))
return true;
}
return false;
}
int FolderData::getItems(FileData::List& to, Filter includes, bool includefolders) const
{
int gameCount = 0;
......
......@@ -132,7 +132,12 @@ class FolderData : public FileData
bool hasGame() const;
/*!
* Get total games in all folders, incuding hidden
* Return true if contain at least one visible game
*/
bool hasVisibleGame() const;
/*!
* Get total games in all folders, including hidden
* @return Game count
*/
int countAll(bool includefolders) const { return countItemsRecursively(Filter::All, includefolders); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment