Skip to content

Commit

Permalink
Use methods instead of friend class
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed Oct 16, 2024
1 parent a401973 commit 9087b1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
19 changes: 7 additions & 12 deletions src/config/favorite_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,9 +50,6 @@ class FavoriteStatus
std::unordered_map<std::string, std::set<std::string> > m_favorite;

public:
friend class KartPropertiesManager;
friend class TrackManager;

static const std::string DEFAULT_FAVORITE_GROUP_NAME;

/** Parse all <(parse_type)/> in <favorite> in xml node */
Expand All @@ -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<std::string, std::set<std::string> >& getAllFavorites() const
{ return m_favorite; }
}; // class FavoriteStatus

#endif

Expand Down
10 changes: 5 additions & 5 deletions src/karts/kart_properties_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void KartPropertiesManager::removeKart(const std::string &ident)
std::vector<std::string> 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())
{
Expand Down Expand Up @@ -319,8 +319,8 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
std::vector<std::string> 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())
{
Expand Down Expand Up @@ -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++)
{
Expand Down
10 changes: 5 additions & 5 deletions src/tracks/track_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ void TrackManager::removeTrackFromGroups(TrackGroupType type, const Track* track
std::vector<std::string> 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())
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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++)
{
Expand Down

0 comments on commit 9087b1d

Please sign in to comment.