Added a discrete game counting function.

This commit is contained in:
Leon Styhre 2020-10-30 12:53:35 +01:00
parent 2dc8b85aee
commit f753fef1c5
2 changed files with 18 additions and 0 deletions

View file

@ -752,6 +752,22 @@ void FileData::sort(const SortType& type, bool mFavoritesOnTop)
sort(*type.comparisonFunction, type.ascending, mGameCount);
}
void FileData::countGames(std::pair<unsigned int, unsigned int>& gameCount)
{
for (unsigned int i = 0; i < mChildren.size(); i++) {
if (mChildren[i]->getType() == GAME && mChildren[i]->getCountAsGame()) {
if (!mChildren[i]->getFavorite())
gameCount.first++;
else
gameCount.second++;
}
// Iterate through any folders.
else if (mChildren[i]->getType() == FOLDER)
mChildren[i]->countGames(gameCount);
}
mGameCount = gameCount;
}
FileData::SortType FileData::getSortTypeFromString(std::string desc) {
std::vector<FileData::SortType> SortTypes = FileSorts::SortTypes;

View file

@ -123,6 +123,8 @@ public:
std::pair<unsigned int, unsigned int>& gameCount);
void sort(const SortType& type, bool mFavoritesOnTop = false);
MetaDataList metadata;
// Only count the games, a cheaper alternative to a full sort when that is not required.
void countGames(std::pair<unsigned int, unsigned int>& gameCount);
inline void setSortTypeString(std::string typestring) { mSortTypeString = typestring; }
inline std::string getSortTypeString() { return mSortTypeString; }