From 9087b1db6faf1d637b308256fd01889073507ea3 Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Thu, 17 Oct 2024 02:02:19 +0800 Subject: [PATCH] Use methods instead of friend class --- src/config/favorite_status.hpp | 19 +++++++------------ src/karts/kart_properties_manager.cpp | 10 +++++----- src/tracks/track_manager.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/config/favorite_status.hpp b/src/config/favorite_status.hpp index dd2f222c95..522ae3dd55 100644 --- a/src/config/favorite_status.hpp +++ b/src/config/favorite_status.hpp @@ -34,14 +34,9 @@ class TrackManager; class UTFWriter; class XMLNode; -/** Class for managing player profiles (name, usage frequency, - * etc.). All PlayerProfiles are managed by the PlayerManager. - * A PlayerProfile keeps track of the story mode progress using an instance - * of StoryModeStatus, and achievements with AchievementsStatus. All data - * is saved in the players.xml file. - * This class also defines the interface for handling online data. All of - * the online handling is done in the derived class OnlinePlayerProfile, - * where the interface is fully implemented. +/** Class for storing the current favorites/custom groups of karts and tracks. + * Put it into KartPropertiesManager or TrackManager by setFavoriteStatus() + * to add them into the original groups. * \ingroup config */ class FavoriteStatus @@ -55,9 +50,6 @@ class FavoriteStatus std::unordered_map > m_favorite; public: - friend class KartPropertiesManager; - friend class TrackManager; - static const std::string DEFAULT_FAVORITE_GROUP_NAME; /** Parse all <(parse_type)/> in in xml node */ @@ -72,7 +64,10 @@ class FavoriteStatus void addFavorite(std::string ident, std::string group = DEFAULT_FAVORITE_GROUP_NAME); void removeFavorite(std::string ident, std::string group = DEFAULT_FAVORITE_GROUP_NAME); -}; // class PlayerProfile + + const std::unordered_map >& getAllFavorites() const + { return m_favorite; } +}; // class FavoriteStatus #endif diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 6de879b22f..adce7c117f 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -113,8 +113,8 @@ void KartPropertiesManager::removeKart(const std::string &ident) std::vector groups = kp->getGroups(); if (m_current_favorite_status) { - for (auto it = m_current_favorite_status->m_favorite.begin(); - it != m_current_favorite_status->m_favorite.end(); it++) + for (auto it = m_current_favorite_status->getAllFavorites().begin(); + it != m_current_favorite_status->getAllFavorites().end(); it++) { // User-defined groups if (it->second.find(kp->getNonTranslatedName()) != it->second.end()) { @@ -319,8 +319,8 @@ bool KartPropertiesManager::loadKart(const std::string &dir) std::vector groups=kart_properties->getGroups(); if (m_current_favorite_status) { - for (auto it = m_current_favorite_status->m_favorite.begin(); - it != m_current_favorite_status->m_favorite.end(); it++) + for (auto it = m_current_favorite_status->getAllFavorites().begin(); + it != m_current_favorite_status->getAllFavorites().end(); it++) { // User-defined groups if (it->second.find(kart_properties->getNonTranslatedName()) != it->second.end()) { @@ -512,7 +512,7 @@ void KartPropertiesManager::setFavoriteKartStatus(FavoriteStatus *status) if (status) { // Add all user-defined groups - for (auto it = status->m_favorite.begin(); it != status->m_favorite.end(); it++) + for (auto it = status->getAllFavorites().begin(); it != status->getAllFavorites().end(); it++) { for (auto it_name = it->second.begin(); it_name != it->second.end(); it_name++) { diff --git a/src/tracks/track_manager.cpp b/src/tracks/track_manager.cpp index 0b7e4a1709..667cc7ad84 100644 --- a/src/tracks/track_manager.cpp +++ b/src/tracks/track_manager.cpp @@ -318,8 +318,8 @@ void TrackManager::removeTrackFromGroups(TrackGroupType type, const Track* track std::vector groups = track->getGroups(); if (m_current_favorite_status) { - for (auto it = m_current_favorite_status->m_favorite.begin(); - it != m_current_favorite_status->m_favorite.end(); it++) + for (auto it = m_current_favorite_status->getAllFavorites().begin(); + it != m_current_favorite_status->getAllFavorites().end(); it++) { // User-defined groups if (it->second.find(track->getIdent()) != it->second.end()) { @@ -415,8 +415,8 @@ void TrackManager::updateGroups(TrackGroupType type, const Track* track) if (m_current_favorite_status) { - for (auto it = m_current_favorite_status->m_favorite.begin(); - it != m_current_favorite_status->m_favorite.end(); it++) + for (auto it = m_current_favorite_status->getAllFavorites().begin(); + it != m_current_favorite_status->getAllFavorites().end(); it++) { // User-defined groups if (it->second.find(ident) != it->second.end()) { @@ -444,7 +444,7 @@ void TrackManager::setFavoriteTrackStatus(FavoriteStatus *status) if (status) { // Add all user-defined groups - for (auto it = status->m_favorite.begin(); it != status->m_favorite.end(); it++) + for (auto it = status->getAllFavorites().begin(); it != status->getAllFavorites().end(); it++) { for (auto it_name = it->second.begin(); it_name != it->second.end(); it_name++) {