From c85700571d277e2ec3cb5a080f0a39551a7b8774 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 25 Sep 2021 16:16:25 +0200 Subject: [PATCH] Added a filter for the 'Alternative emulator' field. --- es-app/src/FileFilterIndex.cpp | 66 +++++++++++++++++++++------------- es-app/src/FileFilterIndex.h | 7 +++- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/es-app/src/FileFilterIndex.cpp b/es-app/src/FileFilterIndex.cpp index 75daf387f..72671f104 100644 --- a/es-app/src/FileFilterIndex.cpp +++ b/es-app/src/FileFilterIndex.cpp @@ -31,21 +31,23 @@ FileFilterIndex::FileFilterIndex() , mFilterByCompleted(false) , mFilterByBroken(false) , mFilterByHidden(false) + , mFilterByAltemulator(false) { clearAllFilters(); // clang-format off FilterDataDecl filterDecls[] = { - //type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel - {FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES"}, - {GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE"}, - {PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS"}, - {PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER"}, - {RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING"}, - {KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME"}, - {COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED"}, - {BROKEN_FILTER, &mBrokenIndexAllKeys, &mFilterByBroken, &mBrokenIndexFilteredKeys, "broken", false, "", "BROKEN"}, - {HIDDEN_FILTER, &mHiddenIndexAllKeys, &mFilterByHidden, &mHiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN"} + //type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel + {FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES"}, + {GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE"}, + {PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS"}, + {PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER"}, + {RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING"}, + {KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME"}, + {COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED"}, + {BROKEN_FILTER, &mBrokenIndexAllKeys, &mFilterByBroken, &mBrokenIndexFilteredKeys, "broken", false, "", "BROKEN"}, + {HIDDEN_FILTER, &mHiddenIndexAllKeys, &mFilterByHidden, &mHiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN"}, + {ALTEMULATOR_FILTER, &mAltemulatorIndexAllKeys, &mFilterByAltemulator, &mAltemulatorIndexFilteredKeys, "altemulator", false, "", "ALTERNATIVE EMULATOR"} }; // clang-format on @@ -76,6 +78,7 @@ void FileFilterIndex::importIndex(FileFilterIndex* indexToImport) {&mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys)}, {&mBrokenIndexAllKeys, &(indexToImport->mBrokenIndexAllKeys)}, {&mHiddenIndexAllKeys, &(indexToImport->mHiddenIndexAllKeys)}, + {&mAltemulatorIndexAllKeys, &(indexToImport->mAltemulatorIndexAllKeys)}, }; std::vector indexImportDecl = std::vector( @@ -111,6 +114,7 @@ void FileFilterIndex::resetIndex() clearIndex(mCompletedIndexAllKeys); clearIndex(mBrokenIndexAllKeys); clearIndex(mHiddenIndexAllKeys); + clearIndex(mAltemulatorIndexAllKeys); } std::string FileFilterIndex::getIndexableKey(FileData* game, @@ -142,14 +146,12 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, case PLAYER_FILTER: { if (getSecondary) break; - key = Utils::String::toUpper(game->metadata.get("players")); break; } case PUBDEV_FILTER: { key = Utils::String::toUpper(game->metadata.get("publisher")); key = Utils::String::trim(key); - if ((getSecondary && !key.empty()) || (!getSecondary && key.empty())) key = Utils::String::toUpper(game->metadata.get("developer")); else @@ -210,6 +212,12 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, key = Utils::String::toUpper(game->metadata.get("hidden")); break; } + case ALTEMULATOR_FILTER: { + if (getSecondary) + break; + key = Utils::String::toUpper(game->metadata.get("altemulator")); + break; + } default: break; } @@ -231,6 +239,7 @@ void FileFilterIndex::addToIndex(FileData* game) manageCompletedEntryInIndex(game); manageBrokenEntryInIndex(game); manageHiddenEntryInIndex(game); + manageAltemulatorEntryInIndex(game); } void FileFilterIndex::removeFromIndex(FileData* game) @@ -244,6 +253,7 @@ void FileFilterIndex::removeFromIndex(FileData* game) manageCompletedEntryInIndex(game, true); manageBrokenEntryInIndex(game, true); manageHiddenEntryInIndex(game, true); + manageAltemulatorEntryInIndex(game, true); } void FileFilterIndex::setFilter(FilterIndexType type, std::vector* values) @@ -339,6 +349,9 @@ void FileFilterIndex::debugPrintIndexes() for (auto x : mHiddenIndexAllKeys) { LOG(LogInfo) << "Hidden Index: " << x.first << ": " << x.second; } + for (auto x : mAltemulatorIndexAllKeys) { + LOG(LogInfo) << "Altemulator Index: " << x.first << ": " << x.second; + } } bool FileFilterIndex::showFile(FileData* game) @@ -415,26 +428,27 @@ bool FileFilterIndex::isFiltered() if (UIModeController::getInstance()->isUIModeKid()) { return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers || mFilterByPubDev || mFilterByRatings || mFilterByCompleted || mFilterByBroken || - mFilterByHidden); + mFilterByHidden || mFilterByAltemulator); } else { return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers || mFilterByPubDev || mFilterByRatings || mFilterByKidGame || mFilterByCompleted || - mFilterByBroken || mFilterByHidden); + mFilterByBroken || mFilterByHidden | mFilterByAltemulator); } } bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type) { - const FilterIndexType filterTypes[9] = {FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER, - PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER, - COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER}; - std::vector filterKeysList[9] = { - mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys, - mPubDevIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys, - mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys}; + const FilterIndexType filterTypes[10] = { + FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER, + KIDGAME_FILTER, COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER, ALTEMULATOR_FILTER}; + std::vector filterKeysList[10] = { + mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys, + mPubDevIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys, + mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys, + mAltemulatorIndexFilteredKeys}; - for (int i = 0; i < 9; i++) { + for (int i = 0; i < 10; i++) { if (filterTypes[i] == type) { for (std::vector::const_iterator it = filterKeysList[i].cbegin(); it != filterKeysList[i].cend(); it++) { @@ -467,7 +481,6 @@ void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove) // Flag for including unknowns. bool includeUnknown = INCLUDE_UNKNOWN; - // Only add unknown in pubdev IF both dev and pub are empty. if (!includeUnknown && (key == UNKNOWN_LABEL || key == "BIOS")) // No valid genre info found. return; @@ -485,7 +498,6 @@ void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove) bool includeUnknown = INCLUDE_UNKNOWN; std::string key = getIndexableKey(game, PLAYER_FILTER, false); - // Only add unknown in pubdev IF both dev and pub are empty. if (!includeUnknown && key == UNKNOWN_LABEL) // No valid player info found. return; @@ -595,6 +607,12 @@ void FileFilterIndex::manageHiddenEntryInIndex(FileData* game, bool remove) manageIndexEntry(&mHiddenIndexAllKeys, key, remove); } +void FileFilterIndex::manageAltemulatorEntryInIndex(FileData* game, bool remove) +{ + std::string key = getIndexableKey(game, ALTEMULATOR_FILTER, false); + manageIndexEntry(&mAltemulatorIndexAllKeys, key, remove); +} + void FileFilterIndex::manageIndexEntry(std::map* index, std::string key, bool remove) diff --git a/es-app/src/FileFilterIndex.h b/es-app/src/FileFilterIndex.h index 18cbf4469..cd2576f39 100644 --- a/es-app/src/FileFilterIndex.h +++ b/es-app/src/FileFilterIndex.h @@ -29,7 +29,8 @@ enum FilterIndexType { KIDGAME_FILTER, COMPLETED_FILTER, BROKEN_FILTER, - HIDDEN_FILTER + HIDDEN_FILTER, + ALTEMULATOR_FILTER }; struct FilterDataDecl { @@ -79,6 +80,7 @@ private: void manageCompletedEntryInIndex(FileData* game, bool remove = false); void manageBrokenEntryInIndex(FileData* game, bool remove = false); void manageHiddenEntryInIndex(FileData* game, bool remove = false); + void manageAltemulatorEntryInIndex(FileData* game, bool remove = false); void manageIndexEntry(std::map* index, std::string key, bool remove); @@ -97,6 +99,7 @@ private: bool mFilterByCompleted; bool mFilterByBroken; bool mFilterByHidden; + bool mFilterByAltemulator; std::map mFavoritesIndexAllKeys; std::map mGenreIndexAllKeys; @@ -107,6 +110,7 @@ private: std::map mCompletedIndexAllKeys; std::map mBrokenIndexAllKeys; std::map mHiddenIndexAllKeys; + std::map mAltemulatorIndexAllKeys; std::vector mFavoritesIndexFilteredKeys; std::vector mGenreIndexFilteredKeys; @@ -117,6 +121,7 @@ private: std::vector mCompletedIndexFilteredKeys; std::vector mBrokenIndexFilteredKeys; std::vector mHiddenIndexFilteredKeys; + std::vector mAltemulatorIndexFilteredKeys; }; #endif // ES_APP_FILE_FILTER_INDEX_H